From e9b7c410bd50582d2a6ecd49cf02ea8f54ec1f1d Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Tue, 16 Jan 2024 15:34:55 -0500 Subject: DWARF Import : Remove a bunch of CString overhead --- .../dwarf/dwarf_import/src/dwarfdebuginfo.rs | 43 +++++++++++----------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs') diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs index cefc8672..4b0f9350 100644 --- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -29,7 +29,6 @@ use gimli::{DebuggingInformationEntry, Dwarf, Reader, Unit}; use log::{error, warn}; use std::{ collections::{hash_map::Values, HashMap}, - ffi::CString, hash::Hash, }; @@ -41,22 +40,22 @@ pub(crate) type TypeUID = usize; // TODO : Function local variables #[derive(PartialEq, Eq, Hash)] pub(crate) struct FunctionInfoBuilder { - pub(crate) full_name: Option, - pub(crate) raw_name: Option, + pub(crate) full_name: Option, + pub(crate) raw_name: Option, pub(crate) return_type: Option, pub(crate) address: Option, - pub(crate) parameters: Vec>, + pub(crate) parameters: Vec>, pub(crate) platform: Option>, } impl FunctionInfoBuilder { pub(crate) fn update( &mut self, - full_name: Option, - raw_name: Option, + full_name: Option, + raw_name: Option, return_type: Option, address: Option, - parameters: Vec>, + parameters: Vec>, ) { if full_name.is_some() { self.full_name = full_name; @@ -93,7 +92,7 @@ impl FunctionInfoBuilder { // TODO : Don't make this pub...fix the value thing pub(crate) struct DebugType { - name: CString, + name: String, t: Ref, commit: bool, } @@ -101,7 +100,7 @@ pub(crate) struct DebugType { pub(crate) struct DebugInfoBuilderContext> { dwarf: Dwarf, units: Vec>, - names: HashMap, + names: HashMap, default_address_size: usize, pub(crate) total_die_count: usize, } @@ -140,7 +139,7 @@ impl> DebugInfoBuilderContext { self.default_address_size } - pub(crate) fn set_name(&mut self, die_uid: TypeUID, name: CString) { + pub(crate) fn set_name(&mut self, die_uid: TypeUID, name: String) { assert!(self.names.insert(die_uid, name).is_none()); } @@ -148,7 +147,7 @@ impl> DebugInfoBuilderContext { &self, unit: &Unit, entry: &DebuggingInformationEntry, - ) -> Option { + ) -> Option { match resolve_specification(unit, entry, self) { DieReference::UnitAndOffset((entry_unit, entry_offset)) => self .names @@ -168,7 +167,7 @@ impl> DebugInfoBuilderContext { pub(crate) struct DebugInfoBuilder { functions: Vec, types: HashMap, - data_variables: HashMap, TypeUID)>, + data_variables: HashMap, TypeUID)>, } impl DebugInfoBuilder { @@ -183,11 +182,11 @@ impl DebugInfoBuilder { #[allow(clippy::too_many_arguments)] pub(crate) fn insert_function( &mut self, - full_name: Option, - raw_name: Option, + full_name: Option, + raw_name: Option, return_type: Option, address: Option, - parameters: Vec>, + parameters: Vec>, ) { // Raw names should be the primary key, but if they don't exist, use the full name // TODO : Consider further falling back on address/architecture @@ -226,7 +225,7 @@ impl DebugInfoBuilder { pub(crate) fn add_type( &mut self, type_uid: TypeUID, - name: CString, + name: String, t: Ref, commit: bool, ) { @@ -258,7 +257,7 @@ impl DebugInfoBuilder { } // TODO : Non-copy? - pub(crate) fn get_type(&self, type_uid: TypeUID) -> Option<(CString, Ref)> { + pub(crate) fn get_type(&self, type_uid: TypeUID) -> Option<(String, Ref)> { self.types .get(&type_uid) .map(|type_ref_ref| (type_ref_ref.name.clone(), type_ref_ref.t.clone())) @@ -271,7 +270,7 @@ impl DebugInfoBuilder { pub(crate) fn add_data_variable( &mut self, address: u64, - name: Option, + name: Option, type_uid: TypeUID, ) { if let Some((_existing_name, existing_type_uid)) = @@ -317,7 +316,7 @@ impl DebugInfoBuilder { _ => Conf::new(binaryninja::types::Type::void(), 0), }; - let parameters: Vec> = function + let parameters: Vec> = function .parameters .iter() .filter_map(|parameter| match parameter { @@ -363,7 +362,7 @@ impl DebugInfoBuilder { for func in &mut self.functions { // If the function's raw name already exists in the binary... if let Some(raw_name) = &func.raw_name { - if let Ok(symbol) = bv.symbol_by_raw_name(raw_name.as_c_str()) { + if let Ok(symbol) = bv.symbol_by_raw_name(raw_name) { // Link mangled names without addresses to existing symbols in the binary if func.address.is_none() && func.raw_name.is_some() { // DWARF doesn't contain GOT info, so remove any entries there...they will be wrong (relying on Binja's mechanisms for the GOT is good ) @@ -373,7 +372,7 @@ impl DebugInfoBuilder { } if let Some(full_name) = &func.full_name { - let func_full_name = full_name.to_str().unwrap(); + let func_full_name = full_name; let symbol_full_name = symbol.full_name(); // If our name has fewer namespaces than the existing name, assume we lost the namespace info @@ -381,7 +380,7 @@ impl DebugInfoBuilder { < simplify_str_to_fqn(symbol_full_name.clone(), true).len() { func.full_name = - Some(CString::new(symbol_full_name.to_string()).unwrap()); + Some(symbol_full_name.to_string()); } } } -- cgit v1.3.1