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: UnitTableA 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: LineStringTableA table of strings that will be stored in the .debug_line_str section.
strings: StringTableA table of strings that will be stored in the .debug_str section.
Implementations§
Source§impl Dwarf
impl Dwarf
Sourcepub fn from<R: Reader<Offset = usize>>(
from_dwarf: &Dwarf<R>,
convert_address: &dyn Fn(u64) -> Option<Address>,
) -> ConvertResult<Dwarf>
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)),
)?;Sourcepub fn convert<'a, R: Reader<Offset = usize>>(
&'a mut self,
dwarf: &'a Dwarf<R>,
) -> ConvertResult<ConvertUnitSection<'a, R>>
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.
}Sourcepub fn convert_with_filter<'a, R: Reader<Offset = usize>>(
&'a mut self,
filter: FilterUnitSection<'a, R>,
) -> ConvertResult<ConvertUnitSection<'a, R>>
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.
}Sourcepub 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>>
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.