Skip to main content

ConvertLineProgram

Struct ConvertLineProgram 

Source
pub struct ConvertLineProgram<'a, R: Reader> { /* private fields */ }
Expand description

The state for the conversion of a line number program.

After calling Dwarf::read_line_program, or ConvertUnit::read_line_program, you may call either ConvertLineProgram::read_row to read the next row, or ConvertLineProgram::read_sequence to read a sequence of rows.

If desired, you may transform the rows that are read. For example, it may be useful to modify the addresses of the rows to match a corresponding transformation of the machine instructions.

Next, you may call ConvertLineProgram::set_address, ConvertLineProgram::generate_row, ConvertLineProgram::end_sequence to update the converted line number program.

Once all rows have been converted, you may call ConvertLineProgram::program to obtain the converted program and a mapping for file indices.

§Example Usage

Convert a line program using ConvertLineProgram::read_row.

use gimli::write::{Address, ConvertLineProgram, ConvertLineRow};
let mut dwarf = gimli::write::Dwarf::new();
// Start the conversion. This will convert the header, directories and files.
let mut convert = dwarf.read_line_program(
    &from_dwarf,
    from_program,
    // Use the original encodings.
    None,
    None,
)?;
// Read and convert each row in the program.
while let Some(row) = convert.read_row()? {
    match row {
        ConvertLineRow::SetAddress(address) => {
            convert.set_address(Address::Constant(address));
        }
        ConvertLineRow::Row(row) => {
            convert.generate_row(row);
        }
        ConvertLineRow::EndSequence(length) => {
            convert.end_sequence(length);
        }
    }
}
if convert.in_sequence() {
   // The sequence was never ended. This is invalid DWARF.
   return Err(gimli::write::ConvertError::MissingLineEndSequence);
}
let (program, files) = convert.program();

Implementations§

Source§

impl<'a, R: Reader + 'a> ConvertLineProgram<'a, R>

Source

pub fn read_row(&mut self) -> ConvertResult<Option<ConvertLineRow>>

Read the next row from the source program.

See ConvertLineProgram for an example of how to add the row to the converted program.

Source

pub fn read_sequence(&mut self) -> ConvertResult<Option<ConvertLineSequence>>

Read the next sequence from the source program.

This will read rows in the sequence up to either the end of the sequence, or the next DW_LNE_set_address instruction.

§Example Usage
// Read and convert each sequence in the program.
while let Some(sequence) = convert.read_sequence()? {
    if let Some(start) = sequence.start {
        convert.set_address(Address::Constant(start));
    }
    for row in sequence.rows {
        convert.generate_row(row);
    }
    if let ConvertLineSequenceEnd::Length(length) = sequence.end {
        convert.end_sequence(length);
    }
}
Source

pub fn begin_sequence(&mut self, address: Option<Address>)

Call LineProgram::begin_sequence for the converted program.

Source

pub fn set_address(&mut self, address: Address)

Call LineProgram::set_address for the converted program.

Source

pub fn end_sequence(&mut self, address_offset: u64)

Call LineProgram::end_sequence for the converted program.

Source

pub fn in_sequence(&self) -> bool

Return LineProgram::in_sequence for the converted program.

Source

pub fn generate_row(&mut self, row: LineRow)

Set the next row and call LineProgram::generate_row for the converted program.

Source

pub fn program(self) -> (LineProgram, Vec<FileId>)

Return the program and a mapping from source file index to FileId.

The file index mapping is 0 based, regardless of the DWARF version. For DWARF version <= 4, the entry at index 0 should not be used.

Source

pub fn convert( self, convert_address: &dyn Fn(u64) -> Option<Address>, ) -> ConvertResult<(LineProgram, Vec<FileId>)>

Convert the entire program.

Returns the program and a mapping from source file index to FileId, as for ConvertLineProgram::program.

See Dwarf::from for the meaning of convert_address.

Trait Implementations§

Source§

impl<'a, R: Debug + Reader> Debug for ConvertLineProgram<'a, R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, R> Freeze for ConvertLineProgram<'a, R>
where R: Freeze, <R as Reader>::Offset: Freeze,

§

impl<'a, R> RefUnwindSafe for ConvertLineProgram<'a, R>

§

impl<'a, R> Send for ConvertLineProgram<'a, R>
where R: Send + Sync, <R as Reader>::Offset: Send,

§

impl<'a, R> Sync for ConvertLineProgram<'a, R>
where R: Sync + Send, <R as Reader>::Offset: Sync,

§

impl<'a, R> Unpin for ConvertLineProgram<'a, R>
where R: Unpin, <R as Reader>::Offset: Unpin,

§

impl<'a, R> UnsafeUnpin for ConvertLineProgram<'a, R>
where R: UnsafeUnpin, <R as Reader>::Offset: UnsafeUnpin,

§

impl<'a, R> !UnwindSafe for ConvertLineProgram<'a, R>

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.