为什么GDB“下一个”显示构造函数行两次? [英] Why does GDB "next" show the constructor line twice?

查看:195
本文介绍了为什么GDB“下一个”显示构造函数行两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用gdbnext跟踪下面的代码时,

  int main(){
vector< int> ;一个;
.push_back(28);
}

第二行 vector< int>一个显示两次。
请参阅截图



有谁能告诉我为什么这行显示两次吗?



源代码t.cpp使用


  • g ++ -g -std = c ++ 11 t.cpp,Ubuntu 16.04上的
  • LTS
    与g ++(Ubuntu 5.4.0-6ubuntu1〜16.04.4)5.4.0 20160609



我注意到了 gdb,whynext显示每个源代码行两次?,但没有答案在那里。



预先感谢!

编译器资源管理器网站上查看生成的程序集。

这可能是因为析构函数在离开范围时被调用,这可能导致多个对象在同一行上被销毁。在调试器中多次显示'}'并不是很有用,因为用户无法看到接下来要破坏的对象。


When using gdb "next" tracing the code below,

int main(){
    vector<int> a;
    a.push_back(28);
}

The second line vector<int> a was displayed twice. Please see the screen shot

Can anybody tell me why the line was displayed twice?

The source code t.cpp was compiled using

  • g++ -g -std=c++11 t.cpp,
  • on Ubuntu 16.04 LTS with g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

I noticed the post gdb,why "next" show each source line twice?, but no answer was given there.

Thanks in advance!

解决方案

Because G++ assigns the code for objects' constructors to the same line as their destructors, as 'Some programmer dude' suggested. Have a look at the resulting assembly over at the Compiler Explorer website.

This is probably done because destructors are called when leaving the scope, which can lead to multiple objects being destroyed on the same line. Showing '}' multiple times in the debugger is not very helpful as the user can't see which object is to be destructed next.

这篇关于为什么GDB“下一个”显示构造函数行两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆