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

set stop-on-solib-events command

Specifies whether GDB should stop the target when a shared library is loaded or unloaded.

Syntax

set stop-on-solib-events 0
set stop-on-solib-events 1
show stop-on-solib-events

Modes

0
GDB will not stop the target when a shared library is loaded and unloaded. GDB will automatically update your breakpoints and continue.
1
When a shared library is loaded or unloaded GDB will stop as if a breakpoint has been hit. You will have a chance to inspect the loaded libraries, modify your breakpoints and resume the target.

Default value

The default value for the stop-on-solib-events variable is 0.

Examples

In this example we will debug a simple shared library:

#include <stdio.h>

int func()
{
    printf("In func()\n");
    return 0;
}

We will use a simple program to test our library:

#include <stdio.h>

int func();

int main()
{
    printf("In main()\n");
    func();
    return 0;
}

We will build the application and the library:

cd /home/testuser/libtest
g++ -ggdb -fPIC -shared lib.cpp -o libTest.so
g++ -ggdb main.cpp libTest.so -o testApp -Wl,--rpath='$ORIGIN'

Then we will run GDB and enable the set stop-on-solib-events option:

cd /home/testuser/libtest
gdb testApp

Note how GDB will stop when ld-linux.so and libTest.so are loaded:

GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/testuser/libtest/testApp...done.
(gdb) show stop-on-solib-events
Stopping for shared library events is 0.
(gdb) set stop-on-solib-events 1
(gdb) run
Starting program: /home/testuser/libtest/testApp
Stopped due to shared library event
(gdb) info shared
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f Yes (*) /lib/ld-linux.so.2
(*): Shared library is missing debugging information.
(gdb) continue
Continuing.
Stopped due to shared library event
(gdb) info shared
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f Yes (*) /lib/ld-linux.so.2
0xb7fd83a0 0xb7fd84c8 Yes /home/testuser/libtest/libTest.so
0xb7e35f10 0xb7f6635c Yes (*) /lib/i386-linux-gnu/libc.so.6
(*): Shared library is missing debugging information.
(gdb) continue
Continuing.
In main()
In func()
[Inferior 1 (process 5936) exited normally]
(gdb) quit

Compatibility with VisualGDB

VisualGDB automatically enables the set stop-on-solib-events feature when debugging your projects. It will automatically update the state of your breakpoints in Visual Studio and continue from the shared library events.

See also