Debugging / tracing inside a shared library at runtime?

I am trying to understand how a particular library works. I collected it with my additional privileges, and everything is fine. Now I want to stop the sample program at runtime in order to look at the call stack, but I cannot figure out how to do this with gdb. The function I want to break is inside the shared library. I reviewed the previous question here on SO, but the approach does not work for me. This language belongs to C ++. I tried to provide the file name and line number, but gdb refuses to understand this, it only displays the source files from the demo application.

Any suggestions?

+7
c ++ debugging shared-libraries gdb
source share
3 answers

You can first "break the core". When you click this, you need to load the shared library, and you can set a breakpoint in any of its routines.

+4
source share

There are two cases to consider (and your question does not make it clear in which case you have):
- your executable file is directly linked to the shared library:
this means that GDB will β€œsee” the characters (and sources) from the shared library when you stop at the main
- your executable file dynamically loads the shared library (e.g. via dlopen ):
in this case, GDB will not β€œsee” your shared library until dlopen completes.

Since you cannot see the symbols when you stop at the main thing, I assume that you have a second case. You can do "set stop-on-solib-events 1" at the prompt (gdb) , and GDB will stop every time a new shared library is loaded (or unloaded).

You can see which GDB libraries "knows" about with the info shared command.
Wait until you see your target library on this list before trying to set breakpoints in it.

+3
source share

Check this:

http://linux.die.net/man/1/ltrace

he will track your calls in the library - perhaps it will be useful.

And "strace" does the same for system calls.

And with this you can find the entry point ... You can set a breakpoint in GDB this way (although I can’t explain the details myself)

+1
source share

All Articles