diff --git a/src/base/base_strings.c b/src/base/base_strings.c index aa65537d..209b0e37 100644 --- a/src/base/base_strings.c +++ b/src/base/base_strings.c @@ -1856,7 +1856,7 @@ path_absolute_dst_from_relative_dst_src(Arena *arena, String8 dst, String8 src) if(dst.size != 0 && dst_style == PathStyle_Relative) { Temp scratch = scratch_begin(&arena, 1); - String8 dst_from_src_absolute = push_str8f(scratch.arena, "%S/%S", src, dst); + String8 dst_from_src_absolute = str8f(scratch.arena, "%S/%S", src, dst); String8List dst_from_src_absolute_parts = str8_split_path(scratch.arena, dst_from_src_absolute); PathStyle dst_from_src_absolute_style = path_style_from_str8(src); str8_path_list_resolve_dots_in_place(&dst_from_src_absolute_parts, dst_from_src_absolute_style); @@ -3081,15 +3081,15 @@ str8_compar(String8 a, String8 b, B32 ignore_case) { U64 size = Min(a.size, b.size); int cmp = ignore_case ? MemCompareI(a.str, b.str, size) : MemCompare(a.str, b.str, size); - + // normalize compar result cmp = cmp > 0 ? 1 : cmp < 0 ? -1 : 0; - + // shorter prefix must precede longer prefixes if (cmp == 0) { cmp = a.size < b.size ? -1 : - a.size > b.size ? +1 : 0; + a.size > b.size ? +1 : 0; } return cmp; diff --git a/src/dbg_engine/dbg_engine_ctrl.c b/src/dbg_engine/dbg_engine_ctrl.c index a613378e..eb9f1fc1 100644 --- a/src/dbg_engine/dbg_engine_ctrl.c +++ b/src/dbg_engine/dbg_engine_ctrl.c @@ -823,7 +823,14 @@ internal DI_Key d_dbgi_key_from_module(D_Entity *module) { D_Entity *debug_info_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); - DI_Key dbgi_key = di_key_from_path_timestamp(debug_info_path->string, debug_info_path->timestamp); + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(debug_info_path); + return dbgi_key; +} + +internal DI_Key +d_dbgi_key_from_debug_info_path(D_Entity *dbg_path) +{ + DI_Key dbgi_key = di_key_from_path_timestamp(dbg_path->string, dbg_path->timestamp); return dbgi_key; } diff --git a/src/dbg_engine/dbg_engine_ctrl.h b/src/dbg_engine/dbg_engine_ctrl.h index 4fe1ab95..dd83ff99 100644 --- a/src/dbg_engine/dbg_engine_ctrl.h +++ b/src/dbg_engine/dbg_engine_ctrl.h @@ -488,6 +488,7 @@ internal D_Entity *d_entity_ancestor_from_kind(D_Entity *entity, D_EntityKind ki internal D_Entity *d_process_from_entity(D_Entity *entity); internal D_Entity *d_module_from_process_vaddr(D_Entity *process, U64 vaddr); internal DI_Key d_dbgi_key_from_module(D_Entity *module); +internal DI_Key d_dbgi_key_from_debug_info_path(D_Entity *dbg_path); internal D_Entity *d_module_from_thread_candidates(D_Entity *thread, D_EntityList *candidates); internal U64 d_vaddr_from_voff(D_Entity *module, U64 voff); internal U64 d_voff_from_vaddr(D_Entity *module, U64 vaddr); diff --git a/src/dbg_engine/dbg_engine_user.c b/src/dbg_engine/dbg_engine_user.c index 9a923aa1..cc39701a 100644 --- a/src/dbg_engine/dbg_engine_user.c +++ b/src/dbg_engine/dbg_engine_user.c @@ -345,7 +345,9 @@ d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread) U64 ip_vaddr = d_cached_ip_from_thread(thread->handle); D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); D_Entity *module = d_module_from_process_vaddr(process, ip_vaddr); - DI_Key dbgi_key = d_dbgi_key_from_module(module); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); log_infof("ip_vaddr: 0x%I64x\n", ip_vaddr); log_infof("dbgi_key: {0x%I64x, 0x%I64x}\n", dbgi_key.u64[0], dbgi_key.u64[1]); @@ -355,7 +357,7 @@ d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread) Rng1U64 line_vaddr_rng = {0}; { U64 ip_voff = d_voff_from_vaddr(module, ip_vaddr); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, ip_voff); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, ip_voff); Rng1U64 line_voff_rng = {0}; if(lines.first != 0) { @@ -404,7 +406,7 @@ d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread) // is enabled. This is enabled by default normally. { U64 opl_line_voff_rng = d_voff_from_vaddr(module, line_vaddr_rng.max); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, opl_line_voff_rng); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, opl_line_voff_rng); if(lines.first != 0 && (lines.first->v.pt.line == 0xf00f00 || lines.first->v.pt.line == 0xfeefee)) { line_vaddr_rng.max = d_vaddr_from_voff(module, lines.first->v.voff_range.max); @@ -583,7 +585,9 @@ d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread) U64 ip_vaddr = d_cached_ip_from_thread(thread->handle); D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); D_Entity *module = d_module_from_process_vaddr(process, ip_vaddr); - DI_Key dbgi_key = d_dbgi_key_from_module(module); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); // rjf: ip => line info String8 file_path = {0}; @@ -591,7 +595,7 @@ d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread) Rng1U64 line_vaddr_rng = {0}; { U64 ip_voff = d_voff_from_vaddr(module, ip_vaddr); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, ip_voff); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, ip_voff); Rng1U64 line_voff_rng = {0}; if(lines.first != 0) { @@ -623,7 +627,7 @@ d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread) // is enabled. This is enabled by default normally. { U64 opl_line_voff_rng = d_voff_from_vaddr(module, line_vaddr_rng.max); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, opl_line_voff_rng); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, opl_line_voff_rng); if(lines.first != 0 && (lines.first->v.pt.line == 0xf00f00 || lines.first->v.pt.line == 0xfeefee)) { line_vaddr_rng.max = d_vaddr_from_voff(module, lines.first->v.voff_range.max); @@ -686,8 +690,10 @@ d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread) U64 jump_dest_vaddr = point->jump_dest_vaddr; D_Entity *jump_dest_module = d_module_from_process_vaddr(process, jump_dest_vaddr); U64 jump_dest_voff = d_voff_from_vaddr(jump_dest_module, jump_dest_vaddr); - DI_Key jump_dest_dbgi_key = d_dbgi_key_from_module(jump_dest_module); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, jump_dest_dbgi_key, jump_dest_voff); + D_Entity *jump_dest_dbg_path = d_entity_child_from_kind(jump_dest_module, D_EntityKind_DebugInfoPath); + String8 jump_dest_dbgi_path = jump_dest_dbg_path->string; + DI_Key jump_dest_dbgi_key = d_dbgi_key_from_debug_info_path(jump_dest_dbg_path); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, jump_dest_dbgi_key, jump_dest_dbgi_path, jump_dest_voff); if(lines.count == 0) { add = 0; @@ -996,7 +1002,7 @@ d_trap_net_from_thread__step_to_exit(Arena *arena, D_Entity *thread) //- rjf: voff -> line info internal D_LineList -d_lines_from_dbgi_key_voff(Arena *arena, DI_Key dbgi_key, U64 voff) +d_lines_from_dbgi_key_path_voff(Arena *arena, DI_Key dbgi_key, String8 dbgi_path, U64 voff) { Temp scratch = scratch_begin(&arena, 1); Access *access = access_open(); @@ -1064,12 +1070,18 @@ d_lines_from_dbgi_key_voff(Arena *arena, DI_Key dbgi_key, U64 voff) StringJoin join = {0}; join.sep = str8_lit("/"); String8 file_normalized_full_path = str8_list_join(arena, &path_parts, &join); + String8 file_normalized_full_path_absolute = file_normalized_full_path; + if(dbgi_path.size != 0) + { + String8 dbgi_path_folder = str8_chop_last_slash(dbgi_path); + file_normalized_full_path_absolute = path_absolute_dst_from_relative_dst_src(arena, file_normalized_full_path, dbgi_path_folder); + } D_LineNode *n = push_array(arena, D_LineNode, 1); SLLQueuePush(result.first, result.last, n); result.count += 1; - if(line->file_idx != 0 && file_normalized_full_path.size != 0) + if(line->file_idx != 0 && file_normalized_full_path_absolute.size != 0) { - n->v.file_path = file_normalized_full_path; + n->v.file_path = file_normalized_full_path_absolute; } n->v.pt = txt_pt(line->line_num, column ? column->col_first : 1); n->v.voff_range = r1u64(parsed_line_table.voffs[line_info_idx], parsed_line_table.voffs[line_info_idx+1]); diff --git a/src/dbg_engine/dbg_engine_user.h b/src/dbg_engine/dbg_engine_user.h index eb63a750..3eeb8598 100644 --- a/src/dbg_engine/dbg_engine_user.h +++ b/src/dbg_engine/dbg_engine_user.h @@ -433,7 +433,7 @@ internal D_TrapNet d_trap_net_from_thread__step_to_exit(Arena *arena, D_Entity * //~ rjf: Debug Info Lookups //- rjf: voff -> line info -internal D_LineList d_lines_from_dbgi_key_voff(Arena *arena, DI_Key dbgi_key, U64 voff); +internal D_LineList d_lines_from_dbgi_key_path_voff(Arena *arena, DI_Key dbgi_key, String8 dbgi_path, U64 voff); //- rjf: file:line -> line info // TODO(rjf): this depends on file path maps, needs to move diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 14b199ff..225fe2d9 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -4846,11 +4846,11 @@ rd_view_ui(Rng2F32 rect) // rjf: try to unpack debug info from type E_TypeKey type_key = e_type_key_unwrap(cell->eval.irtree.type_key, E_TypeUnwrapFlag_All); DI_Key dbgi_key = {0}; - String8 base_folder = {0}; + String8 dbgi_path = {0}; { E_DbgInfo *dbg_info = e_dbg_info_from_type_key(type_key); dbgi_key = dbg_info->dbgi_key; - base_folder = str8_chop_last_slash(dbg_info->name); + dbgi_path = dbg_info->name; } // rjf: if this is a vaddr evaluation, then unpack voff/vaddr & switch to module's debug info @@ -4864,11 +4864,10 @@ rd_view_ui(Rng2F32 rect) module = d_module_from_process_vaddr(process, vaddr); voff = d_voff_from_vaddr(module, vaddr); dbgi_key = d_dbgi_key_from_module(module); - base_folder = str8_chop_last_slash(module->string); } // rjf: voff * debug info -> lines - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, voff); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, voff); // rjf: snap to line if(lines.first != 0) @@ -10652,10 +10651,12 @@ rd_gather_auto_exprs(Arena *arena) D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); U64 thread_ip_vaddr = d_cached_ip_from_thread(thread_handle); D_Entity *module = d_module_from_process_vaddr(process, thread_ip_vaddr); - DI_Key dbgi_key = d_dbgi_key_from_module(module); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); RDI_Parsed *rdi = di_rdi_from_key(access, dbgi_key, 0, 0); U64 thread_ip_voff = d_voff_from_vaddr(module, thread_ip_vaddr); - D_LineList thread_ip_lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, thread_ip_voff); + D_LineList thread_ip_lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, thread_ip_voff); //- rjf: gather all relevant code vaddr ranges Rng1U64List code_vaddr_ranges = {0}; @@ -13644,8 +13645,10 @@ rd_frame(void) D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); D_Entity *module = d_module_from_process_vaddr(process, vaddr); U64 voff = d_voff_from_vaddr(module, vaddr); - DI_Key dbgi_key = d_dbgi_key_from_module(module); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, voff); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, voff); str8_list_pushf(rd_state->cmd_output_arena, &rd_state->cmd_outputs, " lines:\n {\n"); for EachNode(n, D_LineNode, lines.first) { @@ -13732,8 +13735,10 @@ rd_frame(void) D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); D_Entity *module = d_module_from_process_vaddr(process, vaddr); U64 voff = d_voff_from_vaddr(module, vaddr); - DI_Key dbgi_key = d_dbgi_key_from_module(module); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, voff); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, voff); str8_list_pushf(rd_state->cmd_output_arena, &rd_state->cmd_outputs, "lines:\n{\n"); for EachNode(n, D_LineNode, lines.first) { @@ -15399,10 +15404,12 @@ rd_frame(void) U64 rip_vaddr = d_query_cached_rip_from_thread_unwind(thread, unwind_index); D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); D_Entity *module = d_module_from_process_vaddr(process, rip_vaddr); - DI_Key dbgi_key = d_dbgi_key_from_module(module); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); RDI_Parsed *rdi = di_rdi_from_key(access, dbgi_key, 0, 0); U64 rip_voff = d_voff_from_vaddr(module, rip_vaddr); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, rip_voff); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, rip_voff); D_Line line = {0}; { U64 idx = 0; @@ -15482,6 +15489,7 @@ rd_frame(void) // rjf: try to resolve name as a symbol U64 voff = 0; DI_Key voff_dbgi_key = {0}; + String8 voff_dbgi_path = {0}; if(!name_resolved) { DI_Match match = {0}; @@ -15502,6 +15510,14 @@ rd_frame(void) RDI_Symbol *procedure = rdi_element_from_name_idx(rdi, Procedures, match.idx); voff = rdi_first_voff_from_procedure(rdi, procedure); voff_dbgi_key = match.key; + for EachIndex(idx, e_base_ctx->dbg_infos_count) + { + if(di_key_match(e_base_ctx->dbg_infos[idx].dbgi_key, voff_dbgi_key)) + { + voff_dbgi_path = e_base_ctx->dbg_infos[idx].name; + break; + } + } } access_close(access); } @@ -15562,7 +15578,7 @@ rd_frame(void) // rjf: name resolved to voff * dbg info if(name_resolved && voff != 0) { - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, voff_dbgi_key, voff); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, voff_dbgi_key, voff_dbgi_path, voff); if(lines.first != 0) { D_Entity *process = &d_entity_nil; @@ -15660,14 +15676,6 @@ rd_frame(void) } } - //- rjf: absolutify file path - { - String8 base_folder = {0}; - if(base_folder.size == 0) { base_folder = str8_chop_last_slash(e_base_ctx->primary_dbg_info->name); } - if(base_folder.size == 0) { base_folder = str8_chop_last_slash(e_base_ctx->primary_module->name); } - file_path = path_absolute_dst_from_relative_dst_src(scratch.arena, file_path, base_folder); - } - //- rjf: if transient tabs are turned off, always prefer new tab if(!rd_setting_b32_from_name(str8_lit("transient_tabs"))) { diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index 11c8a90c..5d788220 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -563,9 +563,11 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla U64 rip_vaddr = d_query_cached_rip_from_thread_unwind(thread, unwind_count); U64 last_inst_on_unwound_rip_vaddr = rip_vaddr - !!unwind_count; D_Entity *module = d_module_from_process_vaddr(process, last_inst_on_unwound_rip_vaddr); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); U64 rip_voff = d_voff_from_vaddr(module, last_inst_on_unwound_rip_vaddr); - DI_Key dbgi_key = d_dbgi_key_from_module(module); - D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, rip_voff); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); + D_LineList lines = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, rip_voff); String8 file_checksums[RDI_ChecksumKind_COUNT] = {0}; for(D_LineNode *n = lines.first; n != 0; n = n->next) { @@ -715,14 +717,16 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla if(dasm_lines) { D_Entity *module = d_module_from_process_vaddr(process, dasm_vaddr_range.min); - DI_Key dbgi_key = d_dbgi_key_from_module(module); + D_Entity *dbg_path = d_entity_child_from_kind(module, D_EntityKind_DebugInfoPath); + String8 dbgi_path = dbg_path->string; + DI_Key dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); for(S64 line_num = visible_line_num_range.min; line_num < visible_line_num_range.max; line_num += 1) { U64 vaddr = dasm_vaddr_range.min + dasm_line_array_code_off_from_idx(dasm_lines, line_num-1); U64 voff = d_voff_from_vaddr(module, vaddr); U64 slice_idx = line_num-visible_line_num_range.min; code_slice_params.line_vaddrs[slice_idx] = vaddr; - code_slice_params.line_infos[slice_idx] = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, voff); + code_slice_params.line_infos[slice_idx] = d_lines_from_dbgi_key_path_voff(scratch.arena, dbgi_key, dbgi_path, voff); } } @@ -2731,6 +2735,7 @@ RD_VIEW_UI_FUNCTION_DEF(disasm) D_Entity *space_entity = rd_ctrl_entity_from_eval_space(space); D_Entity *dasm_module = &d_entity_nil; DI_Key dbgi_key = {0}; + String8 dbgi_path = {0}; U64 base_vaddr = 0; switch(space_entity->kind) { @@ -2739,8 +2744,10 @@ RD_VIEW_UI_FUNCTION_DEF(disasm) { if(arch == Arch_Null) { arch = space_entity->arch; } dasm_module = d_module_from_process_vaddr(space_entity, range.min); - dbgi_key = d_dbgi_key_from_module(dasm_module); - base_vaddr = dasm_module->vaddr_range.min; + D_Entity *dbg_path = d_entity_child_from_kind(dasm_module, D_EntityKind_DebugInfoPath); + dbgi_path = dbg_path->string; + dbgi_key = d_dbgi_key_from_debug_info_path(dbg_path); + base_vaddr = dasm_module->vaddr_range.min; }break; } DASM_StyleFlags style_flags = 0; @@ -2835,7 +2842,7 @@ RD_VIEW_UI_FUNCTION_DEF(disasm) rd_regs()->vaddr = range.min+off; rd_regs()->vaddr_range = r1u64(range.min+off, range.min+off); rd_regs()->voff_range = d_voff_range_from_vaddr_range(dasm_module, rd_regs()->vaddr_range); - rd_regs()->lines = d_lines_from_dbgi_key_voff(rd_frame_arena(), dbgi_key, rd_regs()->voff_range.min); + rd_regs()->lines = d_lines_from_dbgi_key_path_voff(rd_frame_arena(), dbgi_key, dbgi_path, rd_regs()->voff_range.min); } //////////////////////////////