如何自己调试gdb

sbu*_*nny 6 debugging gdb

我的机器上安装了 gdb。今天我编译了另一个运行良好的gdb版本。现在我想使用旧的 gdb 调试这个新的 gdb。请在这方面指导我。我怎么知道 gdb 如何从提供的可执行文件中读取符号,它如何插入断点,处理函数调用和其他事情。

谢谢。

ikh*_*ikh 5

轻松思考;当你想调试某个程序时,你可能会用-g或编译它-ggdb并运行gdb,不是吗?

  1. 下载gdb 源代码

  2. 编译它 -ggdb

    ./configure --prefix=<where-to-install>
    make CFLAGS="-ggdb" CXXFLAGS="-ggdb"
    make install
    
    Run Code Online (Sandbox Code Playgroud)
  3. 调试一下!

    gdb <where-to-install>/bin/gdb
    
    Run Code Online (Sandbox Code Playgroud)

我从未尝试过(也从未想过),但它可能会奏效。(而且看起来很有趣;我正要试一试!)


嗯,我刚刚在cygwin中测试了一下,发现调试器gdb的输出和被调试器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
Run Code Online (Sandbox Code Playgroud)

# 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)
Run Code Online (Sandbox Code Playgroud)