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(dwarf): Resolve symbol names by exact address #510

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion symbolic-debuginfo/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'data> SymbolMap<'data> {
}
}

/// Looks up a symbol in the symbol map.
/// Looks up the symbol covering the given address.
pub fn lookup(&self, address: u64) -> Option<&Symbol<'data>> {
match self.symbols.binary_search_by_key(&address, Self::key) {
Ok(index) => Some(&self.symbols[index]),
Expand All @@ -306,6 +306,15 @@ impl<'data> SymbolMap<'data> {
}
}

/// Looks up a symbol by its start address.
pub fn lookup_exact(&self, address: u64) -> Option<&Symbol<'data>> {
let idx = self
.symbols
.binary_search_by_key(&address, Self::key)
.ok()?;
self.symbols.get(idx)
}

/// Looks up a symbol covering an entire range.
///
/// This is similar to [`lookup`], but it only returns the symbol result if it _also_ covers the
Expand Down
12 changes: 4 additions & 8 deletions symbolic-debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::collections::BTreeSet;
use std::error::Error;
use std::fmt;
use std::marker::PhantomData;
use std::ops::{Deref, RangeBounds};
use std::ops::Deref;
use std::sync::Arc;

use fallible_iterator::FallibleIterator;
Expand Down Expand Up @@ -743,11 +743,8 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
}

/// Resolves the name of a function from the symbol table.
fn resolve_symbol_name<R>(&self, range: R) -> Option<Name<'d>>
where
R: RangeBounds<u64>,
{
let symbol = self.inner.info.symbol_map.lookup_range(range)?;
fn resolve_symbol_name(&self, address: u64) -> Option<Name<'d>> {
let symbol = self.inner.info.symbol_map.lookup_exact(address)?;
let name = resolve_cow_name(self.bcsymbolmap, symbol.name.clone()?);
Some(Name::new(name, NameMangling::Mangled, self.language))
}
Expand Down Expand Up @@ -816,7 +813,6 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {

let function_address = offset(range_buf[0].begin, self.inner.info.address_offset);
let function_size = range_buf[range_buf.len() - 1].end - range_buf[0].begin;
let function_end = function_address + function_size;

// We have seen duplicate top-level function entries being yielded from the
// [`DwarfFunctionIterator`], which combined with recursively walking its inlinees can
Expand All @@ -840,7 +836,7 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
let symbol_name = if self.prefer_dwarf_names || inline {
None
} else {
self.resolve_symbol_name(function_address..function_end)
self.resolve_symbol_name(function_address)
};

let name = symbol_name
Expand Down