From 5532aa690359c09d4faf428fa09d7195b23ef5a0 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 13 May 2025 16:23:31 -0700 Subject: [PATCH] rdi_from_pdb: when relative paths are supplied by line info, build them as being relative to OBJ; this is not necessarily correct but it is the best thing we can do given the available information. the user needs to remap this once in the debugger, but then it will work. --- src/raddbg/raddbg_core.c | 2 +- src/rdi_from_pdb/rdi_from_pdb.c | 35 +++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index b2c7622f..a6899d88 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -14557,7 +14557,7 @@ rd_frame(void) U64 vaddr = 0; B32 require_disasm_snap = 0; { - file_path = rd_regs()->file_path; + file_path = rd_mapped_from_file_path(scratch.arena, rd_regs()->file_path); point = rd_regs()->cursor; thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); process = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process); diff --git a/src/rdi_from_pdb/rdi_from_pdb.c b/src/rdi_from_pdb/rdi_from_pdb.c index 70105610..b6b61b0e 100644 --- a/src/rdi_from_pdb/rdi_from_pdb.c +++ b/src/rdi_from_pdb/rdi_from_pdb.c @@ -616,13 +616,14 @@ ASYNC_WORK_DEF(p2r_units_convert_work) } } - //- rjf: produce obj name + //- rjf: produce obj name/path String8 obj_name = pdb_unit->obj_name; if(str8_match(obj_name, str8_lit("* Linker *"), 0) || str8_match(obj_name, str8_lit("Import:"), StringMatchFlag_RightSideSloppy)) { MemoryZeroStruct(&obj_name); } + String8 obj_folder_path = lower_from_str8(scratch.arena, str8_chop_last_slash(obj_name)); //- rjf: build this unit's line table, fill out primary line info (inline info added after) RDIM_LineTable *line_table = 0; @@ -644,6 +645,13 @@ ASYNC_WORK_DEF(p2r_units_convert_work) { PathStyle file_path_normalized_style = path_style_from_str8(file_path_normalized); String8List file_path_normalized_parts = str8_split_path(scratch.arena, file_path_normalized); + if(file_path_normalized_style == PathStyle_Relative) + { + String8List obj_folder_path_parts = str8_split_path(scratch.arena, obj_folder_path); + str8_list_concat_in_place(&obj_folder_path_parts, &file_path_normalized_parts); + file_path_normalized_parts = obj_folder_path_parts; + file_path_normalized_style = path_style_from_str8(obj_folder_path); + } str8_path_list_resolve_dots_in_place(&file_path_normalized_parts, file_path_normalized_style); file_path_normalized = str8_path_list_join_by_style(scratch.arena, &file_path_normalized_parts, file_path_normalized_style); } @@ -715,10 +723,23 @@ ASYNC_WORK_DEF(p2r_units_convert_work) ProfScope("pass 3: parse all inlinee line tables") for(U64 comp_unit_idx = 0; comp_unit_idx < in->comp_units->count; comp_unit_idx += 1) { + //- rjf: unpack unit + PDB_CompUnit *pdb_unit = in->comp_units->units[comp_unit_idx]; CV_SymParsed *unit_sym = in->comp_unit_syms[comp_unit_idx]; CV_C13Parsed *unit_c13 = in->comp_unit_c13s[comp_unit_idx]; CV_RecRange *rec_ranges_first = unit_sym->sym_ranges.ranges; CV_RecRange *rec_ranges_opl = rec_ranges_first+unit_sym->sym_ranges.count; + + //- rjf: produce obj name/path + String8 obj_name = pdb_unit->obj_name; + if(str8_match(obj_name, str8_lit("* Linker *"), 0) || + str8_match(obj_name, str8_lit("Import:"), StringMatchFlag_RightSideSloppy)) + { + MemoryZeroStruct(&obj_name); + } + String8 obj_folder_path = lower_from_str8(scratch.arena, str8_chop_last_slash(obj_name)); + + //- rjf: parse inlinee line tables U64 base_voff = 0; for(CV_RecRange *rec_range = rec_ranges_first; rec_range < rec_ranges_opl; @@ -839,12 +860,18 @@ ASYNC_WORK_DEF(p2r_units_convert_work) // rjf: file name -> normalized file path String8 file_path = seq_file_name; String8 file_path_normalized = lower_from_str8(scratch.arena, str8_skip_chop_whitespace(file_path)); - for(U64 idx = 0; idx < file_path_normalized.size; idx += 1) { - if(file_path_normalized.str[idx] == '\\') + PathStyle file_path_normalized_style = path_style_from_str8(file_path_normalized); + String8List file_path_normalized_parts = str8_split_path(scratch.arena, file_path_normalized); + if(file_path_normalized_style == PathStyle_Relative) { - file_path_normalized.str[idx] = '/'; + String8List obj_folder_path_parts = str8_split_path(scratch.arena, obj_folder_path); + str8_list_concat_in_place(&obj_folder_path_parts, &file_path_normalized_parts); + file_path_normalized_parts = obj_folder_path_parts; + file_path_normalized_style = path_style_from_str8(obj_folder_path); } + str8_path_list_resolve_dots_in_place(&file_path_normalized_parts, file_path_normalized_style); + file_path_normalized = str8_path_list_join_by_style(scratch.arena, &file_path_normalized_parts, file_path_normalized_style); } // rjf: normalized file path -> source file node