Skip to content

Commit abea56c

Browse files
authored
Update gimli and addr2line (probe-rs#3796)
1 parent 50d90f7 commit abea56c

File tree

7 files changed

+121
-162
lines changed

7 files changed

+121
-162
lines changed

Cargo.lock

Lines changed: 29 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

probe-rs-debug/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ description = "Debugging functionality built on top of the probe-rs crate"
1414
exclude = ["tests/debug-unwind-tests"]
1515

1616
[dependencies]
17-
addr2line = "0.25.0"
17+
addr2line = "0.26"
1818
bitfield = "0.19.0"
19-
gimli = "0.32.0"
19+
gimli = "0.33.0"
2020
itertools = "0.14.0"
2121
object = "0.38"
2222
parse_int = "0.9.0"

probe-rs-debug/src/debug_info.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,14 @@ impl DebugInfo {
259259
match parent_variable.variable_node_type {
260260
VariableNodeType::TypeOffset(header_offset, unit_offset)
261261
| VariableNodeType::DirectLookup(header_offset, unit_offset) => {
262-
let Some(unit_info) = self
263-
.unit_infos
264-
.iter()
265-
.find(|unit_info| unit_info.unit.header.offset() == header_offset.into())
266-
else {
262+
let Some(unit_info) = self.unit_infos.iter().find(|unit_info| {
263+
unit_info
264+
.unit
265+
.header
266+
.offset()
267+
.to_debug_info_offset(&unit_info.unit)
268+
== Some(header_offset)
269+
}) else {
267270
return Err(DebugError::Other(
268271
"Failed to find unit info for offset lookup.".to_string(),
269272
));
@@ -294,7 +297,7 @@ impl DebugInfo {
294297

295298
// Only process statics for this unit header.
296299
// Navigate the current unit from the header down.
297-
let (_, unit_node) = entries.next_dfs()?.unwrap();
300+
let unit_node = entries.next_dfs()?.unwrap();
298301
let unit_offset = unit_node.offset();
299302

300303
let mut type_tree = unit_info.unit.entries_tree(Some(unit_offset))?;
@@ -952,13 +955,13 @@ impl DebugInfo {
952955
attribute: gimli::DwAt,
953956
die: &Die,
954957
unit_info: &'unit_info UnitInfo,
955-
) -> Option<Die<'debug_info, 'debug_info>>
958+
) -> Option<Die>
956959
where
957960
'unit_info: 'debug_info,
958961
{
959-
let attr = die.attr(attribute).ok().flatten()?;
962+
let attr = die.attr(attribute)?;
960963

961-
self.resolve_die_reference_with_unit(&attr, unit_info)
964+
self.resolve_die_reference_with_unit(attr, unit_info)
962965
.ok()
963966
.map(|(_, die)| die)
964967
}
@@ -973,7 +976,7 @@ impl DebugInfo {
973976
&'debug_info self,
974977
attr: &gimli::Attribute<GimliReader>,
975978
unit_info: &'unit_info UnitInfo,
976-
) -> Result<(&'debug_info UnitInfo, Die<'debug_info, 'debug_info>), DebugError>
979+
) -> Result<(&'debug_info UnitInfo, Die), DebugError>
977980
where
978981
'unit_info: 'debug_info,
979982
{
@@ -1151,7 +1154,7 @@ pub fn unwind_register(
11511154
// If we do not have unwind info, or there is no register rule, then use UnwindRule::Undefined.
11521155
let register_rule = debug_register
11531156
.dwarf_id
1154-
.map(|register_position| unwind_info.register(gimli::Register(register_position)))
1157+
.and_then(|register_position| unwind_info.register(gimli::Register(register_position)))
11551158
.unwrap_or(RegisterRule::Undefined);
11561159

11571160
unwind_register_using_rule(

probe-rs-debug/src/function_die.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use gimli::{RunTimeEndian, UnitOffset};
1+
use gimli::UnitOffset;
22
use std::ops::Range;
33

44
use crate::{MemoryInterface, stack_frame::StackFrameInfo};
@@ -8,27 +8,26 @@ use super::{
88
unit_info::{ExpressionResult, UnitInfo},
99
};
1010

11-
pub(crate) type Die<'abbrev, 'unit> =
12-
gimli::DebuggingInformationEntry<'abbrev, 'unit, debug_info::GimliReader, usize>;
11+
pub(crate) type Die = gimli::DebuggingInformationEntry<debug_info::GimliReader, usize>;
1312

1413
/// Reference to a DIE for a function
1514
#[derive(Clone)]
1615
pub(crate) struct FunctionDie<'data> {
1716
/// A reference to the compilation unit this function belongs to.
1817
pub(crate) unit_info: &'data UnitInfo,
1918
/// The DIE (Debugging Information Entry) for the function.
20-
pub(crate) function_die: Die<'data, 'data>,
19+
pub(crate) function_die: Die,
2120
/// The optional specification DIE for the function, if it has one.
2221
/// - For regular functions, this applies to the `function_die`.
2322
/// - For inlined functions, this applies to the `abstract_die`.
2423
///
2524
/// The specification DIE will contain separately declared attributes,
2625
/// e.g. for the function name.
2726
/// See DWARF spec, 2.13.2.
28-
pub(crate) specification_die: Option<Die<'data, 'data>>,
27+
pub(crate) specification_die: Option<Die>,
2928
/// Only present for inlined functions, where this is a reference
3029
/// to the declaration of the function.
31-
pub(crate) abstract_die: Option<Die<'data, 'data>>,
30+
pub(crate) abstract_die: Option<Die>,
3231
/// The address ranges for which this function is valid.
3332
pub(crate) ranges: Vec<Range<u64>>,
3433
}
@@ -39,7 +38,7 @@ impl<'a> FunctionDie<'a> {
3938
/// relevant to the address/program counter specified.
4039
/// Other DIE's will return None, and should be ignored.
4140
pub(crate) fn new(
42-
function_die: Die<'a, 'a>,
41+
function_die: Die,
4342
unit_info: &'a UnitInfo,
4443
debug_info: &'a DebugInfo,
4544
address: u64,
@@ -198,11 +197,14 @@ impl<'a> FunctionDie<'a> {
198197
debug_info: &super::DebugInfo,
199198
attribute_name: gimli::DwAt,
200199
) -> Option<debug_info::GimliAttribute> {
201-
let attribute =
202-
collapsed_attribute(&self.function_die, &self.specification_die, attribute_name);
200+
let attribute = collapsed_attribute(
201+
&self.function_die,
202+
self.specification_die.as_ref(),
203+
attribute_name,
204+
);
203205

204206
if attribute.is_some() {
205-
return attribute;
207+
return attribute.cloned();
206208
}
207209

208210
// For inlined function, the *abstract instance* has to be checked if we cannot find the
@@ -213,11 +215,14 @@ impl<'a> FunctionDie<'a> {
213215
abstract_die,
214216
self.unit_info,
215217
);
216-
let inline_attribute =
217-
collapsed_attribute(abstract_die, &inlined_specification_die, attribute_name);
218+
let inline_attribute = collapsed_attribute(
219+
abstract_die,
220+
inlined_specification_die.as_ref(),
221+
attribute_name,
222+
);
218223

219224
if inline_attribute.is_some() {
220-
return inline_attribute;
225+
return inline_attribute.cloned();
221226
}
222227
}
223228

@@ -259,21 +264,13 @@ impl<'a> FunctionDie<'a> {
259264
}
260265

261266
// Try to retrieve the attribute from the specification or the function DIE.
262-
fn collapsed_attribute(
263-
function_die: &Die,
264-
specification_die: &Option<Die>,
267+
fn collapsed_attribute<'a>(
268+
function_die: &'a Die,
269+
specification_die: Option<&'a Die>,
265270
attribute_name: gimli::DwAt,
266-
) -> Option<gimli::Attribute<gimli::EndianReader<RunTimeEndian, std::rc::Rc<[u8]>>>> {
271+
) -> Option<&'a debug_info::GimliAttribute> {
267272
specification_die
268273
.as_ref()
269-
.and_then(|specification_die| {
270-
specification_die
271-
.attr(attribute_name)
272-
.map_or(None, |attribute| attribute)
273-
})
274-
.or_else(|| {
275-
function_die
276-
.attr(attribute_name)
277-
.map_or(None, |attribute| attribute)
278-
})
274+
.and_then(|specification_die| specification_die.attr(attribute_name))
275+
.or_else(|| function_die.attr(attribute_name))
279276
}

probe-rs-debug/src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn extract_file(
206206
/// If a DW_AT_byte_size attribute exists, return the u64 value, otherwise (including errors) return None
207207
fn extract_byte_size(node_die: &DebuggingInformationEntry<GimliReader>) -> Option<u64> {
208208
match node_die.attr(gimli::DW_AT_byte_size) {
209-
Ok(Some(byte_size_attr)) => match byte_size_attr.value() {
209+
Some(byte_size_attr) => match byte_size_attr.value() {
210210
AttributeValue::Udata(byte_size) => Some(byte_size),
211211
AttributeValue::Data1(byte_size) => Some(byte_size as u64),
212212
AttributeValue::Data2(byte_size) => Some(byte_size as u64),
@@ -217,14 +217,7 @@ fn extract_byte_size(node_die: &DebuggingInformationEntry<GimliReader>) -> Optio
217217
None
218218
}
219219
},
220-
Ok(None) => None,
221-
Err(error) => {
222-
tracing::warn!(
223-
"Failed to extract byte_size: {error:?} for debug_entry {:?}",
224-
node_die.tag().static_string()
225-
);
226-
None
227-
}
220+
None => None,
228221
}
229222
}
230223

@@ -244,9 +237,7 @@ pub(crate) fn _print_all_attributes(
244237
tag: &gimli::DebuggingInformationEntry<DwarfReader>,
245238
print_depth: usize,
246239
) {
247-
let mut attrs = tag.attrs();
248-
249-
while let Some(attr) = attrs.next().unwrap() {
240+
for attr in tag.attrs() {
250241
for _ in 0..print_depth {
251242
print!("\t");
252243
}

0 commit comments

Comments
 (0)