Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I inspect a static library to see if the debug symbols are being exported?

I have a static library I'm building in debug mode, but when I step into it I still get disassembly. I want to know how to use nm or another tool to ensure that the debug symbols are not being stripped.

like image 671
Spilly Avatar asked Dec 20 '12 05:12

Spilly


People also ask

How do I know if a file has debugging symbols?

To check if there's debug info inside the kernel object, you can add the following at the end of the objdump command: | grep debug . If this string is found, you know the kernel object contains debug information. If not, then it's a "clean" kernel object.

How do I find the symbol in an .so file?

We can use the readelf command with the -s flag to view exported symbols: $ readelf -s lib.so Symbol table '.

What commands can be used to list the symbols stored in a static library in C?

If we want to see the contents of our library, we can use the ar option -t . We can also see the symbols in our library, using the command nm , which lists each symbol's symbol value, symbol type, and symbol name from object files.


3 Answers

You might use nm's option --debug-syms, to let nm also list debugger symbols (if any) for the object packed into a library.

For debugger symbols the second column indicates N.

Example (assumes the object example.o to be in the library)

nm --debug-syms libexample.a 

Output (excerpt):

example.o: 0000000000000000 b .bss 0000000000000000 n .comment 0000000000000000 d .data 0000000000000000 N .debug_abbrev     0000000000000000 N .debug_aranges 0000000000000000 N .debug_info 0000000000000000 N .debug_line 0000000000000000 N .debug_loc 0000000000000000 N .debug_pubnames 0000000000000000 N .debug_str 0000000000000000 r .eh_frame 0000000000000000 n .note.GNU-stack 0000000000000000 r .rodata 0000000000000000 t .text ... 

For more on this please see man nm.

like image 111
alk Avatar answered Sep 21 '22 17:09

alk


You can use the file command, available for many OSes, including Windows via Cygwin.
If it says 'not stripped' it means it has the debug info present.
As a side note, for static libs use ar to extract the .o files & use file on them directly.

like image 44
Eugen Constantin Dinca Avatar answered Sep 21 '22 17:09

Eugen Constantin Dinca


You can use strip -S libXX.a to check if your static library size has been reduce. The static library size will not change if it's not include debugging symbols.

It is works on Mac OS to check static library generated by Xcode.

Linux and Unix strip command

like image 29
eason Avatar answered Sep 22 '22 17:09

eason