Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(debuginfo): include more pdb symbols #641

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions symbolic-debuginfo/src/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::sync::Arc;
use elsa::FrozenMap;
use parking_lot::RwLock;
use pdb_addr2line::pdb::{
AddressMap, FallibleIterator, InlineSiteSymbol, LineProgram, MachineType, Module, ModuleInfo,
PdbInternalSectionOffset, ProcedureSymbol, RawString, SeparatedCodeSymbol, SymbolData,
TypeIndex,
AddressMap, FallibleIterator, ImageSectionHeader, InlineSiteSymbol, LineProgram, MachineType,
Module, ModuleInfo, PdbInternalSectionOffset, ProcedureSymbol, RawString, SeparatedCodeSymbol,
SymbolData, TypeIndex,
};
use pdb_addr2line::ModuleProvider;
use smallvec::SmallVec;
Expand Down Expand Up @@ -120,6 +120,7 @@ pub struct PdbObject<'data> {
debug_info: Arc<pdb::DebugInformation<'data>>,
pdb_info: pdb::PDBInformation<'data>,
public_syms: pdb::SymbolTable<'data>,
executable_sections: ExecutableSections,
data: &'data [u8],
}

Expand All @@ -144,13 +145,15 @@ impl<'data> PdbObject<'data> {
let dbi = pdb.debug_information()?;
let pdbi = pdb.pdb_information()?;
let pubi = pdb.global_symbols()?;
let sections = pdb.sections()?;

Ok(PdbObject {
pdb: Arc::new(RwLock::new(pdb)),
debug_info: Arc::new(dbi),
pdb_info: pdbi,
public_syms: pubi,
data,
executable_sections: ExecutableSections::from_sections(&sections),
})
}

Expand Down Expand Up @@ -224,6 +227,7 @@ impl<'data> PdbObject<'data> {
PdbSymbolIterator {
symbols: self.public_syms.iter(),
address_map: self.pdb.write().address_map().ok(),
executable_sections: &self.executable_sections,
}
}

Expand Down Expand Up @@ -383,12 +387,50 @@ pub(crate) fn arch_from_machine(machine: MachineType) -> Arch {
}
}

/// Contains information about which sections are executable.
struct ExecutableSections {
/// For every section header in the PDB, a boolean which indicates whether the "executable"
/// or "execute" flag is set in the section header's characteristics.
is_executable_per_section: Vec<bool>,
}

impl ExecutableSections {
pub fn from_sections(sections: &Option<Vec<ImageSectionHeader>>) -> Self {
Self {
is_executable_per_section: match sections {
Some(sections) => sections
.iter()
.map(|section| section.characteristics)
.map(|char| char.executable() || char.execute())
.collect(),
None => Default::default(),
},
}
}

/// Returns whether the given offset is contained in an executable section.
pub fn contains(&self, offset: &PdbInternalSectionOffset) -> bool {
// offset.section is a one-based index.
if offset.section == 0 {
// No section.
return false;
}

let section_index = (offset.section - 1) as usize;
self.is_executable_per_section
.get(section_index)
.cloned()
.unwrap_or(false)
}
}

/// An iterator over symbols in the PDB file.
///
/// Returned by [`PdbObject::symbols`](struct.PdbObject.html#method.symbols).
pub struct PdbSymbolIterator<'data, 'object> {
symbols: pdb::SymbolIter<'object>,
address_map: Option<AddressMap<'data>>,
executable_sections: &'object ExecutableSections,
}

impl<'data, 'object> Iterator for PdbSymbolIterator<'data, 'object> {
Expand All @@ -399,7 +441,7 @@ impl<'data, 'object> Iterator for PdbSymbolIterator<'data, 'object> {

while let Ok(Some(symbol)) = self.symbols.next() {
if let Ok(SymbolData::Public(public)) = symbol.parse() {
if !public.function {
if !self.executable_sections.contains(&public.offset) {
continue;
}

Expand Down