Skip to content

Commit

Permalink
read: add Unit::dwo_id
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Jul 16, 2021
1 parent 148e4ce commit 78ec1c6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 47 deletions.
47 changes: 2 additions & 45 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,23 +613,7 @@ where
dwo_parent_units = match dwo_parent
.units()
.map(|unit_header| dwo_parent.unit(unit_header))
.filter_map(|unit| {
let dwo_id = match unit.header.type_() {
gimli::UnitType::Skeleton(dwo_id) => dwo_id,
gimli::UnitType::Compilation => {
let mut entries = unit.entries();
let (_, this) = entries.next_dfs()?.unwrap();
match this.attr_value(gimli::constants::DW_AT_GNU_dwo_id)? {
Some(gimli::AttributeValue::DwoId(dwo_id)) => dwo_id,
Some(_) => unreachable!(),
None => return Ok(None),
}
}
_ => return Ok(None),
};

Ok(Some((dwo_id, unit)))
})
.filter_map(|unit| Ok(unit.dwo_id.map(|dwo_id| (dwo_id, unit))))
.collect()
{
Ok(units) => units,
Expand Down Expand Up @@ -1059,34 +1043,7 @@ where
};

if flags.dwo {
if let Some(dwo_id) = match unit.header.type_() {
UnitType::SplitCompilation(dwo_id) => Some(dwo_id),
UnitType::Compilation => {
let mut entries = unit.entries();
let this = match entries.next_dfs() {
Ok(v) => v.unwrap().1,
Err(err) => {
writeln_error(buf, dwarf, err.into(), "Failed to load CU root unit")?;
return Ok(());
}
};
match this.attr_value(gimli::constants::DW_AT_GNU_dwo_id) {
Ok(None) => None,
Ok(Some(gimli::AttributeValue::DwoId(v))) => Some(v),
Ok(Some(_)) => unreachable!(),
Err(err) => {
writeln_error(
buf,
dwarf,
err.into(),
"Failed to parse DW_AT_GNU_dwo_id",
)?;
return Ok(());
}
}
}
_ => None,
} {
if let Some(dwo_id) = unit.dwo_id {
if let Some(parent_unit) = dwo_parent_units.get(&dwo_id) {
unit.copy_relocated_attributes(parent_unit);
}
Expand Down
16 changes: 14 additions & 2 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::sync::Arc;
use crate::common::{
DebugAddrBase, DebugAddrIndex, DebugInfoOffset, DebugLineStrOffset, DebugLocListsBase,
DebugLocListsIndex, DebugRngListsBase, DebugRngListsIndex, DebugStrOffset, DebugStrOffsetsBase,
DebugStrOffsetsIndex, DebugTypesOffset, DwarfFileType, Encoding, LocationListsOffset,
DebugStrOffsetsIndex, DebugTypesOffset, DwarfFileType, DwoId, Encoding, LocationListsOffset,
RangeListsOffset, RawRangeListsOffset, SectionId, UnitSectionOffset,
};
use crate::constants;
Expand All @@ -14,7 +14,7 @@ use crate::read::{
DebugTypesUnitHeadersIter, DebuggingInformationEntry, EntriesCursor, EntriesRaw, EntriesTree,
Error, IncompleteLineProgram, LocListIter, LocationLists, Range, RangeLists, RawLocListIter,
RawRngListIter, Reader, ReaderOffset, ReaderOffsetId, Result, RngListIter, Section, UnitHeader,
UnitOffset,
UnitOffset, UnitType,
};

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

/// The line number program of the unit.
pub line_program: Option<IncompleteLineProgram<R, Offset>>,

/// The DWO ID of a skeleton unit or split compilation unit.
pub dwo_id: Option<DwoId>,
}

impl<R: Reader> Unit<R> {
Expand Down Expand Up @@ -629,6 +632,10 @@ impl<R: Reader> Unit<R> {
dwarf.file_type,
),
line_program: None,
dwo_id: match header.type_() {
UnitType::Skeleton(dwo_id) | UnitType::SplitCompilation(dwo_id) => Some(dwo_id),
_ => None,
},
header,
};
let mut name = None;
Expand Down Expand Up @@ -677,6 +684,11 @@ impl<R: Reader> Unit<R> {
unit.rnglists_base = base;
}
}
constants::DW_AT_GNU_dwo_id => {
if let AttributeValue::DwoId(dwo_id) = attr.value() {
unit.dwo_id = Some(dwo_id);
}
}
_ => {}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/write/loc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ mod tests {
loclists_base: DebugLocListsBase(0),
rnglists_base: DebugRngListsBase(0),
line_program: None,
dwo_id: None,
};
let context = ConvertUnitContext {
dwarf: &dwarf,
Expand Down
1 change: 1 addition & 0 deletions src/write/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,7 @@ mod tests {
loclists_base: DebugLocListsBase(0),
rnglists_base: DebugRngListsBase(0),
line_program: None,
dwo_id: None,
};

let mut entry_ids = HashMap::new();
Expand Down
1 change: 1 addition & 0 deletions src/write/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ mod tests {
loclists_base: DebugLocListsBase(0),
rnglists_base: DebugRngListsBase(0),
line_program: None,
dwo_id: None,
};
let context = ConvertUnitContext {
dwarf: &dwarf,
Expand Down
2 changes: 2 additions & 0 deletions src/write/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,7 @@ mod tests {
loclists_base: DebugLocListsBase(0),
rnglists_base: DebugRngListsBase(0),
line_program: None,
dwo_id: None,
};

let mut context = convert::ConvertUnitContext {
Expand Down Expand Up @@ -3018,6 +3019,7 @@ mod tests {
loclists_base: DebugLocListsBase(0),
rnglists_base: DebugRngListsBase(0),
line_program: None,
dwo_id: None,
};

let mut context = convert::ConvertUnitContext {
Expand Down

0 comments on commit 78ec1c6

Please sign in to comment.