Skip to content

Commit

Permalink
Fix handling of DW_FORM_ref_addr in name_attr
Browse files Browse the repository at this point in the history
We were converting the reference to a unit offset, but incorrectly
continuing to use the old unit. This resulted in errors such
as `OffsetOutOfBounds` or `NoEntryAtGivenOffset`.
  • Loading branch information
philipc committed Sep 25, 2020
1 parent c83114d commit a8838d8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ where
let header = ilnp.header();
match header.file(0) {
Some(file) => files.push(self.render_file(file, header, sections)?),
None => files.push(String::from("")), // DWARF version <= 4 may not have 0th index
None => files.push(String::from("")), // DWARF version <= 4 may not have 0th index
}
let mut index = 1;
while let Some(file) = header.file(index) {
Expand Down Expand Up @@ -650,7 +650,7 @@ fn path_push(path: &mut String, p: &str) {
}
}

fn name_attr<'abbrev, 'unit, R>(
fn name_attr<R>(
attr: gimli::AttributeValue<R>,
unit: &gimli::Unit<R>,
sections: &gimli::Dwarf<R>,
Expand All @@ -664,20 +664,23 @@ where
return Ok(None);
}

let mut entries = match attr {
gimli::AttributeValue::UnitRef(offset) => unit.entries_raw(Some(offset))?,
let (unit, offset) = match attr {
gimli::AttributeValue::UnitRef(offset) => (unit, offset),
gimli::AttributeValue::DebugInfoRef(dr) => {
let unit = match units.binary_search_by_key(&dr.0, |unit| unit.offset.0) {
let res_unit = match units.binary_search_by_key(&dr.0, |unit| unit.offset.0) {
// There is never a DIE at the unit offset or before the first unit.
Ok(_) | Err(0) => return Err(gimli::Error::NoEntryAtGivenOffset),
Err(i) => &units[i - 1],
};
unit.dw_unit
.entries_raw(Some(gimli::UnitOffset(dr.0 - unit.offset.0)))?
(
&res_unit.dw_unit,
gimli::UnitOffset(dr.0 - res_unit.offset.0),
)
}
_ => return Ok(None),
};

let mut entries = unit.entries_raw(Some(offset))?;
let abbrev = if let Some(abbrev) = entries.read_abbreviation()? {
abbrev
} else {
Expand Down

0 comments on commit a8838d8

Please sign in to comment.