gdb -x shared library breakpoint

陌路散爱 提交于 2019-12-11 16:22:12

问题


I have a list of breakpoints which I want to add each time I debug a particular program. I created a file that contain the breakpoints and used gdb -x "file" commend, but all the breakpoints that are pending on future shared library load wasn't added. Is there a way to fix this problem?


回答1:


In your script set breakpoints in shared libraries as pending and when the shared libraries are loaded your breakpoints will be correctly set.

(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.

And this is an example of a script (suppose print_in_lib in in a shared library that will be loaded with dlopen):

file main
set breakpoint pending on
b print_in_lib
r

And this is its output:

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)


来源:https://stackoverflow.com/questions/11273564/gdb-x-shared-library-breakpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!