Skip to content

Commit

Permalink
fmt, clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
0vercl0k committed Jun 13, 2024
1 parent 4ad6548 commit 961fdac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
3 changes: 1 addition & 2 deletions crates/symbolizer/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ impl<SC> Builder<SC> {
}

impl Builder<Symcache> {
pub fn build(self) -> Result<Symbolizer>
{
pub fn build(self) -> Result<Symbolizer> {
let Self {
symcache,
modules,
Expand Down
25 changes: 18 additions & 7 deletions crates/symbolizer/src/symbolizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ pub struct Config {
/// The [`Symbolizer`] is the main object that glues all the logic.
///
/// It downloads, parses PDB information, and symbolizes.
pub struct Symbolizer
{
pub struct Symbolizer {
/// Keep track of some statistics such as the number of lines symbolized,
/// PDB downloaded, etc.
stats: StatsBuilder,
Expand All @@ -248,8 +247,7 @@ pub struct Symbolizer
offline: bool,
}

impl Symbolizer
{
impl Symbolizer {
pub fn builder() -> Builder<NoSymcache> {
Builder::default()
}
Expand Down Expand Up @@ -313,7 +311,11 @@ impl Symbolizer
/// or remotely) and extract every bit of relevant information for us.
/// Finally, the result will be kept around to symbolize addresses in that
/// module faster in the future.
fn try_symbolize_addr_from_pdbs(&self, addr_space: &mut impl AddrSpace, addr: u64) -> Result<Option<Rc<String>>> {
fn try_symbolize_addr_from_pdbs(
&self,
addr_space: &mut impl AddrSpace,
addr: u64,
) -> Result<Option<Rc<String>>> {
trace!("symbolizing address {addr:#x}..");
let Some(module) = self.modules.find(addr) else {
trace!("address {addr:#x} doesn't belong to any module");
Expand Down Expand Up @@ -379,7 +381,11 @@ impl Symbolizer
/// If the address has been symbolized before, it will be in the
/// `addr_cache` already. If not, we need to take the slow path and ask the
/// right [`PdbCache`] which might require to create one in the first place.
fn try_symbolize_addr(&self, addr_space: &mut impl AddrSpace, addr: u64) -> Result<Option<Rc<String>>> {
fn try_symbolize_addr(
&self,
addr_space: &mut impl AddrSpace,
addr: u64,
) -> Result<Option<Rc<String>>> {
match self.addr_cache.borrow_mut().entry(addr) {
hash_map::Entry::Occupied(o) => {
self.stats.cache_hit();
Expand Down Expand Up @@ -423,7 +429,12 @@ impl Symbolizer

/// Symbolize `addr` in the `module!function+offset` style and write the
/// result into `output`.
pub fn full(&mut self, addr_space: &mut impl AddrSpace, addr: u64, output: &mut impl Write) -> Result<()> {
pub fn full(
&mut self,
addr_space: &mut impl AddrSpace,
addr: u64,
output: &mut impl Write,
) -> Result<()> {
match self.try_symbolize_addr(addr_space, addr)? {
Some(sym) => {
output
Expand Down
17 changes: 10 additions & 7 deletions crates/symbolizer/tests/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn raw_virt() {
let mut symb = Builder::default()
.modules(vec![Module::new("mrt100", 0x0, len)])
.msft_symsrv()
.symcache(&symcache("basics"))
.symcache(symcache("basics"))
.build()
.unwrap();

Expand Down Expand Up @@ -171,8 +171,8 @@ fn raw_file() {

let mut symb = Builder::default()
.modules(vec![Module::new("mrt100", 0x0, len)])
.online(vec!["https://msdl.microsoft.com/download/symbols/"].into_iter())
.symcache(&symcache("basics"))
.online(vec!["https://msdl.microsoft.com/download/symbols/"])
.symcache(symcache("basics"))
.build()
.unwrap();

Expand Down Expand Up @@ -254,15 +254,16 @@ fn user_dump() {
let mut symb = Builder::default()
.modules(modules.clone())
.msft_symsrv()
.symcache(&symcache("basics"))
.symcache(symcache("basics"))
.build()
.unwrap();

// 0:000> u 00007ff9`aa4f8eb2
// ntdll!EvtIntReportEventWorker$fin$0+0x2:
// 00007ff9`aa4f8eb2 4883ec50 sub rsp,50h
let mut output = Vec::new();
symb.full(&mut udmp_addr_space, 0x7ff9aa4f8eb2, &mut output).unwrap();
symb.full(&mut udmp_addr_space, 0x7ff9aa4f8eb2, &mut output)
.unwrap();
assert_eq!(
String::from_utf8(output).unwrap(),
"ntdll.dll!EvtIntReportEventWorker$fin$0+0x2"
Expand All @@ -281,7 +282,7 @@ fn user_dump() {

drop(symb);
let mut symb_offline = Builder::default()
.symcache(&symcache("basics"))
.symcache(symcache("basics"))
.modules(modules)
.build()
.unwrap();
Expand All @@ -290,7 +291,9 @@ fn user_dump() {
// ntdll!EvtIntReportEventWorker$fin$0+0x2:
// 00007ff9`aa4f8eb2 4883ec50 sub rsp,50h
let mut output = Vec::new();
symb_offline.full(&mut udmp_addr_space, 0x7ff9aa4f8eb2, &mut output).unwrap();
symb_offline
.full(&mut udmp_addr_space, 0x7ff9aa4f8eb2, &mut output)
.unwrap();
assert_ne!(
String::from_utf8(output).unwrap(),
"ntdll.dll!EvtIntReportEventWorker$fin$0+0x2"
Expand Down

0 comments on commit 961fdac

Please sign in to comment.