Next: , Previous: Separate Debug Files, Up: GDB Files


18.3 Debugging information in a special section

Some systems ship pre-built executables and libraries that have a special ‘.gnu_debugdata’ section. This feature is called MiniDebugInfo. This section holds an LZMA-compressed object and is used to supply extra symbols for backtraces.

The intent of this section is to provide extra minimal debugging information for use in simple backtraces. It is not intended to be a replacement for full separate debugging information (see Separate Debug Files). The example below shows the intended use; however, gdb does not currently put restrictions on what sort of debugging information might be included in the section.

gdb has support for this extension. If the section exists, then it is used provided that no other source of debugging information can be found, and that gdb was configured with LZMA support.

This section can be easily created using objcopy and other standard utilities:

     # Extract the dynamic symbols from the main binary, there is no need
     # to also have these in the normal symbol table
     nm -D binary --format=posix --defined-only \
       | awk '{ print $1 }' | sort > dynsyms
     
     # Extract all the text (i.e. function) symbols from the debuginfo .
     nm binary --format=posix --defined-only \
       | awk '{ if ($2 == "T" || $2 == "t") print $1 }' \
       | sort > funcsyms
     
     # Keep all the function symbols not already in the dynamic symbol
     # table.
     comm -13 dynsyms funcsyms > keep_symbols
     
     # Copy the full debuginfo, keeping only a minimal set of symbols and
     # removing some unnecessary sections.
     objcopy -S --remove-section .gdb_index --remove-section .comment \
       --keep-symbols=keep_symbols binary mini_debuginfo
     
     # Inject the compressed data into the .gnu_debugdata section of the
     # original binary.
     xz mini_debuginfo
     objcopy --add-section .gnu_debugdata=mini_debuginfo.xz binary