4

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

user04556
  • 327
  • 1
  • 4
  • 14
  • @EmployedRussian, does set sysroot and set solib-absolute-prefix are identical – user04556 Nov 22 '17 at 23:18
  • 2
    I think they are same – PMat Nov 22 '17 at 23:21
  • 2
    They are aliases: `help solib-absolute-prefix`: `Set an alternate system root.` – Employed Russian Nov 23 '17 at 00:43
  • @EmployedRussian The duplicated question is not a duplicate. solib-absolute-prefix is not the same thing than solib-search-path. This question is "set sysroot" vs "set solib-search-path". The question marked as duplicate is "set solib-search-path" vs "set solib-absolute-prefix". – Étienne Aug 10 '20 at 14:49
  • Do you use absolute paths or relative? Please add examples of your paths passed to set commands. – Alexander Ushakov Aug 11 '20 at 07:19

1 Answers1

2

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"

Étienne
  • 4,773
  • 2
  • 33
  • 58