首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GDB的下一个命令向后跳转到作用域末尾的所有堆栈分配的对象。

GDB的下一个命令向后跳转到作用域末尾的所有堆栈分配的对象。
EN

Stack Overflow用户
提问于 2018-09-17 10:41:52
回答 1查看 267关注 0票数 3

当我在一个作用域(大括号内的一组命令)中有堆栈分配的对象,并且在该作用域的末尾使用next时,gdb会以相反的顺序跳回到每个堆栈分配的对象所在的位置。

这在调试过程中令人困扰:当有许多堆栈分配的对象实例时,调试器会向后跳转到每个实例,并且只有在完成时它才会继续进行。相反,我希望它继续到作用域之后的下一行。

有没有办法将gdb配置为不这样做,或者这是我在构建时需要传递给gcc的标志?

起初,我以为我是在使用-O0或其他工具(GDB jumps to wrong lines in out of order fashion)进行编译,但在这里并非如此。

下面是我是如何构建的:

代码语言:javascript
复制
/opt/rh/devtoolset-6/root/usr/bin/c++  -MD -DDEBUG -g -ggdb -gstabs+  -fPIC  -Wall -Werror -Wsynth -Wno-comment -Wreturn-type   main.cpp -c -o main.o
/opt/rh/devtoolset-6/root/usr/bin/c++  -MD -DDEBUG -g -ggdb -gstabs+  -fPIC  -Wall -Werror -Wsynth -Wno-comment -Wreturn-type   main.o -L. -L/opt/rh/devtoolset-6/root/usr/lib64 -lstdc++  -o main.exe   

下面是我在调试器中看到的内容。注意所涉及的GDB版本:

代码语言:javascript
复制
bash-4.2$ gdb main.exe
GNU gdb (GDB) Red Hat Enterprise Linux 7.12.1-48.el6
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main.exe...done.
(gdb) b main
Breakpoint 1 at 0x400a27: file main.cpp, line 45.
(gdb) r
Starting program: /home/brentg/scratch_sandboxes/cxxminimal/main.exe 
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.x86_64

Breakpoint 1, main (argc=1, argv=0x7fffffffeb38, envp=0x7fffffffeb48)
    at main.cpp:45
45    std::cout << __FILE__ << ":" << __LINE__ << ":" << "main begin" << std::endl;
Missing separate debuginfos, use: debuginfo-install libgcc-4.4.7-17.el6.x86_64 libstdc++-4.4.7-17.el6.x86_64
(gdb) l
40    std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 2" << std::endl;
41  }
42  
43  int main(int argc, char *argv[], char *const envp[])
44  {
45    std::cout << __FILE__ << ":" << __LINE__ << ":" << "main begin" << std::endl;
46    some_function_that_uses_Foo();
47    std::cout << __FILE__ << ":" << __LINE__ << ":" << "main end" << std::endl;
48    return 0;
49  } // end main
(gdb) n
main.cpp:45:main begin
46    some_function_that_uses_Foo();
(gdb) s
some_function_that_uses_Foo () at main.cpp:38
38    std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 1" << std::endl;
(gdb) n
main.cpp:38:printing some info 1
39    Foo the_foo1;
(gdb) n
40    std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 2" << std::endl;
(gdb) l
35  
36  void some_function_that_uses_Foo()
37  {
38    std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 1" << std::endl;
39    Foo the_foo1;
40    std::cout << __FILE__ << ":" << __LINE__ << ":" << "printing some info 2" << std::endl;
41  }
42  
43  int main(int argc, char *argv[], char *const envp[])
44  {
(gdb) n
main.cpp:40:printing some info 2
39    Foo the_foo1;

在这一点上,我想知道:为什么我现在又回到了39行?当我在第40行输入"next“时,它似乎会向后跳转。

查看gdb手册中的"next“命令,我没有看到任何关于C++构造函数/析构函数的内容。

EN

回答 1

Stack Overflow用户

发布于 2018-09-18 09:34:56

/opt/rh/devtoolset-6/root/usr/bin/c++ -MD -DDEBUG -g -ggdb -gstabs+ ...

你可能正在遭受自己造成的创伤。

STABS debugging format是古老的,不应该在任何不到15年的系统上使用。它也是完全不够的,完全没有经过测试。

libgcc-4.4.7-17.el6.x86_64

您还使用了古老的GCC-4.4.7,它是在2012年3月发布的。使用更新的版本,您可能会获得更好的调试体验。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52360140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档