summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2024-07-05 15:13:23 -0400
committerJosh Ferrell <josh@vector35.com>2024-07-05 15:26:40 -0400
commitebef0e0202e9d58907963d632549c2ca9bfa8ea5 (patch)
tree63b54a9695981482c9217fe5ffff103c0ade5238
parent52dd0afc0dce16e454a37d73397359351d3f2064 (diff)
Misc small dwarf perf improvements
-rw-r--r--rust/examples/dwarf/dwarf_import/src/die_handlers.rs4
-rw-r--r--rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs2
-rw-r--r--rust/examples/dwarf/dwarf_import/src/functions.rs59
-rw-r--r--rust/examples/dwarf/dwarf_import/src/types.rs23
4 files changed, 46 insertions, 42 deletions
diff --git a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs
index e6530dd2..be77a414 100644
--- a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs
+++ b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs
@@ -295,9 +295,9 @@ pub(crate) fn handle_function<R: Reader<Offset = usize>>(
if let Some(name) = debug_info_builder_context.get_name(unit, entry) {
debug_info_builder.add_type(
get_uid(unit, entry),
- name.clone(),
+ &name,
Type::named_type_from_type(
- name,
+ &name,
&Type::function::<&binaryninja::types::Type>(return_type.as_ref(), &[], false),
),
false,
diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
index 13030aa8..0e0e8f53 100644
--- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
+++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
@@ -303,7 +303,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,
diff --git a/rust/examples/dwarf/dwarf_import/src/functions.rs b/rust/examples/dwarf/dwarf_import/src/functions.rs
index fa1755fa..f418a47f 100644
--- a/rust/examples/dwarf/dwarf_import/src/functions.rs
+++ b/rust/examples/dwarf/dwarf_import/src/functions.rs
@@ -30,41 +30,44 @@ fn get_parameters<R: Reader<Offset = usize>>(
debug_info_builder: &mut DebugInfoBuilder,
) -> (Vec<Option<(String, TypeUID)>>, bool) {
if !entry.has_children() {
- (vec![], false)
- } else {
- // We make a new tree from the current entry to iterate over its children
- let mut sub_die_tree = unit.entries_tree(Some(entry.offset())).unwrap();
- let root = sub_die_tree.root().unwrap();
+ return (vec![], false);
+ }
+
+ // We make a new tree from the current entry to iterate over its children
+ let mut sub_die_tree = unit.entries_tree(Some(entry.offset())).unwrap();
+ let root = sub_die_tree.root().unwrap();
+
+ let mut variable_arguments = false;
+ let mut result = vec![];
+ let mut children = root.children();
+ while let Some(child) = children.next().unwrap() {
+ match child.entry().tag() {
+ constants::DW_TAG_formal_parameter => {
+ //TODO: if the param type is a typedef to an anonymous struct (typedef struct {...} foo) then this is reoslved to an anonymous struct instead of foo
+ // We should still recurse to make sure we load all types this param type depends on, but
+ let name = debug_info_builder_context.get_name(unit, child.entry());
- let mut variable_arguments = false;
- let mut result = vec![];
- let mut children = root.children();
- while let Some(child) = children.next().unwrap() {
- match child.entry().tag() {
- constants::DW_TAG_formal_parameter => {
- let name = debug_info_builder_context.get_name(unit, child.entry());
- let type_ = get_type(
- unit,
- child.entry(),
- debug_info_builder_context,
- debug_info_builder,
- );
- if let Some(parameter_name) = name {
- if let Some(parameter_type) = type_ {
- result.push(Some((parameter_name, parameter_type)));
- } else {
- result.push(Some((parameter_name, 0)))
- }
+ let type_ = get_type(
+ unit,
+ child.entry(),
+ debug_info_builder_context,
+ debug_info_builder,
+ );
+ if let Some(parameter_name) = name {
+ if let Some(parameter_type) = type_ {
+ result.push(Some((parameter_name, parameter_type)));
} else {
- result.push(None)
+ result.push(Some((parameter_name, 0)))
}
+ } else {
+ result.push(None)
}
- constants::DW_TAG_unspecified_parameters => variable_arguments = true,
- _ => (),
}
+ constants::DW_TAG_unspecified_parameters => variable_arguments = true,
+ _ => (),
}
- (result, variable_arguments)
}
+ (result, variable_arguments)
}
pub(crate) fn parse_function_entry<R: Reader<Offset = usize>>(
diff --git a/rust/examples/dwarf/dwarf_import/src/types.rs b/rust/examples/dwarf/dwarf_import/src/types.rs
index ccc44f4e..e3b53d99 100644
--- a/rust/examples/dwarf/dwarf_import/src/types.rs
+++ b/rust/examples/dwarf/dwarf_import/src/types.rs
@@ -129,7 +129,7 @@ fn do_structure_parse<R: Reader<Offset = usize>>(
if let Some(full_name) = &full_name {
debug_info_builder.add_type(
get_uid(unit, entry),
- full_name.clone(),
+ &full_name,
Type::named_type_from_type(
full_name.clone(),
&Type::structure(&structure_builder.finalize()),
@@ -143,8 +143,8 @@ fn do_structure_parse<R: Reader<Offset = usize>>(
let full_name = format!("anonymous_structure_{:x}", get_uid(unit, entry));
debug_info_builder.add_type(
get_uid(unit, entry),
- full_name.clone(),
- Type::named_type_from_type(full_name, &Type::structure(&structure_builder.finalize())),
+ &full_name,
+ Type::named_type_from_type(&full_name, &Type::structure(&structure_builder.finalize())),
false,
);
}
@@ -209,14 +209,14 @@ fn do_structure_parse<R: Reader<Offset = usize>>(
if let Some(full_name) = full_name {
debug_info_builder.add_type(
get_uid(unit, entry) + 1, // TODO : This is super broke (uid + 1 is not guaranteed to be unique)
- full_name,
+ &full_name,
finalized_structure,
true,
);
} else {
debug_info_builder.add_type(
get_uid(unit, entry),
- format!("{}", finalized_structure),
+ &format!("{}", finalized_structure),
finalized_structure,
false, // Don't commit anonymous unions (because I think it'll break things)
);
@@ -232,8 +232,9 @@ pub(crate) fn get_type<R: Reader<Offset = usize>>(
debug_info_builder: &mut DebugInfoBuilder,
) -> Option<TypeUID> {
// If this node (and thus all its referenced nodes) has already been processed, just return the offset
- if debug_info_builder.contains_type(get_uid(unit, entry)) {
- return Some(get_uid(unit, entry));
+ let entry_uid = get_uid(unit, entry);
+ if debug_info_builder.contains_type(entry_uid) {
+ return Some(entry_uid);
}
// Don't parse types that are just declarations and not definitions
@@ -284,8 +285,8 @@ pub(crate) fn get_type<R: Reader<Offset = usize>>(
// If this node (and thus all its referenced nodes) has already been processed, just return the offset
// This check is not redundant because this type might have been processes in the recursive calls above
- if debug_info_builder.contains_type(get_uid(unit, entry)) {
- return Some(get_uid(unit, entry));
+ if debug_info_builder.contains_type(entry_uid) {
+ return Some(entry_uid);
}
// Collect the required information to create a type and add it to the type map. Also, add the dependencies of this type to the type's typeinfo
@@ -405,8 +406,8 @@ pub(crate) fn get_type<R: Reader<Offset = usize>>(
format!("{}", type_def)
});
- debug_info_builder.add_type(get_uid(unit, entry), name, type_def, commit);
- Some(get_uid(unit, entry))
+ debug_info_builder.add_type(entry_uid, &name, type_def, commit);
+ Some(entry_uid)
} else {
None
}