Module gimli::read

source ·
Expand description

Read DWARF debugging information.

§Example Usage

Print out all of the functions in the debuggee program:

// Read the DWARF sections with whatever object loader you're using.
// These closures should return a `Reader` instance (e.g. `EndianSlice`).
let loader = |section: gimli::SectionId| { get_file_section_reader(section.name()) };
let sup_loader = |section: gimli::SectionId| { get_sup_file_section_reader(section.name()) };
let mut dwarf = gimli::Dwarf::load(loader)?;
dwarf.load_sup(sup_loader)?;

// Iterate over all compilation units.
let mut iter = dwarf.units();
while let Some(header) = iter.next()? {
    // Parse the abbreviations and other information for this compilation unit.
    let unit = dwarf.unit(header)?;

    // Iterate over all of this compilation unit's entries.
    let mut entries = unit.entries();
    while let Some((_, entry)) = entries.next_dfs()? {
        // If we find an entry for a function, print it.
        if entry.tag() == gimli::DW_TAG_subprogram {
            println!("Found a function: {:?}", entry);
        }
    }
}

Full example programs:

  • A simple parser

  • A dwarfdump clone

  • An addr2line clone

  • ddbug, a utility giving insight into code generation by making debugging information readable

  • dwprod, a tiny utility to list the compilers used to create each compilation unit within a shared library or executable (via DW_AT_producer)

  • dwarf-validate, a program to validate the integrity of some DWARF and its references between sections and compilation units.

§API Structure

  • Basic familiarity with DWARF is assumed.

  • The Dwarf type contains the commonly used DWARF sections. It has methods that simplify access to debugging data that spans multiple sections. Use of this type is optional, but recommended.

  • The DwarfPackage type contains the DWARF package (DWP) sections. It has methods to find a DWARF object (DWO) within the package.

  • Each section gets its own type. Consider these types the entry points to the library:

  • Each section type exposes methods for accessing the debugging data encoded in that section. For example, the DebugInfo struct has the units method for iterating over the compilation units defined within it.

  • Offsets into a section are strongly typed: an offset into .debug_info is the DebugInfoOffset type. It cannot be used to index into the DebugLine type because DebugLine represents the .debug_line section. There are similar types for offsets relative to a compilation unit rather than a section.

§Using with FallibleIterator

The standard library’s Iterator trait and related APIs do not play well with iterators where the next operation is fallible. One can make the Iterator’s associated Item type be a Result<T, E>, however the provided methods cannot gracefully handle the case when an Err is returned.

This situation led to the fallible-iterator crate’s existence. You can read more of the rationale for its existence in its docs. The crate provides the helpers you have come to expect (eg map, filter, etc) for iterators that can fail.

gimli’s many lazy parsing iterators are a perfect match for the fallible-iterator crate’s FallibleIterator trait because parsing is not done eagerly. Parse errors later in the input might only be discovered after having iterated through many items.

To use gimli iterators with FallibleIterator, import the crate and trait into your code:

// Use the `FallibleIterator` trait so its methods are in scope!
use fallible_iterator::FallibleIterator;
use gimli::{DebugAranges, EndianSlice, LittleEndian};

fn find_sum_of_address_range_lengths(aranges: DebugAranges<EndianSlice<LittleEndian>>)
    -> gimli::Result<u64>
{
    // `DebugAranges::headers` returns a `FallibleIterator`!
    aranges.headers()
        // `flat_map` is provided by `FallibleIterator`!
        .flat_map(|header| Ok(header.entries()))
        // `map` is provided by `FallibleIterator`!
        .map(|arange| Ok(arange.length()))
        // `fold` is provided by `FallibleIterator`!
        .fold(0, |sum, len| Ok(sum + len))
}

Structs§

  • A single parsed arange.
  • An iterator over the aranges from a .debug_aranges section.
  • A header for a set of entries in the .debug_arange section.
  • An iterator over the headers of a .debug_aranges section.
  • We support the z-style augmentation defined by .eh_frame.
  • Optional base addresses for the relative DW_EH_PE_* encoded pointers.
  • A lazy iterator parsing call frame instructions.
  • An iterator over CIE and FDE entries in a .debug_frame or .eh_frame section.
  • A Common Information Entry holds information that is shared among many Frame Description Entries. There is at least one CIE in every non-empty .debug_frame section.
  • The raw contents of the .debug_addr section.
  • The DebugAranges struct represents the DWARF address range information found in the .debug_aranges section.
  • The data in the .debug_cu_index section of a .dwp file.
  • DebugFrame contains the .debug_frame section’s frame unwinding information required to unwind to and recover registers from older frames on the stack. For example, this is useful for a debugger that wants to print locals in a backtrace.
  • The DebugLineStr struct represents the DWARF strings found in the .debug_line_str section.
  • The raw contents of the .debug_loc section.
  • The DebugLocLists struct represents the DWARF data found in the .debug_loclists section.
  • The raw contents of the .debug_ranges section.
  • The DebugRngLists struct represents the contents of the .debug_rnglists section.
  • The DebugStr struct represents the DWARF strings found in the .debug_str section.
  • The raw contents of the .debug_str_offsets section.
  • The data in the .debug_tu_index section of a .dwp file.
  • EhFrame contains the frame unwinding information needed during exception handling found in the .eh_frame section.
  • EhFrameHdr contains the information about the .eh_frame_hdr section.
  • The CFI binary search table that is an optional part of the .eh_frame_hdr section.
  • An iterator for .eh_frame_hdr section’s binary search table.
  • A &[u8] slice with endianity metadata.
  • A DWARF expression evaluator.
  • The bytecode for a DWARF expression or location description.
  • A FrameDescriptionEntry is a set of CFA instructions for an address range.
  • An iterator over a location list.
  • A location list entry from the .debug_loc or .debug_loclists sections.
  • The DWARF data found in .debug_loc and .debug_loclists sections.
  • An iterator for the operations in an expression.
  • ParsedEhFrameHdr contains the parsed information from the .eh_frame_hdr section.
  • A partially parsed FrameDescriptionEntry.
  • The description of a single piece of the result of a DWARF expression.
  • An address range from the .debug_ranges, .debug_rnglists, or .debug_aranges sections.
  • The DWARF data found in .debug_ranges and .debug_rnglists sections.
  • A raw iterator over a location list.
  • A raw iterator over an address range list.
  • An identifier for an offset within a section reader.
  • An unordered iterator for register rules.
  • A Reader which applies relocations to addresses and offsets.
  • An iterator over an address range list.
  • Optional base addresses for the relative DW_EH_PE_* encoded pointers in a particular section.
  • Indicates that storage should be allocated on heap.
  • The partially parsed index from a DebugCuIndex or DebugTuIndex.
  • Information about a unit’s contribution to a section in a .dwp file.
  • An iterator over the section offsets and sizes for a row in a UnitIndex.
  • An offset into the current compilation or type unit.
  • Common context needed when evaluating the call frame unwinding information.
  • The location of a DWARF expression within an unwind section.
  • The UnwindTable iteratively evaluates a FrameDescriptionEntry’s CallFrameInstruction program, yielding the each row one at a time.
  • A row in the virtual unwind table that describes how to find the values of the registers in the previous frame for a range of PC addresses.

Enums§

  • A parsed call frame instruction.
  • The canonical frame address (CFA) recovery rules.
  • Either a CommonInformationEntry (CIE) or a FrameDescriptionEntry (FDE).
  • A reference to a DIE, either relative to the current CU or relative to the section.
  • An error that occurred when parsing.
  • The state of an Evaluation after evaluating a DWARF expression. The evaluation is either Complete, or it requires more data to continue, as described by the variant.
  • Section kinds which are permitted in a .dwp index.
  • A single location of a piece of the result of a DWARF expression.
  • A single decoded DWARF expression operation.
  • A decoded pointer.
  • A raw entry in .debug_loclists.
  • A raw entry in .debug_rnglists
  • An entry in the abstract CFI table that describes how to find the value of a register.
  • The value of an entry on the DWARF stack.
  • The type of an entry on the DWARF stack.

Traits§

Type Aliases§

  • EndianBufDeprecated
    EndianBuf has been renamed to EndianSlice. For ease of upgrading across gimli versions, we export this type alias.
  • The result of a parse.