GDB的下一个命令在范围结束时向后跳转到所有堆栈分配的对象

问题描述 投票:2回答:1

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

这在调试仪式期间是令人不安的:当存在大量堆栈分配的对象实例时,调试器会向后跳转到每个对象,并且只有在完成后才会向前进行。相反,我希望它在范围之后进入下一行。

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

起初,我认为是我使用-O0或其他东西(GDB jumps to wrong lines in out of order fashion)编译,但这不是这里的情况。

以下是我的建设方式:

/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版本:

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手册,我没有看到有关C ++构造函数/析构函数的任何内容。

gcc gdb stackframe
1个回答
0
投票

/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

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

© www.soinside.com 2019 - 2024. All rights reserved.