Skip to content

Commit

Permalink
Delete sup_dwarf parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed May 2, 2021
1 parent 327b9eb commit 512a1a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
1 change: 0 additions & 1 deletion examples/addr2line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ fn main() {
load_file_section(id, sup_object, endian, &arena_data)
};
dwarf.load_sup(&mut load_sup_section).unwrap();

}

let ctx = Context::from_dwarf(dwarf).unwrap();
Expand Down
53 changes: 18 additions & 35 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ type Error = gimli::Error;
/// when performing lookups for many addresses in the same executable.
pub struct Context<R: gimli::Reader> {
dwarf: ResDwarf<R>,
sup_dwarf: Option<ResDwarf<R>>,
}

/// The type of `Context` that supports the `new` method.
Expand Down Expand Up @@ -185,12 +184,12 @@ impl<R: gimli::Reader> Context<R> {
/// Construct a new `Context` from an existing [`gimli::Dwarf`] object.
#[inline]
pub fn from_dwarf(sections: gimli::Dwarf<R>) -> Result<Self, Error> {
let dwarf = ResDwarf::parse(Arc::new(sections))?;
let sup_dwarf = match dwarf.sections.sup.clone() {
Some(sup_sections) => Some(ResDwarf::parse(sup_sections)?),
let mut dwarf = ResDwarf::parse(Arc::new(sections))?;
dwarf.sup = match dwarf.sections.sup.clone() {
Some(sup_sections) => Some(Arc::new(ResDwarf::parse(sup_sections)?)),
None => None,
};
Ok(Context { dwarf, sup_dwarf })
Ok(Context { dwarf })
}

/// The dwarf sections associated with this `Context`.
Expand Down Expand Up @@ -269,7 +268,7 @@ impl<R: gimli::Reader> Context<R> {
/// Find the DWARF unit corresponding to the given virtual memory address.
pub fn find_dwarf_unit(&self, probe: u64) -> Option<&gimli::Unit<R>> {
for unit in self.find_units(probe) {
match unit.find_function_or_location(probe, &self.dwarf, self.sup_dwarf.as_ref()) {
match unit.find_function_or_location(probe, &self.dwarf) {
Ok((Some(_), _)) | Ok((_, Some(_))) => return Some(&unit.dw_unit),
_ => {}
}
Expand Down Expand Up @@ -308,7 +307,7 @@ impl<R: gimli::Reader> Context<R> {
/// location, until an non-inline caller is reached.
pub fn find_frames(&self, probe: u64) -> Result<FrameIter<R>, Error> {
for unit in self.find_units(probe) {
match unit.find_function_or_location(probe, &self.dwarf, self.sup_dwarf.as_ref())? {
match unit.find_function_or_location(probe, &self.dwarf)? {
(Some(function), location) => {
let inlined_functions = function.find_inlined_functions(probe);
return Ok(FrameIter(FrameIterState::Frames(FrameIterFrames {
Expand Down Expand Up @@ -350,7 +349,7 @@ impl<R: gimli::Reader> Context<R> {
#[doc(hidden)]
pub fn parse_inlined_functions(&self) -> Result<(), Error> {
for unit in &self.dwarf.units {
unit.parse_inlined_functions(&self.dwarf, self.sup_dwarf.as_ref())?;
unit.parse_inlined_functions(&self.dwarf)?;
}
Ok(())
}
Expand All @@ -366,6 +365,7 @@ struct ResDwarf<R: gimli::Reader> {
unit_ranges: Vec<UnitRange>,
units: Vec<ResUnit<R>>,
sections: Arc<gimli::Dwarf<R>>,
sup: Option<Arc<ResDwarf<R>>>,
}

impl<R: gimli::Reader> ResDwarf<R> {
Expand Down Expand Up @@ -459,6 +459,7 @@ impl<R: gimli::Reader> ResDwarf<R> {
units: res_units,
unit_ranges,
sections,
sup: None,
})
}

Expand Down Expand Up @@ -581,16 +582,12 @@ impl<R: gimli::Reader> ResUnit<R> {
.map_err(Error::clone)
}

fn parse_inlined_functions(
&self,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
) -> Result<(), Error> {
fn parse_inlined_functions(&self, dwarf: &ResDwarf<R>) -> Result<(), Error> {
self.funcs
.borrow_with(|| Functions::parse(&self.dw_unit, dwarf))
.as_ref()
.map_err(Error::clone)?
.parse_inlined_functions(&self.dw_unit, dwarf, sup_dwarf)
.parse_inlined_functions(&self.dw_unit, dwarf)
}

fn find_location(
Expand Down Expand Up @@ -622,7 +619,6 @@ impl<R: gimli::Reader> ResUnit<R> {
&self,
probe: u64,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
) -> Result<(Option<&Function<R>>, Option<Location<'_>>), Error> {
let functions = self.parse_functions(dwarf)?;
let function = match functions.find_address(probe) {
Expand All @@ -631,7 +627,7 @@ impl<R: gimli::Reader> ResUnit<R> {
let (offset, ref function) = functions.functions[function_index];
Some(
function
.borrow_with(|| Function::parse(offset, &self.dw_unit, dwarf, sup_dwarf))
.borrow_with(|| Function::parse(offset, &self.dw_unit, dwarf))
.as_ref()
.map_err(Error::clone)?,
)
Expand Down Expand Up @@ -902,7 +898,6 @@ fn name_attr<R>(
attr: gimli::AttributeValue<R>,
unit: &gimli::Unit<R>,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
recursion_limit: usize,
) -> Result<Option<R>, Error>
where
Expand All @@ -913,27 +908,23 @@ where
}

match attr {
gimli::AttributeValue::UnitRef(offset) => {
name_entry(unit, offset, dwarf, sup_dwarf, recursion_limit)
}
gimli::AttributeValue::UnitRef(offset) => name_entry(unit, offset, dwarf, recursion_limit),
gimli::AttributeValue::DebugInfoRef(dr) => {
let res_unit = dwarf.find_unit(dr)?;
name_entry(
&res_unit.dw_unit,
gimli::UnitOffset(dr.0 - res_unit.offset.0),
dwarf,
sup_dwarf,
recursion_limit,
)
}
gimli::AttributeValue::DebugInfoRefSup(dr) => {
if let Some(sup_dwarf) = sup_dwarf {
if let Some(sup_dwarf) = dwarf.sup.as_ref() {
let res_unit = sup_dwarf.find_unit(dr)?;
name_entry(
&res_unit.dw_unit,
gimli::UnitOffset(dr.0 - res_unit.offset.0),
sup_dwarf,
None,
recursion_limit,
)
} else {
Expand All @@ -948,7 +939,6 @@ fn name_entry<R>(
unit: &gimli::Unit<R>,
offset: gimli::UnitOffset<R::Offset>,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
recursion_limit: usize,
) -> Result<Option<R>, Error>
where
Expand Down Expand Up @@ -990,7 +980,7 @@ where
}

if let Some(next) = next {
return name_attr(next, unit, dwarf, sup_dwarf, recursion_limit - 1);
return name_attr(next, unit, dwarf, recursion_limit - 1);
}

Ok(None)
Expand Down Expand Up @@ -1137,12 +1127,11 @@ impl<R: gimli::Reader> Functions<R> {
&self,
unit: &gimli::Unit<R>,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
) -> Result<(), Error> {
for function in &*self.functions {
function
.1
.borrow_with(|| Function::parse(function.0, unit, dwarf, sup_dwarf))
.borrow_with(|| Function::parse(function.0, unit, dwarf))
.as_ref()
.map_err(Error::clone)?;
}
Expand All @@ -1155,7 +1144,6 @@ impl<R: gimli::Reader> Function<R> {
dw_die_offset: gimli::UnitOffset<R::Offset>,
unit: &gimli::Unit<R>,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
) -> Result<Self, Error> {
let mut entries = unit.entries_raw(Some(dw_die_offset))?;
let depth = entries.next_depth();
Expand All @@ -1179,7 +1167,7 @@ impl<R: gimli::Reader> Function<R> {
}
gimli::DW_AT_abstract_origin | gimli::DW_AT_specification => {
if name.is_none() {
name = name_attr(attr.value(), unit, dwarf, sup_dwarf, 16)?;
name = name_attr(attr.value(), unit, dwarf, 16)?;
}
}
_ => {}
Expand All @@ -1196,7 +1184,6 @@ impl<R: gimli::Reader> Function<R> {
depth,
unit,
dwarf,
sup_dwarf,
&mut inlined_functions,
&mut inlined_addresses,
0,
Expand Down Expand Up @@ -1239,7 +1226,6 @@ impl<R: gimli::Reader> Function<R> {
depth: isize,
unit: &gimli::Unit<R>,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
inlined_functions: &mut Vec<InlinedFunction<R>>,
inlined_addresses: &mut Vec<InlinedFunctionAddress>,
inlined_depth: usize,
Expand All @@ -1263,7 +1249,6 @@ impl<R: gimli::Reader> Function<R> {
next_depth,
unit,
dwarf,
sup_dwarf,
inlined_functions,
inlined_addresses,
inlined_depth,
Expand Down Expand Up @@ -1354,7 +1339,6 @@ impl<R: gimli::Reader> InlinedFunction<R> {
depth: isize,
unit: &gimli::Unit<R>,
dwarf: &ResDwarf<R>,
sup_dwarf: Option<&ResDwarf<R>>,
inlined_functions: &mut Vec<InlinedFunction<R>>,
inlined_addresses: &mut Vec<InlinedFunctionAddress>,
inlined_depth: usize,
Expand Down Expand Up @@ -1393,7 +1377,7 @@ impl<R: gimli::Reader> InlinedFunction<R> {
}
gimli::DW_AT_abstract_origin | gimli::DW_AT_specification => {
if name.is_none() {
name = name_attr(attr.value(), unit, dwarf, sup_dwarf, 16)?;
name = name_attr(attr.value(), unit, dwarf, 16)?;
}
}
gimli::DW_AT_call_file => {
Expand Down Expand Up @@ -1435,7 +1419,6 @@ impl<R: gimli::Reader> InlinedFunction<R> {
depth,
unit,
dwarf,
sup_dwarf,
inlined_functions,
inlined_addresses,
inlined_depth + 1,
Expand Down

0 comments on commit 512a1a9

Please sign in to comment.