Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set sysroot command vs set solib-search-path command

Tags:

c++

c

gdb

I am confused by the commands set solib-search-path and set sysroot, not sure when to use one or another. In my case symbols are only loaded when i used both the commands. Is it always both the commands are required and what does each command does.

For here http://visualgdb.com/gdbreference/commands/, it looks like sysroot looks in subdirectories too, then why is solib-search-path required, if both search for libraries and load symbols from those libraries

like image 899
user04556 Avatar asked Oct 24 '25 19:10

user04556


1 Answers

gdb searches first for libraries in sysroot (with an absolute path), and then only if it fails to find them it searches into solib-search-path (with a relative path).

For that reason, when using gdb server / remote debugging you probably want to use ONLY gdb's sysroot option. On a Linux system using solib-search-path will NOT work unless you change the value of sysroot, because the default value of sysroot is target, meaning that gdb is loading the so-file found on the filesystem you are debugging. This is also what is indicated in gdb's documentation:

set solib-search-path path

colon-separated list of directories to search for shared libraries. ‘solib-search-path’ is used after ‘sysroot’ fails to locate the library, or if the path to the library is relative instead of absolute. 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.

As indicated in this thread, the use-case for solib-search-path is rather:

solib-search-path is there mostly to help targets like Windows that don't report to the debugger the full path to the shared library. GNU/Linux always works with full patchs, such as "/usr/lib/libjpeg.so.8"

like image 92
Étienne Avatar answered Oct 26 '25 11:10

Étienne