From c618591f29b35017802fef7a5209fd3b9dbfac30 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Wed, 23 Aug 2023 18:08:23 -0400 Subject: DWARF Import : Fix crash on recursively defined function type that contains itself as a parameter --- .../examples/dwarf/dwarf_import/src/die_handlers.rs | 21 +++++++++++++++++++++ .../dwarf/dwarf_import/src/dwarfdebuginfo.rs | 4 ++++ 2 files changed, 25 insertions(+) (limited to 'rust/examples') diff --git a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs index 531dfa3e..84ad8a43 100644 --- a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs +++ b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs @@ -304,6 +304,23 @@ pub fn handle_function>( None => Type::void(), }; + // Alias function type in the case that it contains itself + if let Some(name) = debug_info_builder.get_name(dwarf, unit, entry) { + debug_info_builder.add_type( + get_uid(unit, entry), + name.clone(), + Type::named_type_from_type( + name, + &Type::function::( + return_type.as_ref(), + &vec![], + false, + ), + ), + false, + ); + } + let mut parameters: Vec> = vec![]; let mut variable_arguments = false; @@ -327,6 +344,10 @@ pub fn handle_function>( } } + if debug_info_builder.get_name(dwarf, unit, entry).is_some() { + debug_info_builder.remove_type(get_uid(unit, entry)); + } + Some(Type::function( return_type.as_ref(), ¶meters, diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs index d4a2794d..b088d527 100644 --- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -176,6 +176,10 @@ impl DebugInfoBuilder { } } + pub fn remove_type(&mut self, type_uid: TypeUID) { + self.types.remove(&type_uid); + } + // TODO : Non-copy? pub fn get_type(&self, type_uid: TypeUID) -> Option<(CString, Ref)> { self.types -- cgit v1.3.1