gccdwarfobjcopyaddr2line

GCC. Generate limited debug info


Is there a way to force gcc to generate only subset of full debug info that will be sufficient for addr2line utility? Or any way to strip unneeded? I've tried

$ objcopy --only-keep-debug --remove-section=.debug_loc --remove-section=.debug_aranges --remove-section=.debug_frame my-elf-file

Is there anything that may be stripped in addition?


Solution

  • You want -g1. This produces minimal debug info for backtraces. From the manual:

    Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug. This includes descriptions of functions and external variables, and line number tables, but no information about local variables.

    You can also strip some of the debug info after the fact. One way to do this is described in the gdb "MiniDebugInfo" documentation.