From 98f9bae4c7d2dc636ab0a7fe61741e7f9fccba70 Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Mon, 20 Oct 2025 12:01:27 -0400 Subject: [DWARF] Greatly improve handling of typedefs --- plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs | 35 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs') diff --git a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs index 94f370a1..eda641ca 100644 --- a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -107,6 +107,7 @@ pub(crate) struct DebugType { pub name: String, pub ty: Ref, pub commit: bool, + pub target_type_uid: Option, } impl DebugType { @@ -363,17 +364,26 @@ impl DebugInfoBuilder { self.types.values() } - pub(crate) fn add_type(&mut self, type_uid: TypeUID, name: String, t: Ref, commit: bool) { + pub(crate) fn add_type( + &mut self, + type_uid: TypeUID, + name: String, + t: Ref, + commit: bool, + target_type_uid: Option, + ) { if let Some(DebugType { name: existing_name, ty: existing_type, commit: _, + target_type_uid: _, }) = self.types.insert( type_uid, DebugType { name: name.clone(), ty: t.clone(), commit, + target_type_uid, }, ) { if existing_type != t && commit { @@ -608,7 +618,28 @@ impl DebugInfoBuilder { }; // TODO : Components - debug_info.add_type(&debug_type_name, &debug_type.ty, &[]); + // If it's a typedef resolve one layer down since we'd technically be defining it as a typedef to itself otherwise + if let Some(ntr) = debug_type.get_type().get_named_type_reference() { + if let Some(target_uid) = debug_type.target_type_uid { + if let Some(target_type) = self.get_type(target_uid) { + debug_info.add_type(&debug_type_name, &target_type.get_type(), &[]); + } else { + error!( + "Failed to find typedef {} target for uid {}", + debug_type_name, + ntr.name() + ); + } + } else { + error!( + "Failed to find typedef {} target uid for {}", + debug_type_name, + ntr.name() + ); + } + } else { + debug_info.add_type(&debug_type_name, &debug_type.ty, &[]); + } type_uids_by_name.insert(debug_type_name, *debug_type_uid); } } -- cgit v1.3.1