1
votes

I would have thought this question was already asked, but I couldn't find it. Bear with me if it was.

I am trying out modifications to an existing program in a debian installation.

The program, call it foo, when compiled creates some of it's own shared libraries. I would like to debug the program and step into one of the local shared libraries, call it libbar.so.

However since this is an existing program there is already a /usr/lib/libbar.so, which I do not want to overwrite.

So how do I get gdb to use the local libbar.so?

1

1 Answers

0
votes

The program, call it foo, when compiled creates some of it's own shared libraries.

Do you mean that the program, at runtime, writes out to disk its own copy of libbar.so?

That is highly unusual. What you probably mean is that when building the program, a local libbar.so is also built.

I would like to debug the program and step into one of the local shared libraries, call it libbar.so.

This should already be happening if in fact the program loaded local libbar.so.

What's probably happening is that when you run the program, it loads /usr/lib/libbar.so, and then GDB uses what the program has already loaded (you can see what GDB believes is loaded by using info shared GDB command).

If you want your program to load local copy of libbar.so, you need to adjust LD_LIBRARY_PATH, or modify the DT_RPATH or DT_RUNPATH baked into the program, using -Wl,-rpath=/path/to/lib (where the local libbar.so is located in /path/to/lib/libbar.so). Once you do that, GDB will automatically pick up the local libbar.so.