簡體   English   中英

如何用自己調試gdb

[英]How to debug gdb with itself

我的機器上安裝了gdb。 今天我編譯了另一個運行正常的gdb版本。 現在我想使用舊的gdb調試這個新的gdb。 請指導我這方面。 我怎么知道gdb如何從提供的可執行文件中讀取符號,如何插入斷點,處理函數調用等等。

謝謝。

輕松思考; 當你想調試一些程序時,你可能用-g-ggdb編譯它並運行gdb,不是嗎?

  1. 下載gdb源代碼

  2. -ggdb編譯它

     ./configure --prefix=<where-to-install> make CFLAGS="-ggdb" CXXFLAGS="-ggdb" make install 
  3. 調試它!

     gdb <where-to-install>/bin/gdb 

我從未嘗試過(從未想過),但它可能會奏效。 (它看起來很有趣;我即將嘗試!)


嗯,我剛剛在cygwin中對它進行了測試,並找出了調試器 gdb輸出和debuggee gdb輸出混合的問題; 我通過使用gdbserver來解決它。

# On terminal 1..
$ gdbserver localhost:1234 gdb-gdb/prefix/bin/gdb
Process gdb-gdb/prefix/bin/gdb created; pid = 972
Listening on port 1234
Remote debugging from host 127.0.0.1
GNU gdb (GDB) 7.7.1
Copyright (C) 2014 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 "i686-pc-mingw32".
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".
(gdb) q

Child exited with status 0
GDBserver exiting

# On terminal 2..
$ gdb gdb-gdb/prefix/bin/gdb
GNU gdb (GDB) 7.8
Copyright (C) 2014 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 "i686-pc-cygwin".
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 gdb-gdb/prefix/bin/gdb...done.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x7c93120f in ntdll!DbgBreakPoint ()
   from /cygdrive/c/WINDOWS/system32/ntdll.dll
(gdb) c
Continuing.
[Inferior 1 (Remote target) exited normally]
(gdb)

一旦第一個gdb在將新gdb作為輸入文件后開始運行,它將在顯示信息消息后暫停。 此時,您可以在要執行的新gdb的功能上設置斷點。

例如,break insert_breakpoints //用於插入斷點的函數。

現在執行:run這將開始執行新加載的gdb。 使用file命令將任何可執行的HelloWorld.c與-g選項(用於構建調試符號)一起提供給新的gdb。

現在在HelloWorld可執行文件中的任何位置插入斷點,即break main

此break命令將調用gdb的insert_breakpoints函數,該函數用於插入我們之前放置斷點的斷點。

現在你可以使用backtrace或其他命令來檢查函數調用和其他類似的東西。

希望能解決您的問題。

@ikh我認為默認情況下gdb是用調試符號編譯的,因為發出:file / path / to / compiled / gdb給出:

ELF 32位LSB可執行文件,Intel 80386,版本1(SYSV),動態鏈接(使用共享庫),用於GNU / Linux 2.6.24,BuildID [sha1] = 0xd1c553318661f8b557f4c3640b02cee1ef512ac0, 未剝離這意味着它具有調試信息它。

如果我錯了,請糾正我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM