Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prepend a directory the library path when loading a core file in gdb on Linux

I have a core file generated on a remote system that I don't have direct access to. I also have local copies of the library files from the remote system, and the executable file for the crashing program.

I'd like to analyse this core dump in gdb.

For example:

gdb path/to/executable path/to/corefile 

My libraries are in the current directory.

In the past I've seen debuggers implement this by supplying the option "-p ." or "-p /=."; so my question is:

How can I specify that libraries be loaded first from paths relative to my current directory when analysing a corefile in gdb?

like image 529
Mike Tunnicliffe Avatar asked Sep 17 '08 15:09

Mike Tunnicliffe


People also ask

Do you need set Solib search path or set Sysroot?

If you want to use ' solib-search-path ' instead of ' sysroot ', be sure to set ' sysroot ' to a nonexistent directory to prevent GDB from finding your host's libraries. ' sysroot ' is preferred; setting it to a nonexistent directory may interfere with automatic loading of shared library symbols.

What is core file in GDB?

What is a core file? A core file is an image of a process that has crashed It contains all process information pertinent to debugging: contents of hardware registers, process status, and process data. Gdb will allow you use this file to determine where your program crashed.

How do I load a shared library?

Once you've created a shared library, you'll want to install it. The simple approach is simply to copy the library into one of the standard directories (e.g., /usr/lib) and run ldconfig(8). Finally, when you compile your programs, you'll need to tell the linker about any static and shared libraries that you're using.


1 Answers

Start gdb without specifying the executable or core file, then type the following commands:

set solib-absolute-prefix ./usr file path/to/executable core-file path/to/corefile 

You will need to make sure to mirror your library path exactly from the target system. The above is meant for debugging targets that don't match your host, that is why it's important to replicate your root filesystem structure containing your libraries.

If you are remote debugging a server that is the same architecture and Linux/glibc version as your host, then you can do as fd suggested:

set solib-search-path <path> 

If you are trying to override some of the libraries, but not all then you can copy the target library directory structure into a temporary place and use the solib-absolute-prefix solution described above.

like image 179
Drew Frezell Avatar answered Oct 05 '22 09:10

Drew Frezell