我正在尝试使用--command标志自动化gdb会话.我正在尝试在共享库(Unix的等价物DLL)中的函数上设置断点.我的cmds.gdb看起来像这样:
set args /home/shlomi/conf/bugs/kde/font-break.txt
b IA__FcFontMatch
r
Run Code Online (Sandbox Code Playgroud)
但是,我得到以下内容:
shlomi:~/progs/bugs-external/kde/font-breaking$ gdb --command=cmds.gdb... GNU gdb 6.8-2mdv2009.0 (Mandriva Linux release 2009.0) Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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 "i586-mandriva-linux-gnu"... (no debugging symbols found) Function "IA__FcFontMatch" not defined. Make …
我有一个断点列表,我想在每次调试特定程序时添加这些断点.
有没有办法可以将所有断点信息放在一个文件中,并在每个调试会话开始时使用它?换句话说,在提供'run'命令之前,我可以向GDB提供带有断点信息的脚本文件吗?
我使用gdb来调试我的cpp代码.我用这种方式设置断点:
(gdb) break ParseDriver.cc:60
No source file named ParseDriver.cc.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (ParseDriver.cc:60) pending.
Run Code Online (Sandbox Code Playgroud)
为了简化设置断点,我编写了一个简单的gdb脚本(名为breakpoints.gdb),它只包含一行:
break ParseDriver.cc:60
Run Code Online (Sandbox Code Playgroud)
我在gdb终端中获取此脚本,但它失败了.
(gdb) source ~/breakpoints.gdb
No source file named ParseDriver.cc.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
Run Code Online (Sandbox Code Playgroud)
似乎我们需要在脚本中回答Y以设置断点.
那么,我如何在gdb脚本中回答Y?先感谢您.
根据这份出色的指南,应该能够重新编译源文件,并且只需使用“ r”使gdb开始调试新的,经过更改的二进制文件。
在gdb手册中,这似乎也暗示着:“如果自上次GDB读取符号以来,符号文件的修改时间已更改,则GDB会丢弃其符号表,然后再次读取它。”
我正在尝试在Ubuntu 16.10上调试一个简单的单个.cpp文件。通过编译后g++ -ggdb -std=c++11 589.cpp,我可以照常进行调试。
GNU gdb (Ubuntu 7.11.90.20161005-0ubuntu2) 7.11.90.20161005-git
[...]
(gdb) break main
Breakpoint 1 at 0x2754: file 589.cpp, line 204.
(gdb) r
Starting program: /home/code/589
Breakpoint 1, main () at 589.cpp:204
(gdb) n
(gdb) k
Kill the program being debugged? (y or n) y
Run Code Online (Sandbox Code Playgroud)
在这里,我对源文件进行了较小的更改,然后重新编译。尝试再次运行文件时:
(gdb) r
/home/code/589' has changed; re-reading symbols.
Error in re-setting breakpoint 1: Cannot access memory at address 0x55555555674b
Starting program: /home/code/598
warning: Probes-based dynamic linker …Run Code Online (Sandbox Code Playgroud) 我的理解是gdb可以监视正在运行的程序的完整状态。我可以保存在断点处暂停的gdb会话并在以后恢复该会话吗?
我的第一次尝试只是在第一个gdb会话中生成了一个核心转储,该会话在断点处暂停,然后使用该核心转储来启动第二个gdb会话。
这导致以下错误。
Program terminated with signal SIGTRAP, Trace/breakpoint trap.
Run Code Online (Sandbox Code Playgroud)
因此,将断点信息插入程序状态,很有趣。在第二次尝试中,我执行了相同的操作,但是这次我在第二次会话中添加了与第一次会话相同的断点。
仍然,我得到同样的错误。
我可以保存并重新启动gdb会话吗?如果是这样,怎么办?
我认为这并不直接相关,但我也收到了此警告。
warning: core file may not match specified executable file.
Run Code Online (Sandbox Code Playgroud)
是gdb只是简单地声明这种事情通常是可能的,还是gdb认为这可能是在运行的会话中发生的?我相信,生成核心转储的同一可执行文件正在gdb下运行。
编辑:对于其他人,这个问题:保存进程的内存以供以后使用?添加到Mats Petersson的答案和指向本文的链接:http : //blogs.msdn.com/b/oldnewthing/archive/2004/04/20/116749.aspx,这是一本有趣的文章。链接的问题还建议将进程包装在VM中。