Skip to content

Commit

Permalink
do not assume the presence of a module when forming an eval parse ctx…
Browse files Browse the repository at this point in the history
…; it must be based on process*vaddr, not module*voff, because you might be evaluating from code without a module
  • Loading branch information
ryanfleury committed Jan 23, 2024
1 parent f50ffd1 commit abb2dd7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
17 changes: 10 additions & 7 deletions src/df/core/df_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/df/core/df_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/df/gfx/df_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 5 additions & 15 deletions src/df/gfx/df_views.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit abb2dd7

Please sign in to comment.