In a script, set breakpoints in shared libraries as pending, and when shared libraries load, your breakpoints will be set correctly.
(gdb) help set breakpoint pending Set debugger 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 script (suppose print_in_lib in in a shared library to be loaded using dlopen ):
file main set breakpoint pending on b print_in_lib r
And this is his conclusion:
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
source share