Skip to main content

Dwarf

Struct Dwarf 

Source
pub struct Dwarf {
    pub units: UnitTable,
    pub line_programs: Vec<LineProgram>,
    pub line_strings: LineStringTable,
    pub strings: StringTable,
}
Expand description

Writable DWARF information for more than one unit.

Fields§

§units: UnitTable

A table of units. These are primarily stored in the .debug_info section, but they also contain information that is stored in other sections.

§line_programs: Vec<LineProgram>

Extra line number programs that are not associated with a unit.

These should only be used when generating DWARF5 line-only debug information.

§line_strings: LineStringTable

A table of strings that will be stored in the .debug_line_str section.

§strings: StringTable

A table of strings that will be stored in the .debug_str section.

Implementations§

Source§

impl Dwarf

Source

pub fn from<R: Reader<Offset = usize>>( from_dwarf: &Dwarf<R>, convert_address: &dyn Fn(u64) -> Option<Address>, ) -> ConvertResult<Dwarf>

Create a write::Dwarf by converting a read::Dwarf.

convert_address is a function to convert addresses read by Reader::read_address into the Address type. For executable files, it is sufficient to simply map the address to Address::Constant.

Relocatable object files are more complicated because there are relocations associated with the address. To handle this, you can use a Reader implementation for which Reader::read_address stores the relocation information in a map and returns the map key instead of an address. Then convert_address can look up the mapping to produce an Address.

Note that convert_address is also used for address and offset pairs in DWARF v2-v4 range lists and location lists. In order for the parser to correctly handle these, Reader::read_address must return the values 0 and -1 unchanged.

convert_address should not be used for complex address transformations, as it will not be called for address offsets (such as in DW_AT_high_pc, line programs, location lists, or range lists). If you need complex transformations, then you need to use Dwarf::convert to enable you to transform the address offsets too.

§Example

Convert DWARF sections using Dwarf::from.

let read_dwarf = gimli::read::Dwarf::load(loader)?;
let write_dwarf = gimli::write::Dwarf::from(
    &read_dwarf,
    &|address| Some(gimli::write::Address::Constant(address)),
)?;
Source

pub fn convert<'a, R: Reader<Offset = usize>>( &'a mut self, dwarf: &'a Dwarf<R>, ) -> ConvertResult<ConvertUnitSection<'a, R>>

Create a converter for all units in the .debug_info section of the given DWARF object.

§Example

Convert DWARF sections using convert. See ConvertUnit for an example of the unit conversion.

let read_dwarf = gimli::read::Dwarf::load(loader)?;
let mut write_dwarf = gimli::write::Dwarf::new();
let mut convert = write_dwarf.convert(&read_dwarf)?;
while let Some((mut unit, root_entry)) = convert.read_unit()? {
    // Now you can convert the root DIE attributes, and other DIEs.
}
Source

pub fn convert_with_filter<'a, R: Reader<Offset = usize>>( &'a mut self, filter: FilterUnitSection<'a, R>, ) -> ConvertResult<ConvertUnitSection<'a, R>>

Create a converter for some of the DIEs in the .debug_info section of the given DWARF object.

filter determines which DIEs are converted. This can be created using FilterUnitSection::new.

§Example

Convert a DWARF section using convert_with_filter. See ConvertUnit for an example of the unit conversion.

let read_dwarf = gimli::read::Dwarf::load(loader)?;
let mut filter = gimli::write::FilterUnitSection::new(&read_dwarf)?;
while let Some(mut unit) = filter.read_unit()? {
    let mut entry = unit.null_entry();
    while unit.read_entry(&mut entry)? {
        if need_entry(&entry)? {
            unit.require_entry(entry.offset);
        }
    }
}
let mut write_dwarf = gimli::write::Dwarf::new();
let mut convert = write_dwarf.convert_with_filter(filter)?;
while let Some((mut unit, root_entry)) = convert.read_unit()? {
    // Now you can convert the root DIE attributes, and other DIEs.
}
Source

pub fn read_line_program<'a, R: Reader<Offset = usize>>( &'a mut self, dwarf: &'a Dwarf<R>, program: IncompleteLineProgram<R>, encoding: Option<Encoding>, line_encoding: Option<LineEncoding>, ) -> ConvertResult<ConvertLineProgram<'a, R>>

Start a new conversion of a line number program.

This is intended for line number programs that do not have an associated read::Unit. If the line number program has an associated read::Unit that you are converting, then you should use ConvertUnit::read_line_program instead.

encoding and line_encoding apply to the converted program, and may be different from the source program. If None, the encoding from the source program is used.

See ConvertLineProgram for an example.

Source§

impl Dwarf

Source

pub fn new() -> Self

Create a new Dwarf instance.

Source

pub fn write<W: Writer>(&mut self, sections: &mut Sections<W>) -> Result<()>

Write the DWARF information to the given sections.

Source

pub fn get_line_string<'a>(&'a self, string: &'a LineString) -> &'a [u8]

Get a reference to the data for a line string.

Trait Implementations§

Source§

impl Debug for Dwarf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Dwarf

Source§

fn default() -> Dwarf

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Dwarf

§

impl RefUnwindSafe for Dwarf

§

impl Send for Dwarf

§

impl Sync for Dwarf

§

impl Unpin for Dwarf

§

impl UnsafeUnpin for Dwarf

§

impl UnwindSafe for Dwarf

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.