Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write/cfi: implement .eh_frame #419

Merged
merged 5 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,17 @@ fn dump_eh_frame<R: Reader, W: Write>(
writeln!(w, " code_align: {}", cie.code_alignment_factor())?;
writeln!(w, " data_align: {}", cie.data_alignment_factor())?;
writeln!(w, " ra_register: {:#x}", cie.return_address_register().0)?;
// TODO: aug_arg
if let Some(encoding) = cie.lsda_encoding() {
writeln!(w, " lsda_encoding: {:#02x}", encoding.0)?;
}
if let Some((encoding, personality)) = cie.personality_with_encoding() {
write!(w, " personality: {:#02x} ", encoding.0)?;
dump_pointer(w, personality)?;
writeln!(w)?;
}
if let Some(encoding) = cie.fde_address_encoding() {
writeln!(w, " fde_encoding: {:#02x}", encoding.0)?;
}
dump_cfi_instructions(w, cie.instructions(eh_frame, bases), true, register_name)?;
writeln!(w)?;
}
Expand All @@ -629,8 +639,10 @@ fn dump_eh_frame<R: Reader, W: Write>(
fde.len(),
fde.initial_address() + fde.len()
)?;
if let Some(gimli::Pointer::Direct(lsda)) = fde.lsda() {
writeln!(w, " lsda: {:#018x}", lsda)?;
if let Some(lsda) = fde.lsda() {
write!(w, " lsda: ")?;
dump_pointer(w, lsda)?;
writeln!(w)?;
}
dump_cfi_instructions(w, fde.instructions(eh_frame, bases), false, register_name)?;
writeln!(w)?;
Expand All @@ -639,6 +651,18 @@ fn dump_eh_frame<R: Reader, W: Write>(
}
}

fn dump_pointer<W: Write>(w: &mut W, p: gimli::Pointer) -> Result<()> {
match p {
gimli::Pointer::Direct(p) => {
write!(w, "{:#018x}", p)?;
}
gimli::Pointer::Indirect(p) => {
write!(w, "({:#018x})", p)?;
}
}
Ok(())
}

#[allow(clippy::unneeded_field_pattern)]
fn dump_cfi_instructions<R: Reader, W: Write>(
w: &mut W,
Expand Down
29 changes: 24 additions & 5 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ pub struct Augmentation {
/// > represents the pointer encoding used for the second argument, which is
/// > the address of a personality routine handler. The size of the
/// > personality routine pointer is specified by the pointer encoding used.
personality: Option<Pointer>,
personality: Option<(constants::DwEhPe, Pointer)>,

/// > A 'R' may be present at any position after the first character of the
/// > string. This character may only be present if 'z' is the first character
Expand Down Expand Up @@ -1134,7 +1134,7 @@ impl Augmentation {
};

let personality = parse_encoded_pointer(encoding, &parameters, rest)?;
augmentation.personality = Some(personality);
augmentation.personality = Some((encoding, personality));
}
b'R' => {
let encoding = parse_pointer_encoding(rest)?;
Expand Down Expand Up @@ -1391,10 +1391,29 @@ impl<R: Reader> CommonInformationEntry<R> {
self.augmentation.map_or(false, |a| a.lsda.is_some())
}

/// Return the encoding of the LSDA address for this CIE's FDEs.
pub fn lsda_encoding(&self) -> Option<constants::DwEhPe> {
self.augmentation.and_then(|a| a.lsda)
}

/// Return the encoding and address of the personality routine handler
/// for this CIE's FDEs.
pub fn personality_with_encoding(&self) -> Option<(constants::DwEhPe, Pointer)> {
self.augmentation.as_ref().and_then(|a| a.personality)
}

/// Return the address of the personality routine handler
/// for this CIE's FDEs.
pub fn personality(&self) -> Option<Pointer> {
self.augmentation.as_ref().and_then(|a| a.personality)
self.augmentation
.as_ref()
.and_then(|a| a.personality)
.map(|(_, p)| p)
}

/// Return the encoding of the addresses for this CIE's FDEs.
pub fn fde_address_encoding(&self) -> Option<constants::DwEhPe> {
self.augmentation.and_then(|a| a.fde_address_encoding)
}

/// True if this CIE's FDEs are trampolines for signal handlers.
Expand Down Expand Up @@ -6204,7 +6223,7 @@ mod tests {
let aug_str = &mut EndianSlice::new(b"zP", LittleEndian);

let mut augmentation = Augmentation::default();
augmentation.personality = Some(Pointer::Direct(0xf00d_f00d));
augmentation.personality = Some((constants::DW_EH_PE_udata8, Pointer::Direct(0xf00d_f00d)));

assert_eq!(
Augmentation::parse(aug_str, &bases, address_size, &section, input),
Expand Down Expand Up @@ -6290,7 +6309,7 @@ mod tests {

let augmentation = Augmentation {
lsda: Some(constants::DW_EH_PE_uleb128),
personality: Some(Pointer::Direct(0x1bad_f00d)),
personality: Some((constants::DW_EH_PE_udata8, Pointer::Direct(0x1bad_f00d))),
fde_address_encoding: Some(constants::DW_EH_PE_uleb128),
is_signal_trampoline: true,
};
Expand Down
Loading