Skip to content

Commit

Permalink
Merge pull request #517 from khuey/dwo_names
Browse files Browse the repository at this point in the history
Add dwo section names.
  • Loading branch information
philipc authored Jul 2, 2020
2 parents 9a0cbd6 + 2a5b377 commit 7b11307
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ struct Flags {
}

impl Flags {
fn section_name(&self, name: &str) -> String {
fn section_name(&self, id: gimli::SectionId) -> Option<&'static str> {
if self.dwo {
format!("{}.dwo", name)
id.dwo_name()
} else {
name.to_string()
Some(id.name())
}
}
}
Expand Down Expand Up @@ -520,8 +520,8 @@ where

let mut load_section = |id: gimli::SectionId| -> Result<_> {
let mut relocations = RelocationMap::default();
let name = flags.section_name(id.name());
let data = match file.section_by_name(&name) {
let name = flags.section_name(id);
let data = match name.and_then(|name| file.section_by_name(&name)) {
Some(ref section) => {
// DWO sections never have relocations, so don't bother.
if !flags.dwo {
Expand Down
14 changes: 14 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,18 @@ impl SectionId {
SectionId::DebugTypes => ".debug_types",
}
}

/// Returns the ELF section name for this kind, when found in a .dwo file.
pub fn dwo_name(self) -> Option<&'static str> {
Some(match self {
SectionId::DebugAbbrev => ".debug_abbrev.dwo",
SectionId::DebugInfo => ".debug_info.dwo",
SectionId::DebugLine => ".debug_line.dwo",
SectionId::DebugLocLists => ".debug_loclists.dwo",
SectionId::DebugMacro => ".debug_macro.dwo",
SectionId::DebugStr => ".debug_str.dwo",
SectionId::DebugStrOffsets => ".debug_str_offsets.dwo",
_ => return None,
})
}
}
6 changes: 6 additions & 0 deletions src/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ pub trait Section<R>: From<R> {
Self::id().name()
}

/// Returns the ELF section name (if any) for this type when used in a dwo
/// file.
fn dwo_section_name() -> Option<&'static str> {
Self::id().dwo_name()
}

/// Try to load the section using the given loader function.
fn load<F, E>(f: F) -> core::result::Result<Self, E>
where
Expand Down

0 comments on commit 7b11307

Please sign in to comment.