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

2

15

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?

Tuyere answered 22/11, 2013 at 13:21 Comment(2)
objdump filename -x | grep 'debug'Frit
possible duplicate of How to check if program was compiled with debug symbols?Nona
S
16

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.

Surbeck answered 22/11, 2013 at 13:26 Comment(1)
I can see libQt5Gui.so.5.5.1 which has debug symbols in different file libQt5Gui.so.5.5.1.debug but the file command shows not stripped for the libQt5Gui.so.5.5.1Freeboard
T
23

Note that not stripped doesn't imply debug symbols.

Library code:

//myshared.c
#include <stdio.h>

void print_from_lib()
{
    printf("Printed from shared library\n");
}

Compiling with and without debug flags:

gcc -c -Wall -Werror -fpic myshared.c
gcc -shared -o libmyshared.so myshared.o
gcc -g -c -Wall -Werror -fpic myshared.c -o myshared-g.o
gcc -g -shared -o libmyshared-g.so myshared-g.o

Checking with file

$ file libmyshared.so
libmyshared.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=1ad3b94d5c8a7392c2140a647254753221a152cd, not stripped
$ file libmyshared-g.so 
libmyshared-g.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0268eaf97e5a670d2f7e767a011be6f06a83090a, not stripped

Both claim they aren't stripped. However only libmyshared-g.so shows the symbols:

$ objdump --syms libmyshared.so | grep debug
$ objdump --syms libmyshared-g.so | grep debug
0000000000000000 l    d  .debug_aranges 0000000000000000              .debug_aranges
0000000000000000 l    d  .debug_info    0000000000000000              .debug_info
0000000000000000 l    d  .debug_abbrev  0000000000000000              .debug_abbrev
0000000000000000 l    d  .debug_line    0000000000000000              .debug_line
0000000000000000 l    d  .debug_str 0000000000000000              .debug_str
Tisbe answered 23/7, 2017 at 21:36 Comment(1)
This should be the correct answer, complemented with clarifications on what stripping is.Noyade
S
16

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.

Surbeck answered 22/11, 2013 at 13:26 Comment(1)
I can see libQt5Gui.so.5.5.1 which has debug symbols in different file libQt5Gui.so.5.5.1.debug but the file command shows not stripped for the libQt5Gui.so.5.5.1Freeboard

© 2022 - 2024 — McMap. All rights reserved.