linux - gdb -x 共享库断点

标签 linux bash gdb breakpoints

我有一个断点列表,我想在每次调试特定程序时添加这些断点。我创建了一个包含断点的文件并使用了 gdb -x "file"commend,但未添加所有在未来共享库加载时挂起的断点。有办法解决这个问题吗?

最佳答案

在您的脚本中,将共享库中的断点设置为挂起,当加载共享库时,您的断点将被正确设置。

(gdb) help set breakpoint pending
Set debugger's behavior regarding pending breakpoints.
If on, an unrecognized breakpoint location will cause gdb to create a
pending breakpoint.  If off, an unrecognized breakpoint location results in
an error.  If auto, an unrecognized breakpoint location results in a
user-query to see if a pending breakpoint should be created.

这是一个脚本示例(假设 print_in_lib 位于将使用 dlopen 加载的共享库中):

file main
set breakpoint pending on
b print_in_lib
r

这是它的输出:

host: srv2-x64rh5-01, OS: Linux 2.6.18-238.el5>gdb -q
Function "print_in_lib" not defined.
Breakpoint 1 (print_in_lib) pending.
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x2aaaaaaab000
thousands: 1
print_debug: 0

Breakpoint 1, print_in_lib (print_debug=0) at my_lib.cpp:7
7           if (print_debug) {
(gdb) bt
#0  print_in_lib (print_debug=0) at my_lib.cpp:7
#1  0x00000000004008ab in main (argc=<value optimized out>, argv=<value optimized out>) at main.cpp:37
(gdb)

关于linux - gdb -x 共享库断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11273564/

相关文章:

linux - 克隆 git 存储库时权限被拒绝

git - 使用 bash 脚本获取当前分支中的提交数

linux - 对不同文件运行命令并存储输出结果

python - 为什么在 CUDA 内核中没有断点的情况下执行相同的程序时,cuda-gdb 比 gdb 慢很多?

android - 在 Android 上使用 GDB 调试 native 应用程序

linux - 为什么 ((counter++)) 在 counter == 0 时失败?

linux - salt 中不允许映射值

xml - 在 bash 中基于 XML 内容验证获取内容

gcc - objcopy 和 dsymutil 有什么区别?

c++ - 在 linux 中使用 win32 api?