【发布时间】:2017-08-13 09:58:48
【问题描述】:
让我们看看这个基本的 c 程序:
#include <stdio.h>
int myadd(int a, int b);
int myadd(int a, int b)
{
return a+b;
}
int main(int argc, char *argv[])
{
int res = myadd(argc,3);
printf("%d\n",res);
return 0;
}
我想要了解调试符号文件的工作原理。
如果我这样编译:
gcc test.c
我可以在 gdb 中看到调试符号:
gdb ./a.out
(gdb) disassemble myadd
Dump of assembler code for function myadd:
0x00000000000006b0 <+0>: push %rbp
没关系!
现在,如果我运行:
gcc -s test.c
这是我在 gdb 中得到的:
(gdb) disassemble myadd
No symbol table is loaded. Use the "file" command.
这也很好,因为我使用 -s gcc 选项去除了符号。
现在,我想将我的 elf 可执行文件“拆分”为 2 个文件: - 一个剥离的精灵可执行文件 - 一个外部调试符号文件。
这是我在一些教程中读到的:
gcc test.c
objcopy --only-keep-debug a.out a.dbg
strip ./a.out
但是,现在,如果我想运行 gdb,我会告诉 gdb 在 ./a.dbg 中查找调试符号
gdb -s ./a.dbg a.out
而gdb无法解析myadd函数:
(gdb) disassemble myadd
No symbol table is loaded. Use the "file" command.
这是我不明白的:为什么 gdb 不解析 myadd 函数?
谢谢
【问题讨论】: