Skip to content

Commit db5634d

Browse files
committed
read: add Unit::dwo_id
1 parent c13c172 commit db5634d

6 files changed

Lines changed: 23 additions & 47 deletions

File tree

examples/dwarfdump.rs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -613,23 +613,7 @@ where
613613
dwo_parent_units = match dwo_parent
614614
.units()
615615
.map(|unit_header| dwo_parent.unit(unit_header))
616-
.filter_map(|unit| {
617-
let dwo_id = match unit.header.type_() {
618-
gimli::UnitType::Skeleton(dwo_id) => dwo_id,
619-
gimli::UnitType::Compilation => {
620-
let mut entries = unit.entries();
621-
let (_, this) = entries.next_dfs()?.unwrap();
622-
match this.attr_value(gimli::constants::DW_AT_GNU_dwo_id)? {
623-
Some(gimli::AttributeValue::DwoId(dwo_id)) => dwo_id,
624-
Some(_) => unreachable!(),
625-
None => return Ok(None),
626-
}
627-
}
628-
_ => return Ok(None),
629-
};
630-
631-
Ok(Some((dwo_id, unit)))
632-
})
616+
.filter_map(|unit| Ok(unit.dwo_id.map(|dwo_id| (dwo_id, unit))))
633617
.collect()
634618
{
635619
Ok(units) => units,
@@ -1059,34 +1043,7 @@ where
10591043
};
10601044

10611045
if flags.dwo {
1062-
if let Some(dwo_id) = match unit.header.type_() {
1063-
UnitType::SplitCompilation(dwo_id) => Some(dwo_id),
1064-
UnitType::Compilation => {
1065-
let mut entries = unit.entries();
1066-
let this = match entries.next_dfs() {
1067-
Ok(v) => v.unwrap().1,
1068-
Err(err) => {
1069-
writeln_error(buf, dwarf, err.into(), "Failed to load CU root unit")?;
1070-
return Ok(());
1071-
}
1072-
};
1073-
match this.attr_value(gimli::constants::DW_AT_GNU_dwo_id) {
1074-
Ok(None) => None,
1075-
Ok(Some(gimli::AttributeValue::DwoId(v))) => Some(v),
1076-
Ok(Some(_)) => unreachable!(),
1077-
Err(err) => {
1078-
writeln_error(
1079-
buf,
1080-
dwarf,
1081-
err.into(),
1082-
"Failed to parse DW_AT_GNU_dwo_id",
1083-
)?;
1084-
return Ok(());
1085-
}
1086-
}
1087-
}
1088-
_ => None,
1089-
} {
1046+
if let Some(dwo_id) = unit.dwo_id {
10901047
if let Some(parent_unit) = dwo_parent_units.get(&dwo_id) {
10911048
unit.copy_relocated_attributes(parent_unit);
10921049
}

src/read/dwarf.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloc::sync::Arc;
44
use crate::common::{
55
DebugAddrBase, DebugAddrIndex, DebugInfoOffset, DebugLineStrOffset, DebugLocListsBase,
66
DebugLocListsIndex, DebugRngListsBase, DebugRngListsIndex, DebugStrOffset, DebugStrOffsetsBase,
7-
DebugStrOffsetsIndex, DebugTypesOffset, DwarfFileType, Encoding, LocationListsOffset,
7+
DebugStrOffsetsIndex, DebugTypesOffset, DwarfFileType, DwoId, Encoding, LocationListsOffset,
88
RangeListsOffset, RawRangeListsOffset, SectionId, UnitSectionOffset,
99
};
1010
use crate::constants;
@@ -14,7 +14,7 @@ use crate::read::{
1414
DebugTypesUnitHeadersIter, DebuggingInformationEntry, EntriesCursor, EntriesRaw, EntriesTree,
1515
Error, IncompleteLineProgram, LocListIter, LocationLists, Range, RangeLists, RawLocListIter,
1616
RawRngListIter, Reader, ReaderOffset, ReaderOffsetId, Result, RngListIter, Section, UnitHeader,
17-
UnitOffset,
17+
UnitOffset, UnitType,
1818
};
1919

2020
/// All of the commonly used DWARF sections, and other common information.
@@ -602,6 +602,9 @@ where
602602

603603
/// The line number program of the unit.
604604
pub line_program: Option<IncompleteLineProgram<R, Offset>>,
605+
606+
/// The DWO ID of a skeleton unit or split compilation unit.
607+
pub dwo_id: Option<DwoId>,
605608
}
606609

607610
impl<R: Reader> Unit<R> {
@@ -629,6 +632,10 @@ impl<R: Reader> Unit<R> {
629632
dwarf.file_type,
630633
),
631634
line_program: None,
635+
dwo_id: match header.type_() {
636+
UnitType::Skeleton(dwo_id) | UnitType::SplitCompilation(dwo_id) => Some(dwo_id),
637+
_ => None,
638+
},
632639
header,
633640
};
634641
let mut name = None;
@@ -677,6 +684,13 @@ impl<R: Reader> Unit<R> {
677684
unit.rnglists_base = base;
678685
}
679686
}
687+
constants::DW_AT_GNU_dwo_id => {
688+
if unit.dwo_id.is_none() {
689+
if let AttributeValue::DwoId(dwo_id) = attr.value() {
690+
unit.dwo_id = Some(dwo_id);
691+
}
692+
}
693+
}
680694
_ => {}
681695
}
682696
}

src/write/loc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ mod tests {
517517
loclists_base: DebugLocListsBase(0),
518518
rnglists_base: DebugRngListsBase(0),
519519
line_program: None,
520+
dwo_id: None,
520521
};
521522
let context = ConvertUnitContext {
522523
dwarf: &dwarf,

src/write/op.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,7 @@ mod tests {
15831583
loclists_base: DebugLocListsBase(0),
15841584
rnglists_base: DebugRngListsBase(0),
15851585
line_program: None,
1586+
dwo_id: None,
15861587
};
15871588

15881589
let mut entry_ids = HashMap::new();

src/write/range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ mod tests {
384384
loclists_base: DebugLocListsBase(0),
385385
rnglists_base: DebugRngListsBase(0),
386386
line_program: None,
387+
dwo_id: None,
387388
};
388389
let context = ConvertUnitContext {
389390
dwarf: &dwarf,

src/write/unit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,7 @@ mod tests {
25462546
loclists_base: DebugLocListsBase(0),
25472547
rnglists_base: DebugRngListsBase(0),
25482548
line_program: None,
2549+
dwo_id: None,
25492550
};
25502551

25512552
let mut context = convert::ConvertUnitContext {
@@ -3018,6 +3019,7 @@ mod tests {
30183019
loclists_base: DebugLocListsBase(0),
30193020
rnglists_base: DebugRngListsBase(0),
30203021
line_program: None,
3022+
dwo_id: None,
30213023
};
30223024

30233025
let mut context = convert::ConvertUnitContext {

0 commit comments

Comments
 (0)