diff --git a/src/read/dwarf.rs b/src/read/dwarf.rs index eeb1a747c..b361bc1bc 100644 --- a/src/read/dwarf.rs +++ b/src/read/dwarf.rs @@ -241,6 +241,30 @@ impl Dwarf { .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, + attr: AttributeValue, + ) -> Result> + where + Header: UnitHeader, + { + 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,