Skip to content

Commit

Permalink
dwarfdump: improve handling of FDE parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Nov 20, 2023
1 parent 531636d commit 1d57668
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
21 changes: 13 additions & 8 deletions crates/examples/src/bin/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,18 +829,23 @@ fn dump_eh_frame<R: Reader, W: Write>(
writeln!(w)?;
}
Some(gimli::CieOrFde::Fde(partial)) => {
let mut offset = None;
let fde = partial.parse(|_, bases, o| {
offset = Some(o);
writeln!(w)?;
writeln!(w, "{:#010x}: FDE", partial.offset())?;
writeln!(w, " length: {:#010x}", partial.entry_len())?;
writeln!(w, " CIE_pointer: {:#010x}", partial.cie_offset().0)?;

let fde = match partial.parse(|_, bases, o| {
cies.entry(o)
.or_insert_with(|| eh_frame.cie_from_offset(bases, o))
.clone()
})?;
}) {
Ok(fde) => fde,
Err(e) => {
writeln!(w, "Failed to parse FDE: {}", e)?;
continue;
}
};

writeln!(w)?;
writeln!(w, "{:#010x}: FDE", fde.offset())?;
writeln!(w, " length: {:#010x}", fde.entry_len())?;
writeln!(w, " CIE_pointer: {:#010x}", offset.unwrap().0)?;
// TODO: symbolicate the start address like the canonical dwarfdump does.
writeln!(w, " start_addr: {:#018x}", fde.initial_address())?;
writeln!(
Expand Down
18 changes: 18 additions & 0 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,24 @@ where
get_cie,
)
}

/// Get the offset of this entry from the start of its containing section.
pub fn offset(&self) -> R::Offset {
self.offset
}

/// Get the offset of this FDE's CIE.
pub fn cie_offset(&self) -> Section::Offset {
self.cie_offset
}

/// > A constant that gives the number of bytes of the header and
/// > instruction stream for this function, not including the length field
/// > itself (see Section 7.2.2). The size of the length field plus the value
/// > of length must be an integral multiple of the address size.
pub fn entry_len(&self) -> R::Offset {
self.length
}
}

/// A `FrameDescriptionEntry` is a set of CFA instructions for an address range.
Expand Down

0 comments on commit 1d57668

Please sign in to comment.