diff options
| author | Michael Krasnitski <michael.krasnitski@gmail.com> | 2024-04-16 19:32:04 -0400 |
|---|---|---|
| committer | Kyle Martin <krm504@nyu.edu> | 2024-05-09 13:11:41 -0400 |
| commit | 29b62677dad48aa4d55ad2dae5d176d9880216bd (patch) | |
| tree | f205a5f4ebb7e71ea132fe06a7076c70616d3c62 /rust/examples/dwarf | |
| parent | 608f261e6bca5869e748d4509da92a5717dce75d (diff) | |
Fix clippy warnings and run rustfmt
Diffstat (limited to 'rust/examples/dwarf')
| -rw-r--r-- | rust/examples/dwarf/dwarf_export/src/lib.rs | 12 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs | 22 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/lib.rs | 45 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarfdump/src/lib.rs | 4 |
4 files changed, 38 insertions, 45 deletions
diff --git a/rust/examples/dwarf/dwarf_export/src/lib.rs b/rust/examples/dwarf/dwarf_export/src/lib.rs index ef71f1ae..057abe27 100644 --- a/rust/examples/dwarf/dwarf_export/src/lib.rs +++ b/rust/examples/dwarf/dwarf_export/src/lib.rs @@ -522,13 +522,11 @@ fn export_data_vars( for data_variable in &bv.data_variables() { if let Some(symbol) = data_variable.symbol(bv) { - if symbol.sym_type() == SymbolType::External { - continue; - } else if symbol.sym_type() == SymbolType::Function { - continue; - } else if symbol.sym_type() == SymbolType::ImportedFunction { - continue; - } else if symbol.sym_type() == SymbolType::LibraryFunction { + if let SymbolType::External + | SymbolType::Function + | SymbolType::ImportedFunction + | SymbolType::LibraryFunction = symbol.sym_type() + { continue; } } diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs index b1b91c1d..537051c8 100644 --- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -28,6 +28,7 @@ use gimli::{DebuggingInformationEntry, Dwarf, Reader, Unit}; use log::{error, warn}; use std::{ + cmp::Ordering, collections::{hash_map::Values, HashMap}, hash::Hash, }; @@ -222,13 +223,7 @@ impl DebugInfoBuilder { self.types.values() } - pub(crate) fn add_type( - &mut self, - type_uid: TypeUID, - name: String, - t: Ref<Type>, - commit: bool, - ) { + pub(crate) fn add_type(&mut self, type_uid: TypeUID, name: String, t: Ref<Type>, commit: bool) { if let Some(DebugType { name: existing_name, t: existing_type, @@ -379,8 +374,7 @@ impl DebugInfoBuilder { if simplify_str_to_fqn(func_full_name, true).len() < simplify_str_to_fqn(symbol_full_name.clone(), true).len() { - func.full_name = - Some(symbol_full_name.to_string()); + func.full_name = Some(symbol_full_name.to_string()); } } } @@ -388,10 +382,12 @@ impl DebugInfoBuilder { if let Some(address) = func.address { let existing_functions = bv.functions_at(address); - if existing_functions.len() > 1 { - warn!("Multiple existing functions at address {address:08x}. One or more functions at this address may have the wrong platform information. Please report this binary."); - } else if existing_functions.len() == 1 { - func.platform = Some(existing_functions.get(0).platform()); + match existing_functions.len().cmp(&1) { + Ordering::Greater => { + warn!("Multiple existing functions at address {address:08x}. One or more functions at this address may have the wrong platform information. Please report this binary."); + } + Ordering::Equal => func.platform = Some(existing_functions.get(0).platform()), + Ordering::Less => {} } } } diff --git a/rust/examples/dwarf/dwarf_import/src/lib.rs b/rust/examples/dwarf/dwarf_import/src/lib.rs index 06809428..8aeac658 100644 --- a/rust/examples/dwarf/dwarf_import/src/lib.rs +++ b/rust/examples/dwarf/dwarf_import/src/lib.rs @@ -106,8 +106,7 @@ fn recover_names<R: Reader<Offset = usize>>( } } } else { - namespace_qualifiers - .push((depth, "anonymous_namespace".to_string())); + namespace_qualifiers.push((depth, "anonymous_namespace".to_string())); } } @@ -129,22 +128,24 @@ fn recover_names<R: Reader<Offset = usize>>( depth, match entry.tag() { constants::DW_TAG_class_type => "anonymous_class".to_string(), - constants::DW_TAG_structure_type => "anonymous_structure".to_string(), + constants::DW_TAG_structure_type => { + "anonymous_structure".to_string() + } constants::DW_TAG_union_type => "anonymous_union".to_string(), _ => unreachable!(), - } + }, )) } debug_info_builder_context.set_name( get_uid(&unit, entry), - simplify_str_to_str( - namespace_qualifiers - .iter() - .map(|(_, namespace)| namespace.to_owned()) - .collect::<Vec<String>>() - .join("::"), - ) - .to_string(), + simplify_str_to_str( + namespace_qualifiers + .iter() + .map(|(_, namespace)| namespace.to_owned()) + .collect::<Vec<String>>() + .join("::"), + ) + .to_string(), ); } constants::DW_TAG_typedef @@ -153,17 +154,15 @@ fn recover_names<R: Reader<Offset = usize>>( if let Some(name) = get_name(&unit, entry, debug_info_builder_context) { debug_info_builder_context.set_name( get_uid(&unit, entry), - simplify_str_to_str( - namespace_qualifiers - .iter() - .chain(vec![&(-1, name)].into_iter()) - .map(|(_, namespace)| { - namespace.to_owned() - }) - .collect::<Vec<String>>() - .join("::"), - ) - .to_string(), + simplify_str_to_str( + namespace_qualifiers + .iter() + .chain(vec![&(-1, name)].into_iter()) + .map(|(_, namespace)| namespace.to_owned()) + .collect::<Vec<String>>() + .join("::"), + ) + .to_string(), ); } } diff --git a/rust/examples/dwarf/dwarfdump/src/lib.rs b/rust/examples/dwarf/dwarfdump/src/lib.rs index c062ac63..2cfbbbce 100644 --- a/rust/examples/dwarf/dwarfdump/src/lib.rs +++ b/rust/examples/dwarf/dwarfdump/src/lib.rs @@ -33,7 +33,7 @@ use gimli::{ UnitSectionOffset, }; -static PADDING: [&'static str; 23] = [ +static PADDING: [&str; 23] = [ "", " ", " ", @@ -189,7 +189,7 @@ fn get_info_string<R: Reader>( let value_string = format!("{}", value); attr_line.push(InstructionTextToken::new( &value_string, - InstructionTextTokenContents::Integer(value.into()), + InstructionTextTokenContents::Integer(value), )); } else if let Some(value) = attr.sdata_value() { let value_string = format!("{}", value); |
