0

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

4

1 回答 1

4

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

(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)
于 2012-06-30T11:26:47.273 回答