我有一個 C 檔案,我使用-g選項編譯并將除錯符號保存到另一個檔案并剝離了可執行檔案。當我嘗試使用 除錯此可執行檔案時set debug-file-directory /root/test,我無法設定斷點。我猜符號檔案映射不起作用。有人可以在這里提供一些輸入嗎?
#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
exea.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
uj5u.com熱心網友回復:
正如busybee所說,您的某些命令不正確。
您應該查看單獨除錯檔案的 gdb 檔案以獲得更完整的描述,但是,您需要的命令是:
$ 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.debug添加一個小部分,a.out告訴 GDB 包含除錯資訊的檔案的名稱。GDB 使用一些內置規則,以及debug-file-directory查找在除錯鏈接中命名的檔案。
最后,當我們啟動 GDB 時,我們可以看到它已經找到了外部除錯資訊。
uj5u.com熱心網友回復:
您至少有兩個錯誤:
strip --strip-debug a.out -o a.out.debug不按你的想法做。
它不是“匯出”除錯資訊,而是將其洗掉并將結果保存在“a.out.debug”中。結果是帶有除錯資訊的可執行檔案。
查找該選項--only-keep-debug作為下一步。
您沒有將任何除錯資訊加載到 gdb
啟動 GDB 后,使用symbol-file命令加載除錯符號。我不認為 GDB 可以自動找到除錯資訊,因為它不知道檔案的名稱。
您無需為此更改除錯檔案目錄。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/510562.html
上一篇:在Flutter(VSCode)中除錯和運行應用程式的問題
下一篇:在顫振中使用標志
