Supported on windows
Supported on linux
Not supported on embedded
Supported on android

set auto-solib-add command

Specifies whether GDB should automatically load symbols when it detects that a shared library has been loaded.

Syntax

set auto-solib-add on
set auto-solib-add off
show auto-solib-add

Modes

on
In this mode GDB will automatically load the symbols when it detects that a shared library has been loaded.
off
In this mode GDB will not automatically load symbols for newly loaded shared libraries. You can load the symbols manually using the sharedlibrary command.

Default value

The default value for the auto-solib-add variable is on.

Examples

In this example we will debug a simple program that loads and unloads a shared library in a loop:

#include <stdio.h>
#include <dlfcn.h>

int main()
{
    for (int i = 0; i < 5; i++)
    {
        void *p = dlopen("./libTest.so", RTLD_NOW);
        printf("Loaded library\n");
        dlclose(p);
        printf("Unloaded library\n");
    }
    return 0;
}

The following example shows how the set auto-solib-add command can disable the automatic symbol loading normally performed by GDB:

(gdb) break 8
Breakpoint 1 at 0x80484b7: file main.cpp, line 8.
(gdb) run
Starting program: /home/testuser/libtest/testApp

Breakpoint 1, main () at main.cpp:8
8 void *p = dlopen("./libTest.so", RTLD_NOW);
(gdb) info shared
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f Yes /lib/ld-linux.so.2
0xb7fc2a60 0xb7fc3a08 Yes /lib/i386-linux-gnu/libdl.so.2
0xb7e2ef10 0xb7f635cc Yes /lib/i386-linux-gnu/libc.so.6
(gdb) next
9 printf("Loaded library\n");
(gdb) info shared
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f Yes /lib/ld-linux.so.2
0xb7fc2a60 0xb7fc3a08 Yes /lib/i386-linux-gnu/libdl.so.2
0xb7e2ef10 0xb7f635cc Yes /lib/i386-linux-gnu/libc.so.6
0xb7fd83a0 0xb7fd84c8 Yes ./libTest.so
(gdb) continue
Continuing.
Loaded library
Unloaded library

Breakpoint 1, main () at main.cpp:8
8 void *p = dlopen("./libTest.so", RTLD_NOW);
(gdb) info shared
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f Yes /lib/ld-linux.so.2
0xb7fc2a60 0xb7fc3a08 Yes /lib/i386-linux-gnu/libdl.so.2
0xb7e2ef10 0xb7f635cc Yes /lib/i386-linux-gnu/libc.so.6
(gdb) set auto-solib-add off
(gdb) next
9 printf("Loaded library\n");
(gdb) info shared
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f Yes /lib/ld-linux.so.2
0xb7fc2a60 0xb7fc3a08 Yes /lib/i386-linux-gnu/libdl.so.2
0xb7e2ef10 0xb7f635cc Yes /lib/i386-linux-gnu/libc.so.6
0xb7fd83a0 0xb7fd84c8 No ./libTest.so
(gdb) sharedlibrary
Reading symbols from ./libTest.so...done.
Loaded symbols for ./libTest.so
(gdb) info shared
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f Yes /lib/ld-linux.so.2
0xb7fc2a60 0xb7fc3a08 Yes /lib/i386-linux-gnu/libdl.so.2
0xb7e2ef10 0xb7f635cc Yes /lib/i386-linux-gnu/libc.so.6
0xb7fd83a0 0xb7fd84c8 Yes ./libTest.so

Compatibility with VisualGDB

Normally you can control symbol loading using the Modules and the Call Stack windows in Visual Studio. Alternatively you can run the set auto-solib-add command under VisualGDB using the GDB Session window.

See also