Skip to content

Commit efcc614

Browse files
authored
feat: add semantic typedef wrappers for all pointer types in debug info (#1538)
1 parent 51efb1e commit efcc614

File tree

4 files changed

+774
-750
lines changed

4 files changed

+774
-750
lines changed

src/codegen/debug.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,30 @@ impl<'ink> DebugBuilder<'ink> {
445445
inkwell::AddressSpace::from(ADDRESS_SPACE_GLOBAL),
446446
);
447447

448-
// Handle auto-dereferencing pointers by creating a typedef if needed. This ensures
449-
// that the DWARF information accurately reflects the intended usage (deref semantics) of the pointer type.
450-
let ty = if let DataTypeInformation::Pointer { auto_deref: Some(_), .. } =
451-
index.get_type(name).map(|it| it.get_type_information())?
452-
{
453-
let file = self.compile_unit.get_file();
454-
let typedef_name = format!("__AUTO_DEREF__{name}");
455-
self.debug_info.create_typedef(
456-
pointer_type.as_type(),
457-
&typedef_name,
458-
file,
459-
0, // Line 0 for built-in types
460-
file.as_debug_info_scope(),
461-
align_bits,
462-
)
463-
} else {
464-
pointer_type
448+
// For pointer types, we create a typedef to represent the pointer type in DWARF.
449+
// This allows other tools to distinguish between different kinds of pointer semantics (e.g., reference vs. auto-deref, type-safety, ...)
450+
// XXX: This is a workaround - gdb will show the mangled type name in the debugger, which is not ideal
451+
let typedef_name = match index.get_type(name).map(|it| it.get_type_information())? {
452+
DataTypeInformation::Pointer { auto_deref: Some(auto_deref), .. } => match auto_deref {
453+
plc_ast::ast::AutoDerefType::Reference => format!("__REFERENCE_TO__{name}"),
454+
_ => format!("__AUTO_DEREF__{name}"),
455+
},
456+
DataTypeInformation::Pointer { type_safe, .. } => {
457+
type_safe.then_some(format!("__REF_TO__{name}")).unwrap_or(format!("__POINTER_TO__{name}"))
458+
}
459+
_ => unreachable!("Only pointer types reach this"),
465460
};
466461

462+
let file = self.compile_unit.get_file();
463+
let ty = self.debug_info.create_typedef(
464+
pointer_type.as_type(),
465+
&typedef_name,
466+
file,
467+
0, // Line 0 for built-in types
468+
file.as_debug_info_scope(),
469+
align_bits,
470+
);
471+
467472
self.register_concrete_type(name, DebugType::Derived(ty));
468473

469474
Ok(())

0 commit comments

Comments
 (0)