diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 3be0a2fb..17433604 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -5513,10 +5513,11 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) ctx->reg_space.u64_0 = (U64)thread; ctx->module_base = push_array(temp.arena, U64, 1); ctx->module_base[0]= module->vaddr_range.min; + ctx->frame_base = push_array(temp.arena, U64, 1); ctx->tls_base = push_array(temp.arena, U64, 1); } - e_select_interpret_ctx(&interpret_ctx); - + e_select_interpret_ctx(&interpret_ctx, type_ctx.primary_module->rdi, type_ctx.ip_voff); + // rjf: evaluate E_Eval eval = zero_struct; ProfScope("evaluate expression") diff --git a/src/eval/eval_interpret.c b/src/eval/eval_interpret.c index c7c824a4..9af391ad 100644 --- a/src/eval/eval_interpret.c +++ b/src/eval/eval_interpret.c @@ -11,9 +11,50 @@ e_selected_interpret_ctx(void) } internal void -e_select_interpret_ctx(E_InterpretCtx *ctx) +e_select_interpret_ctx(E_InterpretCtx *ctx, RDI_Parsed *primary_rdi, U64 ip_voff) { e_interpret_ctx = ctx; + + // compute and apply frame base + { + E_Interpretation frame_base = { .code = ~0 }; + + RDI_Procedure *proc = rdi_procedure_from_voff(primary_rdi, ip_voff); + for(U64 loc_block_idx = proc->frame_base_location_first; loc_block_idx < proc->frame_base_location_opl; loc_block_idx += 1) + { + RDI_LocationBlock *block = rdi_element_from_name_idx(primary_rdi, LocationBlocks, loc_block_idx); + if (block->scope_off_first <= ip_voff && ip_voff < block->scope_off_opl) { + U64 all_location_data_size = 0; + U8 *all_location_data = rdi_table_from_name(primary_rdi, LocationData, &all_location_data_size); + if(block->location_data_off + sizeof(RDI_LocationKind) <= all_location_data_size) + { + RDI_LocationKind loc_kind = *(RDI_LocationKind *)(all_location_data + block->location_data_off); + if(loc_kind == RDI_LocationKind_ValBytecodeStream || loc_kind == RDI_LocationKind_AddrBytecodeStream) + { + U8 *bytecode_ptr = all_location_data + block->location_data_off + sizeof(RDI_LocationKind); + U8 *bytecode_opl = all_location_data + all_location_data_size; + U64 bytecode_size = rdi_size_from_bytecode_stream(bytecode_ptr, bytecode_opl); + String8 bytecode = str8(bytecode_ptr, bytecode_size); + frame_base = e_interpret(bytecode); + } + else if(loc_kind != RDI_LocationKind_NULL) + { + NotImplemented; + } + } + break; + } + } + + if(frame_base.code == E_InterpretationCode_Good) + { + *ctx->frame_base = frame_base.value.u64; + } + else + { + ctx->frame_base = 0; + } + } } //////////////////////////////// diff --git a/src/eval/eval_interpret.h b/src/eval/eval_interpret.h index 3a9d0b51..f91cc7e2 100644 --- a/src/eval/eval_interpret.h +++ b/src/eval/eval_interpret.h @@ -43,7 +43,7 @@ thread_static E_InterpretCtx *e_interpret_ctx = 0; //~ rjf: Context Selection Functions (Selection Required For All Subsequent APIs) internal E_InterpretCtx *e_selected_interpret_ctx(void); -internal void e_select_interpret_ctx(E_InterpretCtx *ctx); +internal void e_select_interpret_ctx(E_InterpretCtx *ctx, RDI_Parsed *primary_rdi, U64 ip_voff); //////////////////////////////// //~ rjf: Space Reading Helpers diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 8ba4a716..575fd4c1 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -12159,11 +12159,12 @@ rd_frame(void) ctx->reg_unwind_count = unwind_count; ctx->module_base = push_array(scratch.arena, U64, 1); ctx->module_base[0] = module->vaddr_range.min; + ctx->frame_base = push_array(scratch.arena, U64, 1); ctx->tls_base = push_array(scratch.arena, U64, 1); ctx->tls_base[0] = d_query_cached_tls_base_vaddr_from_process_root_rip(process, tls_root_vaddr, rip_vaddr); } - e_select_interpret_ctx(interpret_ctx); - + e_select_interpret_ctx(interpret_ctx, eval_modules_primary->rdi, rip_voff); + //////////////////////////// //- rjf: build eval visualization view rule table //