Debugging a dynamically loaded library using gdb

I am trying to debug an application that loads dynamic libraries as plugins and is having problems with gdb to find the source files and set breakpoints at the source level.

I am creating a dynamic library ( libFoo.so ) that is compiled using a static library ( libBar.a ).

After creating libFoo.so, it moves to the plugins directory of my main application, which lives in a different folder.

At run time, the application starts and looks for this directory, and then loads libFoo.so. All code is built with debugging information, and debugging information is correctly loaded for the dynamic library.

What puzzles me is that the source code information does not load in gdb for libFoo. This means that when the code breaks into the libFoo function, I cannot see the source code using list or set breakpoints.

However, the source information from libBar (which is statically linked to libFoo.so) is perfectly loaded, and I can see the source code when I enter the code from libBar and put breakpoints in the code from libBar ...

To be more precise, what gdb shows me about shared libraries:

 (gdb) info sharedlibrary Foo From To Syms Read Shared Object Library 0x... 0x... Yes /path/to/mainapp/plugins/libFoo.so 

OK, so my library is loaded with debugging symbols.

 (gdb) info sources Source files for which symbols have been read in: ... /path/to/mainapp/src/main.cpp /path/to/plugins/libs/bar/bar.cpp ... 

So, gdb correctly loaded the source code from libBar.a , even if it lives in a different folder than the executable, but not from libFoo, which was built with it?

I also tried adding the libFoo source directory with dir to gdb, but to no avail.

Where can I look to help gdb make a link between libFoo and its source? Can I specify the source files explicitly (and not just the directory with dir )? Or is there some kind of option that I am missing?

+5
source share

Source: https://habr.com/ru/post/1243568/


All Articles