Skip to content
Advertisement

How to know the given shared library is built with debug symbols or not?

I have some compiled libraries i.e. shared library (*.so) on x86 Linux and I want to quickly determine whether they were compiled with debugging symbols (i.e with -g/debug option) or not.

How to check it?

Advertisement

Answer

You can use the file command to see if a file is stripped. Basically, this means that the debugging symbols are there or not.

Here’s one file from my system:

$ file libjsd.so
     libjsd.so: ELF 32-bit LSB shared object, 
     Intel 80386, version 1 (SYSV), dynamically linked, 
     stripped

Notice the stripped.

Here’s something I compiled:

$ file libprofile_rt.so
libprofile_rt.so: ELF 64-bit LSB shared object, x86-64, 
      version 1 (SYSV), dynamically linked, 
     BuildID[sha1]=0x..., not stripped

see the ‘not stripped’, that indicates it has debugging symbols.

It’s also possible to separate debug symbols from the shared object itself using objcopy. This would extract symbols in another file and then you’d need to know the link to get them back. You can see instructions for doing this with gdb using build-ids. This is helpful if you want to deliver something without the symbols but then be able to debug it in a pinch from a dump.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement