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

Add Dwarf::attr_address which will convert addr and addrx forms to their proper values #518

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 24 additions & 0 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,30 @@ 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<Header>(
&self,
unit: &Unit<Header, R>,
attr: AttributeValue<R>,
) -> Result<Option<u64>>
where
Header: UnitHeader<R, R::Offset>,
{
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