jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

How can I get debug info for locals?

Fri Apr 01, 2016 5:51 am

I'm trying to debug a program, but gdb stubbornly refuses to print my local variable values.
I compile with -O0 and -gdawrf-4.
When I do "info local" it prints some global variables, but not the locals of the function.

I then tried to debug a very simple program, and that fares even worse -- GDB doesn't even find the line numbers:

Code: Select all

pi@moneypitquattro /tmp $ cat foo.cpp
#include <stdio.h>

int main(int argc, char const *argv[]) {
  printf("argc=%d\n");
  printf("argv[1]=%p\n", argv[1]);
  return 0;
}
pi@moneypitquattro /tmp $ g++ -o foo foo.cpp -g -O0
pi@moneypitquattro /tmp $ gdb ./foo
GNU gdb (GDB) 7.4.1-debian
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 "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/foo...done.
(gdb) br main
Breakpoint 1 at 0x855c
(gdb) run -x -y
Starting program: /tmp/foo -x -y
Traceback (most recent call last):
  File "/usr/lib/debug/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named libstdcxx.v6.printers

Breakpoint 1, 0x0000855c in main ()
(gdb) print argc
No symbol "argc" in current context.
(gdb) print argv
No symbol "argv" in current context.
(gdb) next
Single stepping until exit from function main,
which has no line number information.
argc=2130704196
argv[1]=0x7efff86c
0x76d3581c in __libc_start_main () from /lib/arm-linux-gnueabihf/libc.so.6
(gdb)
Help!

beta-tester
Posts: 1377
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: How can I get debug info for locals?

Fri Apr 01, 2016 9:07 pm

Code: Select all

  printf("argc=%d\n");
shouldn't it be

Code: Select all

  printf("argc=%d\n", argc);
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: How can I get debug info for locals?

Fri Apr 01, 2016 9:30 pm

Yes, it should, but that doesn't change the actual problem I want help with at all!

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: How can I get debug info for locals?

Sat Apr 02, 2016 1:57 pm

That looks like a problem with the version of gdb you are using, the scripts for the pretty-printer are not where it expects them to be (hence the ImportError). I don't know why it's not seeing the variables though - I just edited the autoloader for gdb pretty-printer on my system and although I got the ImportError, everything else worked as it should. Maybe there are more issues with the version you have, can you update it? Raspbian's version is 7.7.1

Running on mine with manually broken pretty-printer:

Code: Select all

pi@rpi3:/tmp $ gdb ./foo
GNU gdb (Raspbian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 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 "arm-linux-gnueabihf".
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 ./foo...done.
(gdb) b main
Breakpoint 1 at 0x1052c: file foo.cpp, line 4.
(gdb) r
Starting program: /tmp/foo
Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.20-gdb.py", line 59, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named libstdcxx.v6.printers

Breakpoint 1, main (argc=1, argv=0x7efff794) at foo.cpp:4
4         printf("argc=%d\n", argc);
(gdb) p argc
$1 = 1
(gdb) p argv
$2 = (const char **) 0x7efff794
(gdb) c
Continuing.
argc=1
argv[1]=(nil)
[Inferior 1 (process 24963) exited normally]
(gdb) q
She who travels light — forgot something.

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: How can I get debug info for locals?

Sat Apr 02, 2016 6:00 pm

Interesting.
I thought I did a full system upgrade already, (using dist-upgrade) but it does look like an older version.
Surprising that GCC got upgraded, but GDB did not.

Oh -- I had not updated sources.lst to point at jessie before doing dist-upgrade. I'll try with 7.7 and hope for the best!

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: How can I get debug info for locals?

Sun Apr 03, 2016 4:35 am

I blew away my sdcard and installed the latest, lightweight, raspian from a couple of weeks ago.
I now get gcc 4.9.2, and gdb 7.7.1, and I can read the value of local variables when compiling with -g and -O0. Yay!
Thanks for the help.

Return to “Advanced users”