What is DWARF Introduction to the DWARF Format
Reference Introduction to the DWARF Debugging Format, Michael J. Eager, Eager Consulting DWARF Debugging Information Format, Version 4, DWARF Debugging Information Format Committee; Gnu gold linker, GNU Binutils Gnu BFD, GNU Binutils
Introduction DWARF is a format for debugging. DWARF data are several sections in the object file The purpose is to figure out the mapping between object code and source code. DWARF is a tree structure with nodes called Debugging Information Entry (DIE). The tree describes the whole source program readelf --dump-debug to dump the debug data
Debug Sections NamesFunctions.debug_abbrevAbbreviations used in the.debug_info section.debug_infoThe core DWARF data containing DIEs.debug_frameCall Frame Information similar to eh_frame.debug_lineLine Number Program.debug_macinfoMacro descriptions.debug_arangesA mapping between memory address and compilation.debug_locA lookup table for global objects and functions.debug_pubnamesA lookup table for global objects and functions.debug_pubtypesA lookup table for global types.debug_rangesAddress ranges referenced by DIEs.debug_strString table used by.debug_info
DIE DIEs are used to represent types, variables, or functions. DIE contains a Tag and a set of Attributes – TAG Specify what this DIE describes DW_TAG_XXX : DW_TAG_base_type, DW_TAG_variable,... – Attribute A detail description such as name, size, address,… DW_AT_XXX: DW_AT_name, DW_AT_byte_size,…
Base Types and Variables Describes 32-bit and 16-bit int base type DW_TAG_base_type DW_AT_name = int DW_AT_byte_size = 4 DW_AT_encoding = signed DW_TAG_base_type DW_AT_name = int DW_AT_byte_size = 2 DW_AT_encoding = signed : DW_TAG_variable DW_AT_name = px DW_AT_type = : DW_TAG_pointer_type DW_AT_byte_size = 4 DW_AT_type = : DW_TAG_base_type DW_AT_name = word DW_AT_byte_size = 4 DW_AT_encoding = signed Describes int *px
Describe Executable Code Compilation Unit DIE – Each separately compiled source file is a compilation unit – Each compilation unit has a DIE to describe its name, directory, address, … – The parent of all other DIEs for this compilation unit Functions – Subprograms DIE Describes name, low/high pc Return value : DW_AT_TYPE – Input parameter DIE Owned by subprogram Described parameter name, type, …
Executable Code, an Example 1 DW_TAG_compile_unit [has children] DW_AT_producer DW_FORM_strp DW_AT_language DW_FORM_data1 DW_AT_name DW_FORM_strp DW_AT_comp_dir DW_FORM_strp DW_AT_low_pc DW_FORM_addr DW_AT_high_pc DW_FORM_addr DW_AT_stmt_list DW_FORM_data4 Compilation Unit DIE : Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_producer : (indirect string, offset: 0x0): GNU C DW_AT_language : 1 (ANSI C) DW_AT_name : (indirect string, offset: 0xc): test.c DW_AT_comp_dir : (indirect string, offset: 0x13): /proj/mtk02422/test/test2 DW_AT_low_pc : 0x0 DW_AT_high_pc : 0x30 DW_AT_stmt_list : 0x0. debug_abbrev. debug_info int foo(int i) { return i++; } int foo(int i) { return i++; } Describe the data types Describe the value
Executable Code, an Example Subprograms DIE : Abbrev Number: 2 (DW_TAG_subprogram) DW_AT_external : 1 DW_AT_name : foo DW_AT_decl_file : 1 DW_AT_decl_line : 1 DW_AT_prototyped : 1 DW_AT_type : DW_AT_low_pc : 0x0 DW_AT_high_pc : 0x30 DW_AT_frame_base : 0x0 (location list) DW_AT_sibling : … : Abbrev Number: 4 (DW_TAG_base_type) DW_AT_byte_size : 4 DW_AT_encoding : 5 (signed) DW_AT_name : int. debug_info
Other DWARF Data Line Number Table –.debug_line – Mapping between the source lines and the memory address – Line number program The byte-coded instruction stream – State machine Expand the line number program and recreate the line number table Macro Information –.debug_macinfo Call Frame Information –.debug_frame – Virtually unwind and find out the desired data in the call stack – CIE (Common Information Entry) – FDE (Frame Description Entry)
What linkers should do? Related options – --strip-debug Strip the debugging information – --strip-debug-non-line Emit only debug line number information (gold only) – --strip-debug-gdb Strip debug symbols that are unused by gdb (at least version 6.7) (gold only) Section merge, applying relocation (Normal passes) Post processing – Compress the sections – Reduce the debug output data.debug_abbrev.debug_info DWARF reader – For error message