debugging GDB未将符号文件Map到剥离的exe

68bkxrlz  于 2022-11-14  发布在  其他
关注(0)|答案(2)|浏览(172)

我有一个C文件,我用-g选项编译,并将调试符号保存到另一个文件中,并剥离了可执行文件。当我尝试用set debug-file-directory /root/test调试此可执行文件时,我无法设置断点。我猜符号文件Map不起作用。有人能在这里给予一些输入吗?

#include <stdio.h>
void func1()
{
}

int main() {
FILE *fp;
fp  = fopen ("/tmp/abcdefg", "w");
func1();
}

用调试符号编译;

gcc -g file.c

已将两柴符号储存至相同目录中的不同档案。

strip --strip-debug a.out -o a.out.debug

剥离了可执行文件;

strip a.out

exe a.out和调试符号文件a.out.debug位于/root/test目录中。
正在启动gdb会话;

root@ubuntu:~/test# gdb a.out
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 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 "x86_64-linux-gnu".
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 a.out...(no debugging symbols found)...done.
(gdb) set debug-file-directory /root/test
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/root/test".
(gdb) b main
Function "main" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) q
You have new mail in /var/mail/root
lhcgjxsq

lhcgjxsq1#

正如the busybee所说,您的一些命令不正确。
您应该查看gdb documentation on separate debug files以获得更完整的描述,但是,您需要的命令是:

$ gcc -g file.c
$ strip --only-keep-debug a.out -o a.out.debug
$ strip --strip-debug a.out
$ objcopy --add-gnu-debuglink=a.out.debug a.out
$ gdb -q a.out
Reading symbols from a.out...
Reading symbols from /home/andrew/tmp/strip-demo/a.out.debug...
(gdb)

strip --only-keep-debug仅将调试部分从a.out复制到a.out.debug
然后,strip --strip-debug只从a.out中删除调试部分,而不删除其他部分。
objcopy --add-gnu-debuglink=a.out.debuga.out中添加了一个小部分,告诉GDB包含调试信息的文件名。GDB使用一些内置的规则,以及debug-file-directory来查找调试链接中指定的文件。
最后,当我们启动GDB时,我们可以看到它已经找到了外部调试信息。

bweufnob

bweufnob2#

您至少有两个错误:

strip --strip-debug a.out -o a.out.debug不会按照您的想法执行。

它不是“导出”调试信息,而是将其删除并将结果保存在“a.out.debug”中。结果是一个带有调试信息的可执行文件。
下一步查找选项--only-keep-debug

未将任何调试信息加载到gdb中

启动GDB后,使用symbol-file命令加载调试符号,我认为GDB不能自动找到调试信息,因为它不知道文件名。
您不需要为此更改debug-file-directory。

相关问题