我有一个断点列表,我想在每次调试特定程序时添加这些断点。我创建了一个包含断点的文件并使用了gdb -x“file”命令,但未添加所有未来共享库加载中待处理的断点。有没有办法解决这个问题?
答案 0 :(得分: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)