diff options
| author | KyleMiles <krm504@nyu.edu> | 2023-08-23 12:53:23 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-08-25 11:18:38 -0400 |
| commit | c0c145ff7286d99edbd4b367bca4e228cae1a3ac (patch) | |
| tree | 5268b4c86520eb24bc4e0bae732df2173fc7f7b7 /rust/examples | |
| parent | 7849cda3f9be3ba7da2abb0e7f4d9f201b43fa50 (diff) | |
DWARF Import : More optimizations
Diffstat (limited to 'rust/examples')
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/die_handlers.rs | 14 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/functions.rs | 2 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/lib.rs | 47 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/types.rs | 28 |
4 files changed, 49 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 39e25669..531dfa3e 100644 --- a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs +++ b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs @@ -29,6 +29,7 @@ pub fn handle_base_type<R: Reader<Offset = usize>>( dwarf: &Dwarf<R>, unit: &Unit<R>, entry: &DebuggingInformationEntry<R>, + debug_info_builder: &mut DebugInfoBuilder, ) -> Option<Ref<Type>> { // All base types have: // DW_AT_name @@ -40,7 +41,9 @@ pub fn handle_base_type<R: Reader<Offset = usize>>( // * = Optional // TODO : By spec base types need to have a name, what if it's spec non-conforming? - let name = get_name(dwarf, unit, entry).expect("DW_TAG_base does not have name attribute"); + let name = debug_info_builder + .get_name(dwarf, unit, entry) + .expect("DW_TAG_base does not have name attribute"); let size = get_size_as_usize(entry).expect("DW_TAG_base does not have size attribute"); match entry.attr_value(constants::DW_AT_encoding) { Ok(Some(Encoding(encoding))) => { @@ -76,6 +79,7 @@ pub fn handle_enum<R: Reader<Offset = usize>>( dwarf: &Dwarf<R>, unit: &Unit<R>, entry: &DebuggingInformationEntry<R>, + debug_info_builder: &mut DebugInfoBuilder, ) -> Option<Ref<Type>> { // All base types have: // DW_AT_byte_size @@ -110,9 +114,9 @@ pub fn handle_enum<R: Reader<Offset = usize>>( let mut children = tree.root().unwrap().children(); while let Ok(Some(child)) = children.next() { if child.entry().tag() == constants::DW_TAG_enumerator { - let name = - get_name(dwarf, unit, child.entry()) // TODO : Might need to recover the full name here - .expect("DW_TAG_enumeration_type does not have name attribute"); + let name = debug_info_builder + .get_name(dwarf, unit, child.entry()) + .expect("DW_TAG_enumeration_type does not have name attribute"); let value = get_attr_as_u64( &child .entry() @@ -312,7 +316,7 @@ pub fn handle_function<R: Reader<Offset = usize>>( if let (Some(child_uid), Some(name)) = { ( get_type(dwarf, unit, child.entry(), debug_info_builder), - get_name(dwarf, unit, child.entry()), + debug_info_builder.get_name(dwarf, unit, child.entry()), ) } { let child_type = debug_info_builder.get_type(child_uid).unwrap().1; diff --git a/rust/examples/dwarf/dwarf_import/src/functions.rs b/rust/examples/dwarf/dwarf_import/src/functions.rs index 652bb8a5..127ec6f4 100644 --- a/rust/examples/dwarf/dwarf_import/src/functions.rs +++ b/rust/examples/dwarf/dwarf_import/src/functions.rs @@ -39,7 +39,7 @@ fn get_parameters<R: Reader<Offset = usize>>( while let Some(child) = children.next().unwrap() { match child.entry().tag() { constants::DW_TAG_formal_parameter => { - let name = get_name(dwarf, unit, child.entry()); + let name = debug_info_builder.get_name(dwarf, unit, child.entry()); let type_ = get_type(dwarf, unit, child.entry(), debug_info_builder); if let Some(parameter_name) = name { if let Some(parameter_type) = type_ { diff --git a/rust/examples/dwarf/dwarf_import/src/lib.rs b/rust/examples/dwarf/dwarf_import/src/lib.rs index cc87e1c6..6ec2e5ad 100644 --- a/rust/examples/dwarf/dwarf_import/src/lib.rs +++ b/rust/examples/dwarf/dwarf_import/src/lib.rs @@ -111,34 +111,22 @@ fn recover_names<R: Reader<Offset = usize>>( resolve_namespace_name(dwarf, &unit, entry, &mut namespace_qualifiers, depth); } - constants::DW_TAG_class_type => { + constants::DW_TAG_class_type + | constants::DW_TAG_structure_type + | constants::DW_TAG_union_type => { if let Some(name) = get_name(dwarf, &unit, entry) { namespace_qualifiers.push((depth, name)) } else { - namespace_qualifiers.push((depth, CString::new("anonymous_class").unwrap())) - } - - debug_info_builder.set_name( - get_uid(&unit, entry), - CString::new( - simplify_str_to_str( - namespace_qualifiers - .iter() - .map(|(_, namespace)| namespace.to_string_lossy().to_string()) - .collect::<Vec<String>>() - .join("::"), - ) - .as_str(), - ) - .unwrap(), - ); - } - constants::DW_TAG_structure_type => { - if let Some(name) = get_name(dwarf, &unit, entry) { - namespace_qualifiers.push((depth, name)) - } else { - namespace_qualifiers - .push((depth, CString::new("anonymous_structure").unwrap())) + namespace_qualifiers.push(( + depth, + CString::new(match entry.tag() { + constants::DW_TAG_class_type => "anonymous_class", + constants::DW_TAG_structure_type => "anonymous_structure", + constants::DW_TAG_union_type => "anonymous_union", + _ => unreachable!(), + }) + .unwrap(), + )) } debug_info_builder.set_name( get_uid(&unit, entry), @@ -155,7 +143,9 @@ fn recover_names<R: Reader<Offset = usize>>( .unwrap(), ); } - _ => { + constants::DW_TAG_typedef + | constants::DW_TAG_subprogram + | constants::DW_TAG_enumeration_type => { if let Some(name) = get_name(dwarf, &unit, entry) { debug_info_builder.set_name( get_uid(&unit, entry), @@ -176,6 +166,11 @@ fn recover_names<R: Reader<Offset = usize>>( ); } } + _ => { + if let Some(name) = get_name(dwarf, &unit, entry) { + debug_info_builder.set_name(get_uid(&unit, entry), name); + } + } } } } diff --git a/rust/examples/dwarf/dwarf_import/src/types.rs b/rust/examples/dwarf/dwarf_import/src/types.rs index d8edf5ab..0fef5fae 100644 --- a/rust/examples/dwarf/dwarf_import/src/types.rs +++ b/rust/examples/dwarf/dwarf_import/src/types.rs @@ -126,14 +126,17 @@ fn do_structure_parse<R: Reader<Offset = usize>>( if child.entry().tag() == constants::DW_TAG_member { if let Some(child_type_id) = get_type(dwarf, unit, child.entry(), debug_info_builder) { if let Some((_, child_type)) = debug_info_builder.get_type(child_type_id) { - if let Some(child_name) = get_name(dwarf, unit, child.entry()).map_or( - if child_type.type_class() == TypeClass::StructureTypeClass { - Some(CString::new("").unwrap()) - } else { - None - }, - Some, - ) { + if let Some(child_name) = debug_info_builder + .get_name(dwarf, unit, child.entry()) + .map_or( + if child_type.type_class() == TypeClass::StructureTypeClass { + Some(CString::new("").unwrap()) + } else { + None + }, + Some, + ) + { // TODO : support DW_AT_data_bit_offset for offset as well if let Ok(Some(raw_struct_offset)) = child.entry().attr(constants::DW_AT_data_member_location) @@ -269,7 +272,10 @@ pub(crate) fn get_type<R: Reader<Offset = usize>>( // 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 // Create the type, make a TypeInfo for it, and add it to the debug info let (type_def, mut commit): (Option<Ref<Type>>, bool) = match entry.tag() { - constants::DW_TAG_base_type => (handle_base_type(dwarf, unit, entry), false), + constants::DW_TAG_base_type => ( + handle_base_type(dwarf, unit, entry, debug_info_builder), + false, + ), constants::DW_TAG_structure_type => { return do_structure_parse( @@ -300,7 +306,9 @@ pub(crate) fn get_type<R: Reader<Offset = usize>>( } // Enum - constants::DW_TAG_enumeration_type => (handle_enum(dwarf, unit, entry), true), + constants::DW_TAG_enumeration_type => { + (handle_enum(dwarf, unit, entry, debug_info_builder), true) + } // Basic types constants::DW_TAG_typedef => handle_typedef( |
