How do I know if a library is compiled with -g?

I have compiled libraries on x86 Linux, and I want to quickly determine if they were compiled using debugging symbols.

+89
c debugging gdb debug-symbols
Jan 04 '10 at 13:52
source share
7 answers

If you are running Linux, use objdump --debugging . There must be an entry for each object file in the library. For object files without character debugging, you will see something like:

 objdump --debugging libvoidincr.a In archive libvoidincr.a: voidincr.o: file format elf64-x86-64 

If there are debugging symbols, the output will be much more verbose.

+71
Jan 04
source share

Proposed team

 objdump --debugging libinspected.a objdump --debugging libinspected.so 

always gives me the same result, at least on Ubuntu / Linaro 4.5.2:

 libinspected.a: file format elf64-x86-64 libinspected.so: file format elf64-x86-64 

regardless of whether the archived / shared library was built with or without the -g option

Which really helped me determine if -g readelf tool was used:

 readelf --debug-dump=decodedline libinspected.so 

or

 readelf --debug-dump=line libinspected.so 

This will display a set of lines consisting of the original file name, line number and address, if such debugging information is included in the library, otherwise it will not print anything.

You can pass any value that you find necessary for the --debug-dump parameter instead of decodedline .

+79
Oct 09
source share

nm -a <lib> will output all characters from the library, including debugging.

So, you can compare the outputs nm <lib> and nm -a <lib> - if they are different, your library contains some debugging symbols.

+25
Jan 04 '10 at
source share

What helped:

 gdb mylib.so 

It prints when no debugging symbols are found:

 Reading symbols from mylib.so...(no debugging symbols found)...done. 

Or if found:

 Reading symbols from mylib.so...done. 

None of the earlier answers gave me meaningful results: libs without debugging symbols produced a lot of results, etc.

+24
Jun 06 '16 at 10:02
source share

On OSX, you can use dsymutil -s and dwarfdump .

Using dsymutil -s <lib_file> | more dsymutil -s <lib_file> | more dsymutil -s <lib_file> | more dsymutil -s <lib_file> | more you will see the paths to the source files in files that have debugging symbols, but only function names otherwise.

+14
Aug 28 '13 at 20:41
source share

You can use objdump for this.

EDIT: From the man page:

 -W --dwarf Displays the contents of the DWARF debug sections in the file, if any are present. 
+11
Jan 04
source share

Answers suggesting using objdump --debugging or objdump --debugging readelf --debug-dump=... do not work if the debug information is stored in a file separately from the binary file, i.e. the section of the debug link is in the binary file. Perhaps this can be called a mistake in readelf.

The following code should handle correctly:

 # Test whether debug information is available for a given binary has_debug_info() { readelf -S "$1" | grep -q " \(.debug_info\)\|\(.gnu_debuglink\) " } 

For more information, see Split Debug Files in the GDB Manual.

+4
Sep 14 '16 at 0:06
source share



All Articles