From 664b41af65d3c9bbc8e09ffcaa91d404fe87d7a0 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 4 Jan 2017 01:56:21 -0500 Subject: [PATCH] fix debug information for function pointers in structs --- src/analyze.cpp | 14 +++++++++++++- src/ir.cpp | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 30c151db5..155b83d99 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1349,6 +1349,18 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { TypeTableEntry *field_type = type_struct_field->type_entry; + // if the field is a function, actually the debug info should be a pointer. + ZigLLVMDIType *field_di_type; + if (field_type->id == TypeTableEntryIdFn) { + TypeTableEntry *field_ptr_type = get_pointer_to_type(g, field_type, true); + uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref); + uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref); + field_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, field_type->di_type, + debug_size_in_bits, debug_align_in_bits, buf_ptr(&field_ptr_type->name)); + } else { + field_di_type = field_type->di_type; + } + assert(field_type->type_ref); assert(struct_type->type_ref); assert(struct_type->data.structure.complete); @@ -1362,7 +1374,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { debug_size_in_bits, debug_align_in_bits, debug_offset_in_bits, - 0, field_type->di_type); + 0, field_di_type); assert(di_element_types[gen_field_index]); } diff --git a/src/ir.cpp b/src/ir.cpp index 5a5dc5c14..86cd3f5d8 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4925,7 +4925,9 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, name = buf_alloc(); buf_append_buf(name, &fn_entry->symbol_name); buf_appendf(name, "("); - // TODO render args + // TODO render args. note that fn_type_id is likely not complete + // at this time. + // probably have to render them from the fn scope buf_appendf(name, ")"); } else { name = buf_sprintf("(anonymous %s at %s:%zu:%zu)", container_string(kind),