Skip to content

Commit

Permalink
Stop returning symbols without name or address
Browse files Browse the repository at this point in the history
It is believed to be extremely rare that source code information for an
address is available but no symbol name: presumably that would require a
specially crafted DWARF file, if allowed at all.
With this change we ignore such cases and stop returning a Sym object to
begin with. In so doing we can now properly treat the symbol name,
address, and offset as unconditionally present.

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o authored and danielocfb committed Aug 1, 2023
1 parent 0d88125 commit 7e4439a
Showing 1 changed file with 34 additions and 45 deletions.
79 changes: 34 additions & 45 deletions src/symbolize/symbolizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,62 +213,51 @@ impl Symbolizer {
#[cfg_attr(feature = "tracing", crate::log::instrument(skip_all, fields(addr = format_args!("0x{addr:x}"), resolver = ?resolver)))]
fn symbolize_with_resolver(&self, addr: Addr, resolver: &dyn SymResolver) -> Result<Vec<Sym>> {
let syms = resolver.find_syms(addr)?;
if syms.is_empty() {
return Ok(Vec::new())
}

let linfo = if self.src_location {
resolver.find_line_info(addr)?
} else {
None
};
if syms.is_empty() {
if let Some(linfo) = linfo {
Ok(vec![Sym {
name: "".to_string(),
addr: 0,
offset: 0,
path: Some(linfo.path),

let mut results = vec![];
for sym in syms {
if let Some(ref linfo) = linfo {
let IntSym {
name,
addr: sym_addr,
lang,
} = sym;
results.push(Sym {
name: self.maybe_demangle(name, lang),
addr: sym_addr,
offset: addr - sym_addr,
path: Some(linfo.path.clone()),
line: linfo.line,
column: linfo.column,
_non_exhaustive: (),
}])
});
} else {
Ok(Vec::new())
}
} else {
let mut results = vec![];
for sym in syms {
if let Some(ref linfo) = linfo {
let IntSym {
name,
addr: sym_addr,
lang,
} = sym;
results.push(Sym {
name: self.maybe_demangle(name, lang),
addr: sym_addr,
offset: addr - sym_addr,
path: Some(linfo.path.clone()),
line: linfo.line,
column: linfo.column,
_non_exhaustive: (),
});
} else {
let IntSym {
name,
addr: sym_addr,
lang,
} = sym;
results.push(Sym {
name: self.maybe_demangle(name, lang),
addr: sym_addr,
offset: addr - sym_addr,
path: None,
line: None,
column: None,
_non_exhaustive: (),
});
}
let IntSym {
name,
addr: sym_addr,
lang,
} = sym;
results.push(Sym {
name: self.maybe_demangle(name, lang),
addr: sym_addr,
offset: addr - sym_addr,
path: None,
line: None,
column: None,
_non_exhaustive: (),
});
}
Ok(results)
}
Ok(results)
}

/// Symbolize a list of addresses using the provided [`SymResolver`].
Expand Down

0 comments on commit 7e4439a

Please sign in to comment.