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

时间:2018-09-17 02:41:52

标签: gcc gdb stackframe

当我在范围内(在大括号内的一组命令)中有堆栈分配的对象,并且在该范围的末尾使用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手册中查找“ next”命令时,我没有看到有关C ++构造函数/析构函数的任何信息。

1 个答案:

答案 0 :(得分:0)

  

class ReservationDetailsSerializers(serializers.ModelSerializer): product = ProductSerializer(required=False) class Meta: model= DetailsReservation fields = ['Reservation', 'Quantity', 'userbyReserva', 'product']

您可能正在遭受自我伤害。

STABS debugging format很古老,不应在少于15年的任何系统上使用。它也是不足并且完全未经测试。

  

class ReservationDetailsSerializers(serializers.ModelSerializer): products = ProductSerializer(required=False, source='product')

class Meta: model = DetailsReservation fields = ['Reservation', 'Quantity', 'userbyReserva', 'products']

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