C语言 GDB 说“没有符号表”,但 nm 显示文件有调试符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19229882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GDB says "no symbol table," but nm shows file has debug symbols
提问by Edward
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.
我正在尝试使用 GDB 调试一个简单的 C 项目,但无论我如何编译,GDB 似乎都找不到该程序的调试符号。
When I load the program into GDB, it claims to have read the symbols successfully because it prints
当我将程序加载到 GDB 时,它声称已成功读取符号,因为它打印
Reading symbols from /home/edward/<executable>...done.
However, when I run the program, break on a segmentation fault, and type info locals, it says
但是,当我运行程序时,中断分段错误并键入info locals,它说
No symbol table info available.
Also, btshows 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.
此外,bt显示执行在我编写的函数(不是系统或库调用)内停止,但没有行号信息,只有原始内存地址。
Why can't GDB find or use the symbols it successfully read earlier? I've run nmand objdumpon 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.
为什么 GDB 找不到或使用它之前成功读取的符号?我已经运行nm和objdump在二进制文件我跑,他们都显示部分喜欢.debug_info,.debug_line,因此该文件实际上包含调试符号。
I usually compile with a Makefile that sets the following flags:
我通常使用设置以下标志的 Makefile 进行编译:
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 invoking gcc -g -O0on 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.
我可以看到当 make 调用 gcc 时正在使用它。但是,我尝试更改为 just -g,并通过调用gcc -g -O0一个简单的测试文件手动编译,结果仍然相同:二进制文件包含调试符号,GDB 读取它们,但调用任何 GDB 命令都会导致一条消息调试信息不可用。
Updates
更新
I'm running Ubuntu 12.04, my GDB version is 7.4, and my GCC version is 4.8.1.
我正在运行 Ubuntu 12.04,我的 GDB 版本是 7.4,我的 GCC 版本是 4.8.1。
If I set complaints 10000in GDB and then load the file, it prints the following complaints:
如果我set complaints 10000在 GDB 中然后加载文件,它会打印以下抱怨:
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?
这些错误是问题的原因吗?他们的意思是我的 GDB 是“错误的”版本吗?
回答by Chris Dodd
gcc 4.8.1 generates dwarf4 debug info which gdb 7.4 can't understand. You need to install gdb 7.6
gcc 4.8.1 生成 gdb 7.4 无法理解的 dwarf4 调试信息。您需要安装 gdb 7.6
回答by Robert
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.
除了 Chris Dodd 的回答,您还可以使用 编译您的代码gcc -gdwarf-3,它使用 dwarf3 调试信息进行编译。这与您的 GDB 版本兼容。
回答by firo
gdb read .debug_info section before .symtab .dynsym.
gdb 在 .symtab .dynsym 之前读取 .debug_info 部分。
nm just read .symtab .dynsym.
nm 只是读取 .symtab .dynsym。
It's because that the .debug_info section in your ELF file was striped.
这是因为您的 ELF 文件中的 .debug_info 部分是条带化的。
You can use:
您可以使用:
readelf -S youelf | grep -i debug
to check wether debug_info is present.
检查 debug_info 是否存在。

