我有一个断点列表,我想在每次调试特定程序时添加这些断点。我创建了一个包含断点的文件并使用了 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/