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>
impl<'a, R: Reader + 'a> ConvertLineProgram<'a, R>
Sourcepub fn read_row(&mut self) -> ConvertResult<Option<ConvertLineRow>>
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.
Sourcepub fn read_sequence(&mut self) -> ConvertResult<Option<ConvertLineSequence>>
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);
}
}Sourcepub fn begin_sequence(&mut self, address: Option<Address>)
pub fn begin_sequence(&mut self, address: Option<Address>)
Call LineProgram::begin_sequence for the converted program.
Sourcepub fn set_address(&mut self, address: Address)
pub fn set_address(&mut self, address: Address)
Call LineProgram::set_address for the converted program.
Sourcepub fn end_sequence(&mut self, address_offset: u64)
pub fn end_sequence(&mut self, address_offset: u64)
Call LineProgram::end_sequence for the converted program.
Sourcepub fn in_sequence(&self) -> bool
pub fn in_sequence(&self) -> bool
Return LineProgram::in_sequence for the converted program.
Sourcepub fn generate_row(&mut self, row: LineRow)
pub fn generate_row(&mut self, row: LineRow)
Set the next row and call LineProgram::generate_row for the converted program.
Sourcepub fn program(self) -> (LineProgram, Vec<FileId>)
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.
Sourcepub fn convert(
self,
convert_address: &dyn Fn(u64) -> Option<Address>,
) -> ConvertResult<(LineProgram, Vec<FileId>)>
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.