From 2aae4cfd461860bd10dcb922f867c98212a11449 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 8 Jan 2025 18:46:25 +0100 Subject: fix #no_nil in debug info Fixes #4664 --- src/llvm_backend_debug.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/llvm_backend_debug.cpp') diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 464f7065c..3951fc977 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -415,6 +415,7 @@ gb_internal LLVMMetadataRef lb_debug_union(lbModule *m, Type *type, String name, LLVMMetadataRef member_scope = lb_get_llvm_metadata(m, bt->Union.scope); unsigned element_count = cast(unsigned)bt->Union.variants.count; if (index_offset > 0) { + GB_ASSERT(index_offset == 1); element_count += 1; } @@ -437,13 +438,11 @@ gb_internal LLVMMetadataRef lb_debug_union(lbModule *m, Type *type, String name, for_array(j, bt->Union.variants) { Type *variant = bt->Union.variants[j]; - unsigned field_index = cast(unsigned)(index_offset+j); - - char name[16] = {}; - gb_snprintf(name, gb_size_of(name), "v%u", field_index); + char name[32] = {}; + gb_snprintf(name, gb_size_of(name), "v%td", j); isize name_len = gb_strlen(name); - elements[field_index] = LLVMDIBuilderCreateMemberType( + elements[index_offset+j] = LLVMDIBuilderCreateMemberType( m->debug_builder, member_scope, name, name_len, file, line, -- cgit v1.2.3 From 7185a93a8631060958565d6e3fba03b4b6eeccce Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 8 Jan 2025 20:22:59 +0100 Subject: actually fix #no_nil debug info Fixes #4664 --- src/llvm_backend_debug.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/llvm_backend_debug.cpp') diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 3951fc977..6740cd1a2 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -438,8 +438,13 @@ gb_internal LLVMMetadataRef lb_debug_union(lbModule *m, Type *type, String name, for_array(j, bt->Union.variants) { Type *variant = bt->Union.variants[j]; + ptrdiff_t variant_index = j; + if (bt->Union.kind == UnionType_no_nil) { + variant_index += 1; + } + char name[32] = {}; - gb_snprintf(name, gb_size_of(name), "v%td", j); + gb_snprintf(name, gb_size_of(name), "v%td", variant_index); isize name_len = gb_strlen(name); elements[index_offset+j] = LLVMDIBuilderCreateMemberType( -- cgit v1.2.3 From b3c359557e7c3a1a298ac5b46af122415e43bf77 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 8 Jan 2025 21:24:22 +0100 Subject: `#no_nil` third time's the charm --- src/llvm_backend_debug.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/llvm_backend_debug.cpp') diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 6740cd1a2..2252c4a31 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -439,7 +439,7 @@ gb_internal LLVMMetadataRef lb_debug_union(lbModule *m, Type *type, String name, Type *variant = bt->Union.variants[j]; ptrdiff_t variant_index = j; - if (bt->Union.kind == UnionType_no_nil) { + if (bt->Union.kind != UnionType_no_nil) { variant_index += 1; } -- cgit v1.2.3 From 2620721128b2835826faa5d224bf9373a92b1998 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 8 Jan 2025 21:45:59 +0100 Subject: '#no_nil' I am actually disappointed in myself --- src/llvm_backend_debug.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/llvm_backend_debug.cpp') diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 2252c4a31..fbb25960a 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -408,8 +408,12 @@ gb_internal LLVMMetadataRef lb_debug_union(lbModule *m, Type *type, String name, lb_set_llvm_metadata(m, type, temp_forward_decl); isize index_offset = 1; + isize variant_offset = 1; if (is_type_union_maybe_pointer(bt)) { index_offset = 0; + variant_offset = 0; + } else if (bt->Union.kind == UnionType_no_nil) { + variant_offset = 0; } LLVMMetadataRef member_scope = lb_get_llvm_metadata(m, bt->Union.scope); @@ -438,13 +442,8 @@ gb_internal LLVMMetadataRef lb_debug_union(lbModule *m, Type *type, String name, for_array(j, bt->Union.variants) { Type *variant = bt->Union.variants[j]; - ptrdiff_t variant_index = j; - if (bt->Union.kind != UnionType_no_nil) { - variant_index += 1; - } - char name[32] = {}; - gb_snprintf(name, gb_size_of(name), "v%td", variant_index); + gb_snprintf(name, gb_size_of(name), "v%td", variant_offset+j); isize name_len = gb_strlen(name); elements[index_offset+j] = LLVMDIBuilderCreateMemberType( -- cgit v1.2.3 From 90a973ccf6b3b42d8808e901c8a839183614f54d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 20 Feb 2025 10:27:59 +0000 Subject: Make debug symbols use the new name canonicalization rules --- src/llvm_backend_debug.cpp | 29 +++++++++++++---------------- src/name_canonicalization.cpp | 22 ++++++++++++++++++---- 2 files changed, 31 insertions(+), 20 deletions(-) (limited to 'src/llvm_backend_debug.cpp') diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index fbb25960a..067004bc1 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -843,7 +843,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { 8*cast(unsigned)type_align_of(type), lb_debug_type(m, type->EnumeratedArray.elem), subscripts, gb_count_of(subscripts)); - gbString name = type_to_string(type, temporary_allocator()); + gbString name = temp_canonical_string(type); return LLVMDIBuilderCreateTypedef(m->debug_builder, array_type, name, gb_string_length(name), nullptr, 0, nullptr, cast(u32)(8*type_align_of(type))); } @@ -852,16 +852,16 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { Type *bt = base_type(type->Map.debug_metadata_type); GB_ASSERT(bt->kind == Type_Struct); - return lb_debug_struct(m, type, bt, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); + return lb_debug_struct(m, type, bt, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); } - case Type_Struct: return lb_debug_struct( m, type, type, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); - case Type_Slice: return lb_debug_slice( m, type, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); - case Type_DynamicArray: return lb_debug_dynamic_array(m, type, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); - case Type_Union: return lb_debug_union( m, type, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); - case Type_BitSet: return lb_debug_bitset( m, type, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); - case Type_Enum: return lb_debug_enum( m, type, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); - case Type_BitField: return lb_debug_bitfield( m, type, make_string_c(type_to_string(type, temporary_allocator())), nullptr, nullptr, 0); + case Type_Struct: return lb_debug_struct( m, type, type, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); + case Type_Slice: return lb_debug_slice( m, type, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); + case Type_DynamicArray: return lb_debug_dynamic_array(m, type, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); + case Type_Union: return lb_debug_union( m, type, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); + case Type_BitSet: return lb_debug_bitset( m, type, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); + case Type_Enum: return lb_debug_enum( m, type, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); + case Type_BitField: return lb_debug_bitfield( m, type, type_to_canonical_string(temporary_allocator(), type), nullptr, nullptr, 0); case Type_Tuple: if (type->Tuple.variables.count == 1) { @@ -904,7 +904,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { { LLVMMetadataRef proc_underlying_type = lb_debug_type_internal_proc(m, type); LLVMMetadataRef pointer_type = LLVMDIBuilderCreatePointerType(m->debug_builder, proc_underlying_type, ptr_bits, ptr_bits, 0, nullptr, 0); - gbString name = type_to_string(type, temporary_allocator()); + gbString name = temp_canonical_string(type); return LLVMDIBuilderCreateTypedef(m->debug_builder, pointer_type, name, gb_string_length(name), nullptr, 0, nullptr, cast(u32)(8*type_align_of(type))); } break; @@ -987,10 +987,7 @@ gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) { line = cast(unsigned)e->token.pos.line; } - String name = type->Named.name; - if (type->Named.type_name && type->Named.type_name->pkg && type->Named.type_name->pkg->name.len != 0) { - name = concatenate3_strings(temporary_allocator(), type->Named.type_name->pkg->name, str_lit("."), type->Named.name); - } + String name = type_to_canonical_string(temporary_allocator(), type); Type *bt = base_type(type->Named.base); @@ -1187,8 +1184,8 @@ gb_internal void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx gb_internal String debug_info_mangle_constant_name(Entity *e, gbAllocator const &allocator, bool *did_allocate_) { String name = e->token.string; if (e->pkg && e->pkg->name.len > 0) { - // NOTE(bill): C++ NONSENSE FOR DEBUG SHITE! - name = concatenate3_strings(allocator, e->pkg->name, str_lit("::"), name); + gbString s = string_canonical_entity_name(allocator, e); + name = make_string(cast(u8 const *)s, gb_string_length(s)); if (did_allocate_) *did_allocate_ = true; } return name; diff --git a/src/name_canonicalization.cpp b/src/name_canonicalization.cpp index 043317ef0..548deb2cf 100644 --- a/src/name_canonicalization.cpp +++ b/src/name_canonicalization.cpp @@ -421,6 +421,8 @@ gb_internal void write_canonical_entity_name(TypeWriter *w, Entity *e) { return; } + bool write_scope_index_suffix = false; + if (e->scope->flags & (ScopeFlag_Builtin)) { goto write_base_name; } else if ((e->scope->flags & (ScopeFlag_File | ScopeFlag_Pkg)) == 0 || @@ -438,7 +440,7 @@ gb_internal void write_canonical_entity_name(TypeWriter *w, Entity *e) { Entity *parent = s->decl_info->entity; write_canonical_parent_prefix(w, parent); if (e->scope->index > 0) { - type_writer_append_fmt(w, CANONICAL_TYPE_SEPARATOR "[%d]", e->scope->index); + write_scope_index_suffix = true; } goto write_base_name; @@ -491,8 +493,11 @@ write_base_name: type_writer_append(w, e->token.string.text, e->token.string.len); } } - return; + break; + case Entity_Constant: + // For debug symbols only + /*fallthrough*/ case Entity_Procedure: case Entity_Variable: type_writer_append(w, e->token.string.text, e->token.string.len); @@ -500,12 +505,18 @@ write_base_name: type_writer_appendc(w, CANONICAL_TYPE_SEPARATOR); write_type_to_canonical_string(w, e->type); } - return; + break; default: GB_PANIC("TODO(bill): entity kind %d", e->kind); break; } + + if (write_scope_index_suffix) { + GB_ASSERT(e != nullptr && e->scope != nullptr); + type_writer_append_fmt(w, "[%d]", e->scope->index); + } + return; } @@ -661,7 +672,10 @@ gb_internal void write_type_to_canonical_string(TypeWriter *w, Type *type) { type_writer_append(w, f->token.string.text, f->token.string.len); type_writer_appendc(w, CANONICAL_TYPE_SEPARATOR); write_type_to_canonical_string(w, f->type); - String tag = type->Struct.tags[i]; + String tag = {}; + if (type->Struct.tags != nullptr) { + tag = type->Struct.tags[i]; + } if (tag.len != 0) { String s = quote_to_ascii(heap_allocator(), tag); type_writer_append(w, s.text, s.len); -- cgit v1.2.3