Wednesday, October 28, 2015

gdb unable to find shared symbols

This primarily happens when you trace your gdb to an unknown terrain - i.e. you enter part of the shared library's code whose symbols have not been loaded by gdb yet.

I encountered this problem while building a device mapper library. Even though I spent a couple of hours going through the Makefile, ensuring that I was configuring the library using the --enable-debug option, when I ran the library with gdb and traced to the part of the code located in the library using 'n' and 's' commands (Please read what they are meant for if you don't have an idea about them), I kept falling into the same pit - no debug symbols found.

I then came across this blog

Which basically stated that all shared libraries loaded by gdb for a particular run can be viewed using the following command:


(gdb) info sharedlibrary
From                To                  Syms Read   Shared Object Library
0x00007ffff7dd9aa0  0x00007ffff7df5590  Yes         /lib64/ld-linux-x86-64.so.2
0x00007ffff7b78330  0x00007ffff7bc320f  Yes      * /lib/libdevmapper.so.1.02
0x00007ffff77c34f0  0x00007ffff7916354  Yes         /lib/x86_64-linux-gnu/libc.so.6
0x00007ffff759e190  0x00007ffff75a1167  Yes         /lib/x86_64-linux-gnu/librt.so.1
0x00007ffff7383a90  0x00007ffff7390c41  Yes         /lib/x86_64-linux-gnu/libpthread.so.0
0x00007ffff707b5a0  0x00007ffff70ecc61  Yes         /lib/x86_64-linux-gnu/libm.so.6
(* No debug symbols found)

This made me realise that /lib/libdevmapper.so.1.02 is the library for the default devicemapper package and that my own library with all debug symbols was not being read by gdb at all!

To correct this, I simply installed my library to override the existing /lib/libdevmapper.so.1.02 library. Rerunning gdb now gives me access to all symbols in my libdevmapper.so.1.02 library!

(gdb) info sharedlibrary
From                To                  Syms Read   Shared Object Library
0x00007ffff7dd9aa0  0x00007ffff7df5590  Yes         /lib64/ld-linux-x86-64.so.2
0x00007ffff7b78330  0x00007ffff7bc320f  Yes         /lib/libdevmapper.so.1.02
0x00007ffff77c34f0  0x00007ffff7916354  Yes         /lib/x86_64-linux-gnu/libc.so.6
0x00007ffff759e190  0x00007ffff75a1167  Yes         /lib/x86_64-linux-gnu/librt.so.1
0x00007ffff7383a90  0x00007ffff7390c41  Yes         /lib/x86_64-linux-gnu/libpthread.so.0
0x00007ffff707b5a0  0x00007ffff70ecc61  Yes         /lib/x86_64-linux-gnu/libm.so.6

Go nuts with gdb!