我的机器上安装了gdb。今天我编译了另一个运行正常的gdb版本。现在我想使用旧的gdb调试这个新的gdb。请指导我这方面。我怎么知道gdb如何从提供的可执行文件中读取符号,如何插入断点,处理函数调用等等。
感谢。
答案 0 :(得分:4)
轻松思考;当你想调试一些程序时,你可能用-g
或-ggdb
编译它并运行gdb,不是吗?
下载gdb source。
使用-ggdb
./configure --prefix=<where-to-install>
make CFLAGS="-ggdb" CXXFLAGS="-ggdb"
make install
调试它!
gdb <where-to-install>/bin/gdb
我从未尝试过(从未想过),但它可能会奏效。 (它看起来非常有趣;我即将尝试它!)
嗯,我刚刚在cygwin中对它进行了测试,并找出了调试器 gdb输出和调试对象 gdb&#39的问题; s输出是混合的;我使用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)
答案 1 :(得分:4)
一旦第一个gdb在将新gdb作为输入文件后开始运行,它将在显示信息消息后暂停。此时,您可以在要执行的新gdb函数上设置断点。
例如,break insert_breakpoints //用于插入断点的函数。
现在执行:run 这将开始执行新加载的gdb。使用file命令将任何可执行的HelloWorld.c与-g选项(用于构建调试符号)一起提供给新的gdb。
现在在HelloWorld可执行文件中的任何位置插入断点,即 打破主要
这个break命令将调用gdb的insert_breakpoints函数,该函数用于插入我们之前放置断点的断点。
现在你可以使用backtrace或其他命令来检查函数调用和其他类似的东西。
希望能解决你的问题。
答案 2 :(得分:-1)
@ikh我认为默认情况下gdb是用调试符号编译的,因为发出: file / path / to / compiled / gdb给出:
ELF 32位LSB可执行文件,Intel 80386,版本1(SYSV),动态链接(使用共享库),用于GNU / Linux 2.6.24,BuildID [sha1] = 0xd1c553318661f8b557f4c3640b02cee1ef512ac0,未剥离 这意味着它有可用的调试信息。
如果我错了,请纠正我。