让我们来看一下这个基本的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可执行文件“拆分”成两个文件: - 一个去掉符号的elf可执行文件 - 一个外部调试符号文件。
以下是我在一些教程中看到的内容:
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无法解析我的add函数?
谢谢。