Skip to content

Commit

Permalink
Merge pull request gimli-rs#524 from khuey/addrx
Browse files Browse the repository at this point in the history
Add Dwarf::attr_address which will convert addr and addrx forms to their proper values.
  • Loading branch information
philipc authored Jul 6, 2020
2 parents cb795d6 + 011e5b9 commit 3408a50
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,23 @@ impl<R: Reader> Dwarf<R> {
.get_address(unit.encoding().address_size, unit.addr_base, index)
}

/// Try to return an attribute value as an address.
///
/// If the attribute value is one of:
///
/// - a `DW_FORM_addr`
/// - a `DW_FORM_addrx` index into the `.debug_addr` entries for the unit
///
/// then return the address.
/// Returns `None` for other forms.
pub fn attr_address(&self, unit: &Unit<R>, attr: AttributeValue<R>) -> Result<Option<u64>> {
match attr {
AttributeValue::Addr(addr) => Ok(Some(addr)),
AttributeValue::DebugAddrIndex(index) => self.address(unit, index).map(Some),
_ => Ok(None),
}
}

/// Return the range list offset at the given index.
pub fn ranges_offset(
&self,
Expand Down

0 comments on commit 3408a50

Please sign in to comment.