From 9fdcc88cab256600264e0e99449c16e2e085389d Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Thu, 24 Sep 2026 11:37:24 -0600 Subject: [PATCH] rdi_from_dwarf: correctly use unit_dir only when line table directories are relative; correctly use unit compilation unit name as first file in pre-dwarf-5 --- src/dwarf/dwarf_parse.c | 5 ++++- src/rdi_from_dwarf/rdi_from_dwarf.c | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/dwarf/dwarf_parse.c b/src/dwarf/dwarf_parse.c index 6b3f3fe5..a7845622 100644 --- a/src/dwarf/dwarf_parse.c +++ b/src/dwarf/dwarf_parse.c @@ -676,6 +676,7 @@ internal void dw2_parse_ctx_equip_unit_root_tag(DW2_ParseCtx *ctx_out, DW2_Tag *tag, DW2_OffsetTableSet *offset_tables) { // rjf: unpack attributes + DW2_Attrib *name_attrib = &dw2_attrib_nil; DW2_Attrib *low_pc_attrib = &dw2_attrib_nil; DW2_Attrib *lang_attrib = &dw2_attrib_nil; DW2_Attrib *rnglists_base_off_attrib = &dw2_attrib_nil; @@ -689,6 +690,7 @@ dw2_parse_ctx_equip_unit_root_tag(DW2_ParseCtx *ctx_out, DW2_Tag *tag, DW2_Offse { default:{}break; #define Case(name, name_upper) case DW_AttribKind_##name_upper:{name##_attrib = &n->v;}break + Case(name, Name); Case(low_pc, LowPc); Case(lang, Language); Case(rnglists_base_off, RngListsBase); @@ -704,6 +706,7 @@ dw2_parse_ctx_equip_unit_root_tag(DW2_ParseCtx *ctx_out, DW2_Tag *tag, DW2_Offse ctx_out->unit_base_addr = low_pc_attrib->val.addr; ctx_out->language = lang_attrib->val.u128.u64[0]; ctx_out->unit_dir = comp_dir_attrib->val.string; + ctx_out->unit_file = comp_dir_attrib->val.string; // rjf: find offset tables Rng1U64Array rnglists_tables_ranges_array = {offset_tables->rnglists_tables_ranges, offset_tables->rnglists_tables_count}; @@ -1115,7 +1118,7 @@ dw2_read_line_table_header(Arena *arena, DW_Raw *raw, DW2_ParseCtx *ctx, String8 DW2_LineTableFile *entry_out = &table.v[idx]; for(U64 entry_format_idx = 0; entry_format_idx < entry_formats_count; entry_format_idx += 1) { - DW_LNCT lnct = (DW_LNCT)entry_formats[entry_format_idx*2 + 0]; + DW_LNCT lnct = (DW_LNCT)entry_formats[entry_format_idx*2 + 0]; DW_FormKind form_kind = (DW_FormKind)entry_formats[entry_format_idx*2 + 1]; DW2_FormVal form_val = {0}; off += dw2_read_form_val(raw, ctx, data, off, form_kind, 0, &form_val); diff --git a/src/rdi_from_dwarf/rdi_from_dwarf.c b/src/rdi_from_dwarf/rdi_from_dwarf.c index 6554251a..ff5d9571 100644 --- a/src/rdi_from_dwarf/rdi_from_dwarf.c +++ b/src/rdi_from_dwarf/rdi_from_dwarf.c @@ -440,10 +440,16 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) if(f->file_name.size != 0) { DW2_LineTableFile *dir = &hdr->dirs.v[f->dir_idx]; + String8 root_dir = {0}; + if(path_style_from_str8(dir->file_name) == PathStyle_Relative) + { + root_dir = ctx->unit_dir; + } String8 full_file_path = str8f(scratch2.arena, "%S%s%S%s%S", - ctx->unit_dir, ctx->unit_dir.size != 0 ? "/" : "", + root_dir, root_dir.size != 0 ? "/" : "", dir->file_name, dir->file_name.size != 0 ? "/" : "", f->file_name); + full_file_path = path_normalized_from_string(scratch2.arena, full_file_path); U64 hash = u64_hash_from_str8(full_file_path); U64 slot_idx = hash%slots_count; SrcFileNode *node = 0;