1

I'm using the GCC ARM cross-compiler (arm-none-eabi-*) and am using a proprietary debugger. The debugger can highlight resultant assembly for a selected source line. Using the nm and objdump, I can see that the binary has more than one .debug_* sections. It's obvious to conclude that the debugger is using information contained in these sections to map source lines to the disassembly (and vice versa). But I'd like to how. I'd like to know what information these sections contain, how they're related, and how to make sense out of them. In short, how would I read the sections and make use of them, if I were to write a debugger (or at least, a tool that can display these mappings: source to disassembly, and back, number of disassembly lines per source line). Assume zero compilation optimization.

Presumably there's some doc that describes the format of these sections?

1

1 Answer 1

1

The .debug_* sections contain data in a format described by the DWARF debugging standard. The standard has a web site where you can download the standard specification: http://www.dwarfstd.org/

There are libraries available for parsing the stored format (which is highly condensed to save space), one such is libdwarf available here: http://reality.sgiweb.org/davea/dwarf.html

In short, the different sections contain different aspects of the source program, and how they map to the target machine architecture (code and data addresses). Information which is typically lost in the compilation process is represented by a tree of Debug Information Entries, which are structures with an identifying tag, and various attributes. For example, the DIE for a variable declaration is represented by a DIE with the DW_TAG_variable tag, and can have such attributes as: name, file/line/column where it is declared, memory location in the object file, etc.

The .debug_info and .debug_abbrev sections together represent the tree of Debug Information Entries. The .debug_line section contains information that allows the debugger to reconstruct a complete table mapping source code line to object code address (and contains other information, like whether or not a source code line is the start of a statement, and is the start of a basic block, etc.).

Other sections contain call frame information, and accelerated lookup tables for quickly finding variable DIEs and types by name, and more. It's all described in the standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.