Reputation: 3460
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?
Upvotes: 7
Views: 9803
Reputation: 3293
Check this out:
http://linux.die.net/man/1/ltrace
it will trace your library calls - probably be useful.
And "strace" does the same thing for system calls.
And with that you should be able to find an entry point... You could set a breakpoint in GDB that way (although i can't explain the details myself)
Upvotes: 1
Reputation: 213526
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.
Upvotes: 4
Reputation: 45045
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.
Upvotes: 4