From 368d36ef20f50cb6fd5161c31959122ce1cba961 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Sat, 14 Jan 2023 23:03:37 -0800 Subject: [PATCH 1/4] Add a helper to get the DWO name. --- src/read/dwarf.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/read/dwarf.rs b/src/read/dwarf.rs index cce364c2..678e9d2b 100644 --- a/src/read/dwarf.rs +++ b/src/read/dwarf.rs @@ -996,6 +996,25 @@ impl Unit { self.rnglists_base = other.rnglists_base; } } + + /// Find the dwo name (if any) for this unit, automatically handling the differences + /// between the standardized DWARF 5 split DWARF format and the pre-DWARF 5 GNU + /// extension. + /// + /// The returned value is relative to this unit's `comp_dir`. + pub fn dwo_name(&self) -> Result>> { + let mut entries = self.entries(); + if let None = entries.next_entry()? { + return Ok(None); + } + + let entry = entries.current().unwrap(); + if self.header.version() < 5 { + entry.attr_value(constants::DW_AT_GNU_dwo_name) + } else { + entry.attr_value(constants::DW_AT_dwo_name) + } + } } impl UnitSectionOffset { From f3b06fdab840f1a3c2bdfdbd910388331422fddd Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Sat, 14 Jan 2023 23:07:55 -0800 Subject: [PATCH 2/4] Add a helper to blend two Dwarfs appropriately for the unpacked split DWARF case. --- src/read/dwarf.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/read/dwarf.rs b/src/read/dwarf.rs index 678e9d2b..4ad1cd14 100644 --- a/src/read/dwarf.rs +++ b/src/read/dwarf.rs @@ -569,6 +569,20 @@ impl Dwarf { } err.description().into() } + + /// Assuming `self` was loaded from a .dwo, take the appropriate + /// sections from `parent` (which contains the skeleton unit for this + /// dwo) and return a suitable instance of `Dwarf`. + pub fn make_dwo(mut self, parent: &Dwarf) -> Dwarf { + self.file_type = DwarfFileType::Dwo; + // These sections are always taken from the parent file and not the dwo. + self.debug_addr = parent.debug_addr.clone(); + // .debug_rnglists comes from the DWO, .debug_ranges comes from the + // parent file. + self.ranges + .set_debug_ranges(parent.ranges.debug_ranges().clone()); + self + } } /// The sections from a `.dwp` file. From 24698e8ce7386412a24e0e6617e8a917255f154b Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Sun, 15 Jan 2023 18:44:21 -0800 Subject: [PATCH 3/4] Address review comments. --- examples/dwarfdump.rs | 8 +++----- src/read/dwarf.rs | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/dwarfdump.rs b/examples/dwarfdump.rs index 98ad2276..8840b185 100644 --- a/examples/dwarfdump.rs +++ b/examples/dwarfdump.rs @@ -679,12 +679,10 @@ where let mut dwarf = gimli::Dwarf::load(&mut load_section)?; if flags.dwo { - dwarf.file_type = gimli::DwarfFileType::Dwo; if let Some(dwo_parent) = dwo_parent { - dwarf.debug_addr = dwo_parent.debug_addr.clone(); - dwarf - .ranges - .set_debug_ranges(dwo_parent.ranges.debug_ranges().clone()); + dwarf = dwarf.make_dwo(&dwo_parent) + } else { + dwarf.file_type = gimli::DwarfFileType::Dwo; } } diff --git a/src/read/dwarf.rs b/src/read/dwarf.rs index 4ad1cd14..fa15c0fb 100644 --- a/src/read/dwarf.rs +++ b/src/read/dwarf.rs @@ -569,7 +569,9 @@ impl Dwarf { } err.description().into() } +} +impl Dwarf { /// Assuming `self` was loaded from a .dwo, take the appropriate /// sections from `parent` (which contains the skeleton unit for this /// dwo) and return a suitable instance of `Dwarf`. From 69935e5af8911b9af282ccba84630e1f767067a6 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Sun, 15 Jan 2023 18:57:35 -0800 Subject: [PATCH 4/4] more comments --- examples/dwarfdump.rs | 2 +- src/read/dwarf.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/dwarfdump.rs b/examples/dwarfdump.rs index 8840b185..a11f298f 100644 --- a/examples/dwarfdump.rs +++ b/examples/dwarfdump.rs @@ -680,7 +680,7 @@ where let mut dwarf = gimli::Dwarf::load(&mut load_section)?; if flags.dwo { if let Some(dwo_parent) = dwo_parent { - dwarf = dwarf.make_dwo(&dwo_parent) + dwarf.make_dwo(&dwo_parent); } else { dwarf.file_type = gimli::DwarfFileType::Dwo; } diff --git a/src/read/dwarf.rs b/src/read/dwarf.rs index fa15c0fb..43239665 100644 --- a/src/read/dwarf.rs +++ b/src/read/dwarf.rs @@ -574,8 +574,8 @@ impl Dwarf { impl Dwarf { /// Assuming `self` was loaded from a .dwo, take the appropriate /// sections from `parent` (which contains the skeleton unit for this - /// dwo) and return a suitable instance of `Dwarf`. - pub fn make_dwo(mut self, parent: &Dwarf) -> Dwarf { + /// dwo) such as `.debug_addr` and merge them into this `Dwarf`. + pub fn make_dwo(&mut self, parent: &Dwarf) { self.file_type = DwarfFileType::Dwo; // These sections are always taken from the parent file and not the dwo. self.debug_addr = parent.debug_addr.clone(); @@ -583,7 +583,6 @@ impl Dwarf { // parent file. self.ranges .set_debug_ranges(parent.ranges.debug_ranges().clone()); - self } }