GDB says "no symbol table," but nm shows file has debug symbols
Solution 1
gcc 4.8.1 generates dwarf4 debug info which gdb 7.4 can't understand. You need to install gdb 7.6
Solution 2
In addition to Chris Dodd's answer, you can also compile your code with gcc -gdwarf-3
, which compiles with dwarf3 debug info. Which is compatible with your GDB version.
Solution 3
gdb read .debug_info section before .symtab .dynsym.
nm just read .symtab .dynsym.
It's because that the .debug_info section in your ELF file was striped.
You can use:
readelf -S youelf | grep -i debug
to check wether debug_info is present.
Related videos on Youtube
Edward
I'm an assistant professor of Computer Science at Augusta University. My research areas include fault-tolerant distributed systems, Internet of Things devices, and privacy and security concerns in systems. I mostly program in C++ these days, but I also have experience with Python, Java, C, and C#.
Updated on July 09, 2022Comments
-
Edward almost 2 years
I'm trying to debug a simple C project using GDB, but GDB can't seem to find the debug symbols for the program no matter how I compile it.
When I load the program into GDB, it claims to have read the symbols successfully because it prints
Reading symbols from /home/edward/<executable>...done.
However, when I run the program, break on a segmentation fault, and type
info locals
, it saysNo symbol table info available.
Also,
bt
shows that execution stopped inside a function I wrote (not a system or library call), but there is no line number information, just raw memory addresses.Why can't GDB find or use the symbols it successfully read earlier? I've run
nm
andobjdump
on the binary file I'm running, and they both show sections like.debug_info
,.debug_line
, so the file does in fact contain debugging symbols.I usually compile with a Makefile that sets the following flags:
CFLAGS = -mno-red-zone -fno-omit-frame-pointer -ggdb -O0 -I. -Wdeclaration-after-statement -Wall
which I can see are being used when make invokes gcc. However, I've tried changing to just
-g
, and compiling manually by invokinggcc -g -O0
on a simple test file, and the result is still the same: the binary file contains debug symbols, and GDB reads them, but invoking any GDB command results in a message that debug information is not available.Updates
I'm running Ubuntu 12.04, my GDB version is 7.4, and my GCC version is 4.8.1.
If I
set complaints 10000
in GDB and then load the file, it prints the following complaints:Reading symbols from /home/edward/<snip>/minithread... DW_AT_low_pc 0x400690 is not < DW_AT_high_pc 0x33 for DIE at 0x205 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x4006c3 is not < DW_AT_high_pc 0xa9 for DIE at 0x235 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x40076c is not < DW_AT_high_pc 0xad for DIE at 0x287 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400819 is not < DW_AT_high_pc 0xe7 for DIE at 0x2d3 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400900 is not < DW_AT_high_pc 0x4f for DIE at 0x345 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x40094f is not < DW_AT_high_pc 0x55 for DIE at 0x39d [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x4009a4 is not < DW_AT_high_pc 0x38 for DIE at 0x3e7 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x4009dc is not < DW_AT_high_pc 0x43 for DIE at 0x433 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400a20 is not < DW_AT_high_pc 0x2e for DIE at 0x56c [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400a4e is not < DW_AT_high_pc 0x2e for DIE at 0x5aa [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400a7c is not < DW_AT_high_pc 0x29 for DIE at 0x5d4 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400aa5 is not < DW_AT_high_pc 0x49 for DIE at 0x620 [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400aee is not < DW_AT_high_pc 0xca for DIE at 0x66c [in module /home/edward/<snip>/minithread] ...DW_AT_low_pc 0x400bb8 is not < DW_AT_high_pc 0x7bb for DIE at 0x6f0 [in module /home/edward/<snip>/minithread]...done.
Are these errors the cause of the problem? Do they mean my GDB is the "wrong" version?
-
Gangadhar over 10 years
gcc -g
gives You symbol info.There is no doubt at all.Can you please post your test file or some part of test file which we can able to compile. have you tried by printing any symbols with the help of p option -
Tom Tromey over 10 yearsOne place to start is to run plain "gdb", then "set complaints 10000", and then "file .../myexecutable". This will make the DWARF reader complain if it finds weird things in the DWARF. Also you don't mention what version of GCC or gdb you are using. Sometimes newer gcc requires a newer gdb.
-
Chris Dodd over 10 yearspossible duplicate of C++ app on Ubuntu. After installing gcc 4.8.1 the gdb does not work
-
ks1322 over 10 yearspossible duplicate of GCC doesn't produce line number information even with -g option
-
-
phil294 over 7 yearsI got gdb 7.11 and struggle with the same problem.
-
Sergei almost 7 yearshave the same problem with gcc 4.8.5 and gdb 7.6.1
-
firo almost 7 yearsHave the same issue with gcc 4.9.1 and gdb 7.2-90.el6
-
Flamefire about 6 yearsThis is even better as cannot always upgrade the gdb version
-
Ravi Menon over 3 yearsThank you very much. Switching from -ggdb to -gdwarf-3 did the trick for my environment : gbd 7.4-2012.04 and gcc 4.9.4