Search code examples
linuxgccgdbdwarf

Dump debug_loc section from executable


How do I dump debug_loc section from an executable on Linux if default options (-g) are provided to GCC while compiling a C file? I use readelf linux utility.

GCC by default produces DWARF info in DWARF4 format, so if I pass -g-dwarf2 I can see .debug_loc section but how do inspect that section if info is generated with default options as I don't see the section in dump?


Solution

  • Do you use a recent version of binutils? On Ubuntu 14.04 I can build executable with "gcc -g test.c -o test".

    With "readelf --debug-dump=info test" I can confirm it's using DWARF 4.

    After that, you have (at least) two ways to dump the contents of .debug_line section.

    readelf --debug-dump=decodedline test

    This will dump decoded line number information. You get line==address mappings directly.

    There is also:

    readelf --debug-dump=rawline test

    This gets you raw debug_line contents.