#328 gdb is not showing backtrace

open
nobody
None
5
2014-08-25
2013-01-08
Vitezslav
No

In some situations gdb is not showing a backtrace (or, more precisly, its not showing the backtrace below current frame). The following example illustrates one such case. If set a breakpoint to line 5 (before a function prologue is executed), the backtrace is correct, but if you continue to the next line (or set a breakpoint to line 6), the backtrace is showing correctly only the innermost stack frame.

test.cpp
#include <iostream>
using namespace std;

void foo()
{ // line 5 - function prologue
char c[1];
cout << c << endl;
}

int main()
{
foo();
return 0;
}

D:\&gt;g++ -g -O0 test.cpp -o test.exe

D:\&gt;gdb test.exe
GNU gdb (rubenvb-4.7.2-release) 7.5.50.20120920-cvs
Copyright (C) 2012 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-w64-mingw32".
For bug reporting instructions, please see:
<mingw-w64-public@lists.sourceforge.net>...
Reading symbols from D:\test.exe...done.
(gdb) break test.cpp:5
Breakpoint 1 at 0x401e81: file test.cpp, line 5.
(gdb) start
Temporary breakpoint 2 at 0x401fc0: file test.cpp, line 12.
Starting program: D:\test.exe
[New Thread 3524.0x13c4]

Temporary breakpoint 2, main () at test.cpp:12
12 foo();
(gdb) continue
Continuing.

Breakpoint 1, foo () at test.cpp:5
5 { // line 5 - function prologue
(gdb) bt
#0 foo () at test.cpp:5
#1 0x0000000000401fc5 in main () at test.cpp:12
(gdb) next
7 cout << c << endl;
(gdb) bt
#0 foo () at test.cpp:7
#1 0x0000000000000000 in ?? ()

It seems that it is connected with the generated function prologue. If you change the line 6 to 'char c = 0;' than the backtrace is correct (and the disassembly of the function prologue looks quite different in this case). Another notice is that if you compile with -fno-dwarf2-cfi-asm option, the backtrace is also correct.

Discussion

  • Jonathan Yong
    Jonathan Yong
    2013-01-08

    -g0 means no debug info, debugging above the asm level is in no way reliable. Try -g1 -g2 or -g3.

     
  • Vitezslav
    Vitezslav
    2013-01-08

    You have misread the arguments, it was -g -O0, not -g0. I tried with -g1 -g2 -g3 (and without -O0) but it's still the same.

     
  • Jonathan Yong
    Jonathan Yong
    2013-01-08

    Have you tried with the latest GCC and GDB release? Other than that, please contact the upstream projects, namely gdb at sourceware.org mailing list and the gdb bug tracker.

     
  • Vitezslav
    Vitezslav
    2013-01-11

    You're right, I forgot to check the latest unstable release of gcc 4.8, my fault. The gdb seems to be working ok with the example above. I can't compile a larger project with it to check it with some more complex code.