Expand description
Write DWARF debugging information.
API Structure
This module works by building up a representation of the debugging information in memory, and then writing it all at once. It supports two major use cases:
-
Use the
DwarfUnit
type when writing DWARF for a single compilation unit. -
Use the
Dwarf
type when writing DWARF for multiple compilation units.
The module also supports reading in DWARF debugging information and writing it out
again, possibly after modifying it. Create a read::Dwarf
instance, and then use Dwarf::from
to convert
it to a writable instance.
Example Usage
Write a compilation unit containing only the top level DIE.
use gimli::write::{
Address, AttributeValue, DwarfUnit, EndianVec, Error, Range, RangeList, Sections,
};
fn example() -> Result<(), Error> {
// Choose the encoding parameters.
let encoding = gimli::Encoding {
format: gimli::Format::Dwarf32,
version: 5,
address_size: 8,
};
// Create a container for a single compilation unit.
let mut dwarf = DwarfUnit::new(encoding);
// Set a range attribute on the root DIE.
let range_list = RangeList(vec![Range::StartLength {
begin: Address::Constant(0x100),
length: 42,
}]);
let range_list_id = dwarf.unit.ranges.add(range_list);
let root = dwarf.unit.root();
dwarf.unit.get_mut(root).set(
gimli::DW_AT_ranges,
AttributeValue::RangeListRef(range_list_id),
);
// Create a `Vec` for each DWARF section.
let mut sections = Sections::new(EndianVec::new(gimli::LittleEndian));
// Finally, write the DWARF data to the sections.
dwarf.write(&mut sections)?;
sections.for_each(|id, data| {
// Here you can add the data to the output object file.
Ok(())
})
}
Structs
An attribute in a DebuggingInformationEntry
, consisting of a name and
associated value.
An identifier for a CIE in a FrameTable
.
A common information entry. This contains information that is shared between FDEs.
A writable .debug_abbrev
section.
A writable .debug_frame
section.
A writable .debug_info
section.
The section offsets of all elements within a .debug_info
section.
A writable .debug_line
section.
A writable .debug_line_str
section.
The section offsets of all strings within a .debug_line_str
section.
A writable .debug_loc
section.
A writable .debug_loclists
section.
A writable .debug_ranges
section.
A writable .debug_rnglists
section.
A writable .debug_str
section.
The section offsets of all strings within a .debug_str
section.
A Debugging Information Entry (DIE).
An identifier for a directory in a LineProgram
.
Writable DWARF information for more than one unit.
Writable DWARF information for a single unit.
A writable .eh_frame
section.
A Vec<u8>
with endianity metadata.
The bytecode for a DWARF expression or location description.
An identifier for a file in a LineProgram
.
Extra information for file in a LineProgram
.
A frame description entry. There should be one FDE per function.
A table of frame description entries.
The offset at which an initial length should be written.
A line number program.
A row in the line number table that corresponds to a machine instruction.
An identifier for a string in a LineStringTable
.
A table of strings that will be stored in a .debug_line_str
section.
A locations list that will be stored in a .debug_loc
or .debug_loclists
section.
An identifier for a location list in a LocationListTable
.
The section offsets of a series of location lists within the .debug_loc
or .debug_loclists
sections.
A table of location lists that will be stored in a .debug_loc
or .debug_loclists
section.
A range list that will be stored in a .debug_ranges
or .debug_rnglists
section.
An identifier for a range list in a RangeListTable
.
The section offsets of a series of range lists within the .debug_ranges
or .debug_rnglists
sections.
A table of range lists that will be stored in a .debug_ranges
or .debug_rnglists
section.
All of the writable DWARF sections.
An identifier for a string in a StringTable
.
A table of strings that will be stored in a .debug_str
section.
A unit’s debugging information.
An identifier for an entry in a Unit
.
An identifier for a unit in a UnitTable
.
A table of units that will be stored in the .debug_info
section.
Enums
An address.
The value of an attribute in a DebuggingInformationEntry
.
An instruction in a frame description entry.
An error that occurred when converting a read value into a write value.
An error that occurred when writing.
A string value for use in defining paths in line number programs.
A single location.
A single range.
A reference to a .debug_info
entry.
Traits
Functionality common to all writable DWARF sections.
A trait for writing the data to a DWARF section.
Type Definitions
The result of a conversion.
The result of a write.