From f4f6e9ad49d6992712815bc7b2e94c8333f33523 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 25 Sep 2019 21:07:56 +0100 Subject: [PATCH] Fix -debug crash on windows caused by missing debug info for files. --- core/os/os_windows.odin | 2 +- src/ir.cpp | 13 ++++++++++++- src/ir_print.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/os/os_windows.odin b/core/os/os_windows.odin index 9618f83be..e45cf9f5f 100644 --- a/core/os/os_windows.odin +++ b/core/os/os_windows.odin @@ -322,4 +322,4 @@ is_windows_8_1 :: proc() -> bool { is_windows_10 :: proc() -> bool { osvi := get_windows_version_ansi(); return (osvi.major_version == 10 && osvi.minor_version == 0); -} \ No newline at end of file +} diff --git a/src/ir.cpp b/src/ir.cpp index 1c326359b..758267c24 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -10028,7 +10028,11 @@ void ir_init_module(irModule *m, Checker *c) { { irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompileUnit); - di->CompileUnit.file = m->info->files.entries[0].value; // Zeroth is the init file + + GB_ASSERT(m->info->files.entries.count > 0); + AstFile *file = m->info->files.entries[0].value; + + di->CompileUnit.file = file; // Zeroth is the init file di->CompileUnit.producer = str_lit("odin"); map_set(&m->debug_info, hash_pointer(m), di); @@ -10047,6 +10051,13 @@ void ir_init_module(irModule *m, Checker *c) { array_init(&m->debug_location_stack, heap_allocator()); // TODO(lachsinc): ir_allocator() ?? } + + { + for_array(i, m->info->files.entries) { + AstFile *file = m->info->files.entries[i].value; + ir_add_debug_info_file(m, file); + } + } } void ir_destroy_module(irModule *m) { diff --git a/src/ir_print.cpp b/src/ir_print.cpp index 30ad914a9..9414a2338 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -2450,11 +2450,13 @@ void print_llvm_ir(irGen *ir) { for_array(di_index, m->debug_info.entries) { irDebugInfo *di = m->debug_info.entries[di_index].value; + GB_ASSERT_MSG(di != nullptr, "Invalid irDebugInfo"); ir_fprintf(f, "!%d = ", di->id); - switch (di->kind) { case irDebugInfo_CompileUnit: { - irDebugInfo *file = *map_get(&m->debug_info, hash_pointer(di->CompileUnit.file)); + irDebugInfo **found = map_get(&m->debug_info, hash_pointer(di->CompileUnit.file)); + GB_ASSERT_MSG(found != nullptr, "Missing debug info for: %.*s\n", LIT(di->CompileUnit.file->fullpath)); + irDebugInfo *file = *found; ir_fprintf(f, "distinct !DICompileUnit(" "language: DW_LANG_C_plus_plus" // Is this good enough?