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:
- 
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 (viaDW_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 Dwarftype 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 DwarfPackagetype 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: - 
DebugAbbrev: The.debug_abbrevsection.
- 
DebugAddr: The.debug_addrsection.
- 
DebugAranges: The.debug_arangessection.
- 
DebugFrame: The.debug_framesection.
- 
DebugInfo: The.debug_infosection.
- 
DebugLine: The.debug_linesection.
- 
DebugLineStr: The.debug_line_strsection.
- 
DebugLoc: The.debug_locsection.
- 
DebugLocLists: The.debug_loclistssection.
- 
DebugPubNames: The.debug_pubnamessection.
- 
DebugPubTypes: The.debug_pubtypessection.
- 
DebugRanges: The.debug_rangessection.
- 
DebugRngLists: The.debug_rnglistssection.
- 
DebugStr: The.debug_strsection.
- 
DebugStrOffsets: The.debug_str_offsetssection.
- 
DebugTypes: The.debug_typessection.
- 
DebugCuIndex: The.debug_cu_indexsection.
- 
DebugTuIndex: The.debug_tu_indexsection.
- 
EhFrame: The.eh_framesection.
- 
EhFrameHdr: The.eh_frame_hdrsection.
 
- 
- 
Each section type exposes methods for accessing the debugging data encoded in that section. For example, the DebugInfostruct has theunitsmethod for iterating over the compilation units defined within it.
- 
Offsets into a section are strongly typed: an offset into .debug_infois theDebugInfoOffsettype. It cannot be used to index into theDebugLinetype becauseDebugLinerepresents the.debug_linesection. 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§
- Abbreviation
- An abbreviation describes the shape of a DebuggingInformationEntry’s type: its code, tag type, whether it has children, and its set of attributes.
- Abbreviations
- A set of type abbreviations.
- AbbreviationsCache 
- A cache of previously parsed Abbreviations.
- ArangeEntry 
- A single parsed arange.
- ArangeEntry Iter 
- An iterator over the aranges from a .debug_arangessection.
- ArangeHeader 
- A header for a set of entries in the .debug_arangesection.
- ArangeHeader Iter 
- An iterator over the headers of a .debug_arangessection.
- Attribute
- An attribute in a DebuggingInformationEntry, consisting of a name and associated value.
- AttributeSpecification 
- The description of an attribute in an abbreviated type. It is a pair of name and form.
- AttrsIter 
- An iterator over a particular entry’s attributes.
- Augmentation
- We support the z-style augmentation defined by .eh_frame.
- BaseAddresses 
- Optional base addresses for the relative DW_EH_PE_*encoded pointers.
- CallFrame Instruction Iter 
- A lazy iterator parsing call frame instructions.
- CfiEntriesIter 
- An iterator over CIE and FDE entries in a .debug_frameor.eh_framesection.
- CommonInformation Entry 
- 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_framesection.
- CompleteLine Program 
- A line number program that has previously been run to completion.
- DebugAbbrev 
- The DebugAbbrevstruct represents the abbreviations describingDebuggingInformationEntrys’ attribute names and forms found in the.debug_abbrevsection.
- DebugAddr 
- The raw contents of the .debug_addrsection.
- DebugAranges 
- The DebugArangesstruct represents the DWARF address range information found in the.debug_arangessection.
- DebugCuIndex 
- The data in the .debug_cu_indexsection of a.dwpfile.
- DebugFrame 
- DebugFramecontains the- .debug_framesection’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.
- DebugInfo 
- The DebugInfostruct represents the DWARF debugging information found in the.debug_infosection.
- DebugInfo Unit Headers Iter 
- An iterator over the units of a .debug_info section.
- DebugLine 
- The DebugLinestruct contains the source location to instruction mapping found in the.debug_linesection.
- DebugLine Str 
- The DebugLineStrstruct represents the DWARF strings found in the.debug_line_strsection.
- DebugLoc 
- The raw contents of the .debug_locsection.
- DebugLocLists 
- The DebugLocListsstruct represents the DWARF data found in the.debug_loclistssection.
- DebugPubNames 
- The DebugPubNamesstruct represents the DWARF public names information found in the.debug_pubnamessection.
- DebugPubTypes 
- The DebugPubTypesstruct represents the DWARF public types information found in the.debug_infosection.
- DebugRanges 
- The raw contents of the .debug_rangessection.
- DebugRngLists 
- The DebugRngListsstruct represents the contents of the.debug_rnglistssection.
- DebugStr 
- The DebugStrstruct represents the DWARF strings found in the.debug_strsection.
- DebugStrOffsets 
- The raw contents of the .debug_str_offsetssection.
- DebugTuIndex 
- The data in the .debug_tu_indexsection of a.dwpfile.
- DebugTypes 
- The DebugTypesstruct represents the DWARF type information found in the.debug_typessection.
- DebugTypes Unit Headers Iter 
- An iterator over the type-units of this .debug_typessection.
- DebuggingInformation Entry 
- A Debugging Information Entry (DIE).
- Dwarf
- All of the commonly used DWARF sections, and other common information.
- DwarfPackage 
- The sections from a .dwpfile, with parsed indices.
- DwarfPackage Sections 
- The sections from a .dwpfile.
- DwarfSections 
- All of the commonly used DWARF sections.
- EhFrame
- EhFramecontains the frame unwinding information needed during exception handling found in the- .eh_framesection.
- EhFrameHdr 
- EhFrameHdrcontains the information about the- .eh_frame_hdrsection.
- EhHdrTable 
- The CFI binary search table that is an optional part of the .eh_frame_hdrsection.
- EhHdrTable Iter 
- An iterator for .eh_frame_hdrsection’s binary search table.
- EndianSlice 
- A &[u8]slice with endianity metadata.
- EntriesCursor 
- A cursor into the Debugging Information Entries tree for a compilation unit.
- EntriesRaw 
- A raw reader of the data that defines the Debugging Information Entries.
- EntriesTree 
- The state information for a tree view of the Debugging Information Entries.
- EntriesTree Iter 
- An iterator that allows traversal of the children of an
EntriesTreeNode.
- EntriesTree Node 
- A node in the Debugging Information Entry tree.
- Evaluation
- A DWARF expression evaluator.
- Expression
- The bytecode for a DWARF expression or location description.
- FileEntry 
- An entry in the LineProgramHeader’sfile_namesset.
- FileEntry Format 
- The format of a component of an include directory or file name entry.
- FrameDescription Entry 
- A FrameDescriptionEntryis a set of CFA instructions for an address range.
- IncompleteLine Program 
- A line number program that has not been run to completion.
- LineInstructions 
- An iterator yielding parsed instructions.
- LineProgram Header 
- A header for a line number program in the .debug_linesection, as defined in section 6.2.4 of the standard.
- LineRow
- A row in the line number program’s resulting matrix.
- LineRows 
- Executes a LineProgramto iterate over the rows in the matrix of line number information.
- LineSequence 
- A sequence within a line number program. A sequence, as defined in section 6.2.5 of the standard, is a linear subset of a line number program within which addresses are monotonically increasing.
- LocListIter 
- An iterator over a location list.
- LocationList Entry 
- A location list entry from the .debug_locor.debug_loclistssections.
- LocationLists 
- The DWARF data found in .debug_locand.debug_loclistssections.
- OperationIter 
- An iterator for the operations in an expression.
- ParsedEhFrame Hdr 
- ParsedEhFrameHdrcontains the parsed information from the- .eh_frame_hdrsection.
- PartialFrame Description Entry 
- A partially parsed FrameDescriptionEntry.
- Piece
- The description of a single piece of the result of a DWARF expression.
- PubNamesEntry 
- A single parsed pubname.
- PubNamesEntry Iter 
- An iterator over the pubnames from a .debug_pubnamessection.
- PubTypesEntry 
- A single parsed pubtype.
- PubTypesEntry Iter 
- An iterator over the pubtypes from a .debug_pubtypessection.
- Range
- An address range from the .debug_ranges,.debug_rnglists, or.debug_arangessections.
- RangeIter 
- An iterator for the address ranges of a DebuggingInformationEntry.
- RangeLists 
- The DWARF data found in .debug_rangesand.debug_rnglistssections.
- RawLocList Iter 
- A raw iterator over a location list.
- RawRngList Iter 
- A raw iterator over an address range list.
- ReaderOffset Id 
- An identifier for an offset within a section reader.
- RegisterRule Iter 
- An unordered iterator for register rules.
- RelocateReader 
- A Readerwhich applies relocations to addresses and offsets.
- RngListIter 
- An iterator over an address range list.
- SectionBase Addresses 
- Optional base addresses for the relative DW_EH_PE_*encoded pointers in a particular section.
- StoreOnHeap 
- Indicates that storage should be allocated on heap.
- Unit
- All of the commonly used information for a unit in the .debug_infoor.debug_typessections.
- UnitHeader 
- The common fields for the headers of compilation units and type units.
- UnitIndex 
- The partially parsed index from a DebugCuIndexorDebugTuIndex.
- UnitIndex Section 
- Information about a unit’s contribution to a section in a .dwpfile.
- UnitIndex Section Iterator 
- An iterator over the section offsets and sizes for a row in a UnitIndex.
- UnitOffset 
- An offset into the current compilation or type unit.
- UnitRef
- A reference to a Unitand its associatedDwarf.
- UnwindContext 
- Common context needed when evaluating the call frame unwinding information.
- UnwindExpression 
- The location of a DWARF expression within an unwind section.
- UnwindTable 
- The UnwindTableiteratively evaluates aFrameDescriptionEntry’sCallFrameInstructionprogram, yielding the each row one at a time.
- UnwindTable Row 
- 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§
- AbbreviationsCache Strategy 
- The strategy to use for caching abbreviations.
- AttributeValue 
- The value of an attribute in a DebuggingInformationEntry.
- CallFrame Instruction 
- A parsed call frame instruction.
- CfaRule
- The canonical frame address (CFA) recovery rules.
- CieOrFde 
- Either a CommonInformationEntry(CIE) or aFrameDescriptionEntry(FDE).
- ColumnType 
- The type of column that a row is referring to.
- DieReference
- A reference to a DIE, either relative to the current CU or relative to the section.
- Error
- An error that occurred when parsing.
- EvaluationResult 
- The state of an Evaluationafter evaluating a DWARF expression. The evaluation is eitherComplete, or it requires more data to continue, as described by the variant.
- IndexSection Id 
- Section kinds which are permitted in a .dwpindex.
- LineInstruction 
- A parsed line number program instruction.
- Location
- A single location of a piece of the result of a DWARF expression.
- Operation
- A single decoded DWARF expression operation.
- Pointer
- A decoded pointer.
- RawLocList Entry 
- A raw entry in .debug_loclists.
- RawRngList Entry 
- A raw entry in .debug_rnglists
- RegisterRule 
- An entry in the abstract CFI table that describes how to find the value of a register.
- UnitType 
- This enum specifies the type of the unit and any type specific data carried in the header (e.g. the type signature/type offset of a type unit).
- Value
- The value of an entry on the DWARF stack.
- ValueType 
- The type of an entry on the DWARF stack.
Traits§
- ArrayLike 
- Marker trait for types that can be used as backing storage when a growable array type is needed.
- EvaluationStorage 
- Specification of what storage should be used for Evaluation.
- LineProgram 
- A LineProgramprovides access to aLineProgramHeaderand a way to add files to the files table if necessary. Gimli consumers should never need to use or see this trait.
- Reader
- A trait for reading the data from a DWARF section.
- ReaderOffset 
- A trait for offsets with a DWARF section.
- Relocate
- Trait for relocating addresses and offsets while reading a section.
- Section
- A convenience trait for loading DWARF sections from object files. To be used like:
- UnwindContext Storage 
- Specification of what storage should be used for UnwindContext.
- UnwindOffset 
- An offset into an UnwindSection.
- UnwindSection 
- A section holding unwind information: either .debug_frameor.eh_frame. SeeDebugFrameandEhFramerespectively.
Type Aliases§
- CompleteLine Number Program Deprecated 
- Deprecated. CompleteLineNumberProgramhas been renamed toCompleteLineProgram.
- EndianBuf Deprecated 
- EndianBufhas been renamed to- EndianSlice. For ease of upgrading across- gimliversions, we export this type alias.
- IncompleteLine Number Program Deprecated 
- Deprecated. IncompleteLineNumberProgramhas been renamed toIncompleteLineProgram.
- LineNumber Program Deprecated 
- Deprecated. LineNumberProgramhas been renamed toLineProgram.
- LineNumber Program Header Deprecated 
- Deprecated. LineNumberProgramHeaderhas been renamed toLineProgramHeader.
- LineNumber Row Deprecated 
- Deprecated. LineNumberRowhas been renamed toLineRow.
- LineNumber Sequence Deprecated 
- Deprecated. LineNumberSequencehas been renamed toLineSequence.
- OpcodeDeprecated 
- Deprecated. Opcodehas been renamed toLineInstruction.
- OpcodesIter Deprecated 
- Deprecated. OpcodesIterhas been renamed toLineInstructions.
- Result
- The result of a parse.
- StateMachine Deprecated 
- Deprecated. StateMachinehas been renamed toLineRows.