Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if program was compiled with debug symbols? [duplicate]

I'd like to trace some code in GIMP and therefore need GIMP with debug symbols enabled. I don't remember whether I have enabled them during compilation. How to check that without recompiling the program?

like image 319
Lukasz Czerwinski Avatar asked Jul 19 '10 19:07

Lukasz Czerwinski


People also ask

How do you know if binary is debug or Release?

If it is debug, it will display all the actual source code call you do. If it is release, it will just display the founded symbol from the symbol table.

Do debug symbols affect performance?

Load time will be increased when the debug symbols are present over when not present. The on-disk footprint will be larger. If you compiled with zero optimization then you really lose nothing. If you set optimization, then the optimized code will be less optimized because of the debug symbols.

How do I get rid of debug symbols?

To remove debugging symbols from a binary (which must be an a. out or ELF binary), run strip --strip-debug filename. Wildcards can be used to treat multiple files (use something like strip --strip-debug $LFS/tools/bin/*).

What is the meaning of debug symbols?

A debug symbol is a special kind of symbol that attaches additional information to the symbol table of an object file, such as a shared library or an executable.


2 Answers

You can use file and objdump on Linux. In particular, you can look at whether file says "stripped" or "not stripped" (under my Ubuntu 20.04.1 LTS, whether an executable is compiled with -g or not shows not stripped with file command. But the one with -g, shows with debug_info, in addition to that), and whether objdump --syms outputs anything useful (for me, it says "no symbols" for a regular build).

like image 59
Matthew Flaschen Avatar answered Oct 03 '22 04:10

Matthew Flaschen


When running the objdump --syms command, I see much more than "no symbols" in the output (at least, for kernel objects).

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.

Example of a kernel module I've compiled without debug information:

geertvc@jimi:~/mystuff/kernels/linux-3.12.6$ objdump --syms ./modules/lib/modules/3.12.6/kernel/drivers/i2c/busses/i2c-at91.ko | grep debug 

Example of that same kernel module I've compiled with debug information:

geertvc@jimi:~/mystuff/kernels/linux-3.12.6$ objdump --syms ./modules/lib/modules/3.12.6/kernel/drivers/i2c/busses/i2c-at91.ko | grep debug 00000000 l    d  .debug_frame   00000000 .debug_frame 00000000 l    d  .debug_info    00000000 .debug_info 00000000 l    d  .debug_abbrev  00000000 .debug_abbrev 00000000 l    d  .debug_loc     00000000 .debug_loc 00000000 l    d  .debug_aranges 00000000 .debug_aranges 00000000 l    d  .debug_ranges  00000000 .debug_ranges 00000000 l    d  .debug_line    00000000 .debug_line 00000000 l    d  .debug_str     00000000 .debug_str 00000010 l       .debug_frame   00000000 $d 

As you can see, the first output returns nothing, while the second output returns lines with debug in it.

Note: in my case, the file command returned me "not stripped" in both debug and non-debug case. However, the difference in size of the kernel object was remarkable:

  • approx. 16k without debug information
  • approx. 137k with debug information

Clearly, the latter version had debug information inside.

My question: is the file command reliable in such cases? From what I've experienced, I rely on the objdump --syms ... | grep debug command.

like image 39
GeertVc Avatar answered Oct 03 '22 03:10

GeertVc