From 74fa729a58b15f63fc8b444274d716070c065254 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 23 Jan 2024 14:44:39 -0800 Subject: [PATCH] do not assume the presence of a module when forming an eval parse ctx; it must be based on process*vaddr, not module*voff, because you might be evaluating from code without a module --- src/df/core/df_core.c | 17 ++++++++++------- src/df/core/df_core.h | 2 +- src/df/gfx/df_gfx.c | 4 +--- src/df/gfx/df_views.c | 20 +++++--------------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/df/core/df_core.c b/src/df/core/df_core.c index 7250ec17..84d978e3 100644 --- a/src/df/core/df_core.c +++ b/src/df/core/df_core.c @@ -1083,9 +1083,7 @@ df_cmd_params_apply_spec_query(Arena *arena, DF_CtrlCtx *ctrl_ctx, DF_CmdParams DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread); U64 vaddr = df_query_cached_rip_from_thread_unwind(thread, ctrl_ctx->unwind_count); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); - DF_Entity *module = df_module_from_process_vaddr(process, vaddr); - U64 voff = df_voff_from_vaddr(module, vaddr); - EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_module_voff(scope, module, voff); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(scope, process, vaddr); DF_Eval eval = df_eval_from_string(scratch.arena, scope, ctrl_ctx, &parse_ctx, query); if(eval.errors.count == 0) { @@ -3962,17 +3960,19 @@ df_eval_memory_read(void *u, void *out, U64 addr, U64 size) } internal EVAL_ParseCtx -df_eval_parse_ctx_from_module_voff(DBGI_Scope *scope, DF_Entity *module, U64 voff) +df_eval_parse_ctx_from_process_vaddr(DBGI_Scope *scope, DF_Entity *process, U64 vaddr) { Temp scratch = scratch_begin(0, 0); //- rjf: extract info + DF_Entity *module = df_module_from_process_vaddr(process, vaddr); + U64 voff = df_voff_from_vaddr(module, vaddr); DF_Entity *binary = df_binary_file_from_module(module); String8 binary_path = df_full_path_from_entity(scratch.arena, binary); DBGI_Parse *dbgi = dbgi_parse_from_exe_path(scope, binary_path, 0); RADDBG_Parsed *rdbg = &dbgi->rdbg; - Architecture arch = df_architecture_from_entity(module); - EVAL_String2NumMap *reg_map = ctrl_string2reg_from_arch (arch); + Architecture arch = df_architecture_from_entity(process); + EVAL_String2NumMap *reg_map = ctrl_string2reg_from_arch(arch); EVAL_String2NumMap *reg_alias_map = ctrl_string2alias_from_arch(arch); EVAL_String2NumMap *locals_map = df_query_cached_locals_map_from_binary_voff(binary, voff); EVAL_String2NumMap *member_map = df_query_cached_member_map_from_binary_voff(binary, voff); @@ -4083,7 +4083,10 @@ df_eval_parse_ctx_from_src_loc(DBGI_Scope *scope, DF_Entity *file, TxtPt pt) if(modules.count != 0) { DF_Entity *module = modules.first->entity; - ctx = df_eval_parse_ctx_from_module_voff(scope, module, src2dasm->voff_range.min); + DF_Entity *process = df_entity_ancestor_from_kind(module, DF_EntityKind_Process); + U64 voff = src2dasm->voff_range.min; + U64 vaddr = df_vaddr_from_voff(module, voff); + ctx = df_eval_parse_ctx_from_process_vaddr(scope, process, vaddr); good_ctx = 1; break; } diff --git a/src/df/core/df_core.h b/src/df/core/df_core.h index 4fa1de55..7fb97677 100644 --- a/src/df/core/df_core.h +++ b/src/df/core/df_core.h @@ -1573,7 +1573,7 @@ internal CTRL_Event df_ctrl_last_stop_event(void); //~ rjf: Evaluation internal B32 df_eval_memory_read(void *u, void *out, U64 addr, U64 size); -internal EVAL_ParseCtx df_eval_parse_ctx_from_module_voff(DBGI_Scope *scope, DF_Entity *module, U64 voff); +internal EVAL_ParseCtx df_eval_parse_ctx_from_process_vaddr(DBGI_Scope *scope, DF_Entity *process, U64 vaddr); internal EVAL_ParseCtx df_eval_parse_ctx_from_src_loc(DBGI_Scope *scope, DF_Entity *file, TxtPt pt); internal DF_Eval df_eval_from_string(Arena *arena, DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, String8 string); internal DF_Eval df_value_mode_eval_from_eval(TG_Graph *graph, RADDBG_Parsed *rdbg, DF_CtrlCtx *ctrl_ctx, DF_Eval eval); diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index c00f09ad..b441208b 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -3918,9 +3918,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_Entity *thread = df_entity_from_handle(ctrl_ctx.thread); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); U64 thread_unwind_rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, ctrl_ctx.unwind_count); - DF_Entity *module = df_module_from_process_vaddr(process, thread_unwind_rip_vaddr); - U64 thread_unwind_rip_voff = df_voff_from_vaddr(module, thread_unwind_rip_vaddr); - EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_module_voff(scope, module, thread_unwind_rip_voff); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(scope, process, thread_unwind_rip_vaddr); String8 expr = ws->hover_eval_string; DF_Eval eval = df_eval_from_string(scratch.arena, scope, &ctrl_ctx, &parse_ctx, expr); diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index 3bfbd4d9..128928d9 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -736,13 +736,11 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW DF_Entity *thread = df_entity_from_handle(ctrl_ctx.thread); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); U64 thread_ip_vaddr = df_query_cached_rip_from_thread_unwind(thread, ctrl_ctx.unwind_count); - DF_Entity *module = df_module_from_process_vaddr(process, thread_ip_vaddr); - U64 thread_ip_voff = df_voff_from_vaddr(module, thread_ip_vaddr); ////////////////////////////// //- rjf: process * thread info -> parse_ctx // - EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_module_voff(scope, module, thread_ip_voff); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(scope, process, thread_ip_vaddr); ////////////////////////////// //- rjf: roots -> viz blocks @@ -4769,9 +4767,7 @@ DF_VIEW_UI_FUNCTION_DEF(Code) U64 unwind_count = ctrl_ctx.unwind_count; U64 rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, unwind_count); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); - DF_Entity *module = df_module_from_process_vaddr(process, rip_vaddr); - U64 rip_voff = df_voff_from_vaddr(module, rip_vaddr); - EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_module_voff(scope, module, rip_voff); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(scope, process, rip_vaddr); ////////////////////////////// //- rjf: unpack entity info @@ -5824,9 +5820,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly) U64 unwind_count = ctrl_ctx.unwind_count; U64 rip_vaddr = df_query_cached_rip_from_thread_unwind(selected_thread, unwind_count); DF_Entity *selected_thread_process = df_entity_ancestor_from_kind(selected_thread, DF_EntityKind_Process); - DF_Entity *selected_thread_module = df_module_from_process_vaddr(selected_thread_process, rip_vaddr); - U64 rip_voff = df_voff_from_vaddr(selected_thread_module, rip_vaddr); - EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_module_voff(scope, selected_thread_module, rip_voff); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(scope, selected_thread_process, rip_vaddr); F_Tag code_font = df_font_from_slot(DF_FontSlot_Code); F32 code_font_size = df_font_size_from_slot(ws, DF_FontSlot_Code); F_Metrics code_font_metrics = f_metrics_from_tag_size(code_font, code_font_size); @@ -6725,9 +6719,7 @@ DF_VIEW_UI_FUNCTION_DEF(Output) U64 unwind_count = ctrl_ctx.unwind_count; U64 rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, unwind_count); DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); - DF_Entity *module = df_module_from_process_vaddr(process, rip_vaddr); - U64 rip_voff = df_voff_from_vaddr(module, rip_vaddr); - EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_module_voff(scope, module, rip_voff); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(scope, process, rip_vaddr); ////////////////////////////// //- rjf: unpack entity info @@ -7674,9 +7666,7 @@ DF_VIEW_UI_FUNCTION_DEF(Memory) }; DBGI_Scope *scope = dbgi_scope_open(); U64 thread_rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, ctrl_ctx.unwind_count); - DF_Entity *module = df_module_from_process_vaddr(process, thread_rip_vaddr); - U64 thread_rip_voff = df_voff_from_vaddr(module, thread_rip_vaddr); - EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_module_voff(scope, module, thread_rip_voff); + EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(scope, process, thread_rip_vaddr); RADDBG_Parsed *rdbg = parse_ctx.rdbg; for(U64 idx = 0; idx < parse_ctx.locals_map->slots_count; idx += 1) {