I'm trying to understand how a certain library works. I've compiled it with my added prinfts and everything is great. Now I want to stop the example program during runtime to look at the call stack, but I can't quite figure out how to do it with gdb. The function I want to break on, is inside a shared library. I've reviewed a previous question here on SO, but the approach doesn't work for me. The language in question is C++. I've attempted to provide the filename and line number, but gdb refuses to understand that, it only lists the source files from the demo app.
Any suggestions?
You can do "break main" first. By the time you hit that, the shared library should be loaded, and you can then set a breakpoint in any of its routines.
There are two cases to consider (and your question doesn't make it clear which case you have):
- your executable is linked with the shared library directly:
this means that GDB
will "see" the symbols (and sources) from shared library when you stop on main
- your executable dynamically loads the shared library (e.g. via dlopen
):
in that case, GDB
will not "see" your shared library until after dlopen
completes.
Since you can't see the symbols when you stop at main, I am guessing you have the second case.
You can do "set stop-on-solib-events 1"
at the (gdb)
prompt, and GDB
will stop every time a new shared library is loaded (or unloaded).
You can see which libraries GDB
"knows" about via info shared
command.
Just wait until you see your target library in that list, before attempting to set breakpoints in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With