mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-26 13:35:00 -07:00
collapse register mode into being a thread space, unify process/thread/debugger read/write paths, keep differences in core eval read/write paths
This commit is contained in:
+17
-6
@@ -1128,7 +1128,7 @@ ctrl_stored_hash_from_process_vaddr_range(CTRL_MachineID machine_id, DMN_Handle
|
||||
}
|
||||
|
||||
//- rjf: not good, or is stale -> submit hash request
|
||||
if((!is_good || is_stale) && os_now_microseconds() >= last_time_requested_us+10000)
|
||||
if((!is_good || is_stale) && os_now_microseconds() >= last_time_requested_us+100000)
|
||||
{
|
||||
if(ctrl_u2ms_enqueue_req(machine_id, process, range, zero_terminated, endt_us)) OS_MutexScopeW(process_stripe->rw_mutex)
|
||||
{
|
||||
@@ -3809,6 +3809,18 @@ ctrl_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
|
||||
U64 read_size = dmn_process_read(entity->handle, range, out);
|
||||
result = (read_size == dim_1u64(range));
|
||||
}break;
|
||||
case CTRL_EntityKind_Thread:
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
U64 regs_size = regs_block_size_from_architecture(entity->arch);
|
||||
void *regs = ctrl_query_cached_reg_block_from_thread(scratch.arena, ctrl_state->ctrl_thread_entity_store, entity->machine_id, entity->handle);
|
||||
Rng1U64 legal_range = r1u64(0, regs_size);
|
||||
Rng1U64 read_range = intersect_1u64(legal_range, range);
|
||||
U64 read_size = dim_1u64(read_range);
|
||||
MemoryCopy(out, (U8 *)regs + read_range.min, read_size);
|
||||
result = (read_size == dim_1u64(range));
|
||||
scratch_end(scratch);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -4707,6 +4719,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
|
||||
E_ParseCtx *ctx = &parse_ctx;
|
||||
ctx->ip_vaddr = thread_rip_vaddr;
|
||||
ctx->ip_voff = thread_rip_voff;
|
||||
ctx->ip_thread_space = (E_Space)thread;
|
||||
ctx->modules = eval_modules;
|
||||
ctx->modules_count = eval_modules_count;
|
||||
ctx->primary_module = eval_modules_primary;
|
||||
@@ -4727,13 +4740,11 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
|
||||
E_InterpretCtx interpret_ctx = zero_struct;
|
||||
{
|
||||
E_InterpretCtx *ctx = &interpret_ctx;
|
||||
ctx->space_read_user_data = ctrl_state->ctrl_thread_entity_store;
|
||||
ctx->space_rw_user_data = ctrl_state->ctrl_thread_entity_store;
|
||||
ctx->space_read = ctrl_eval_space_read;
|
||||
ctx->primary_space = eval_modules_primary->space;
|
||||
ctx->reg_arch = eval_modules_primary->arch;
|
||||
ctx->reg_size = regs_block_size_from_architecture(eval_modules_primary->arch);
|
||||
ctx->reg_data = push_array(temp.arena, U8, ctx->reg_size);
|
||||
dmn_thread_read_reg_block(event->thread, ctx->reg_data);
|
||||
ctx->reg_space = (E_Space)thread;
|
||||
ctx->module_base = push_array(temp.arena, U64, 1);
|
||||
ctx->module_base[0]= module->vaddr_range.min;
|
||||
ctx->tls_base = push_array(temp.arena, U64, 1);
|
||||
@@ -5348,8 +5359,8 @@ ctrl_mem_stream_thread__entry_point(void *p)
|
||||
if(!u128_match(u128_zero(), hash))
|
||||
{
|
||||
range_n->hash = hash;
|
||||
range_n->mem_gen = post_read_mem_gen;
|
||||
}
|
||||
range_n->mem_gen = post_read_mem_gen;
|
||||
ins_atomic_u32_eval_assign(&range_n->is_taken, 0);
|
||||
goto commit__break_all;
|
||||
}
|
||||
|
||||
+128
-14
@@ -3736,6 +3736,7 @@ df_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
|
||||
DF_Entity *entity = (DF_Entity *)space;
|
||||
switch(entity->kind)
|
||||
{
|
||||
//- rjf: default -> evaluating a debugger entity; read from entity POD evaluation
|
||||
default:
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
@@ -3757,6 +3758,8 @@ df_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}break;
|
||||
|
||||
//- rjf: process -> reading process memory
|
||||
case DF_EntityKind_Process:
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
@@ -3769,6 +3772,25 @@ df_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}break;
|
||||
|
||||
//- rjf: thread -> reading from thread register block
|
||||
case DF_EntityKind_Thread:
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
CTRL_Unwind unwind = df_query_cached_unwind_from_thread(entity);
|
||||
U64 frame_idx = e_interpret_ctx->reg_unwind_count;
|
||||
if(frame_idx < unwind.frames.count)
|
||||
{
|
||||
CTRL_UnwindFrame *f = &unwind.frames.v[frame_idx];
|
||||
U64 regs_size = regs_block_size_from_architecture(e_interpret_ctx->reg_arch);
|
||||
Rng1U64 legal_range = r1u64(0, regs_size);
|
||||
Rng1U64 read_range = intersect_1u64(legal_range, range);
|
||||
U64 read_size = dim_1u64(read_range);
|
||||
MemoryCopy(out, (U8 *)f->regs + read_range.min, read_size);
|
||||
result = (read_size == dim_1u64(range));
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -3780,13 +3802,38 @@ df_eval_space_write(void *u, E_Space space, void *in, Rng1U64 range)
|
||||
DF_Entity *entity = (DF_Entity *)space;
|
||||
switch(entity->kind)
|
||||
{
|
||||
//- rjf: default -> making commits to entity evaluation
|
||||
default:
|
||||
{
|
||||
|
||||
}break;
|
||||
|
||||
//- rjf: process -> commit to process memory
|
||||
case DF_EntityKind_Process:
|
||||
{
|
||||
result = ctrl_process_write(entity->ctrl_machine_id, entity->ctrl_handle, range, in);
|
||||
}break;
|
||||
|
||||
//- rjf: thread -> commit to thread's register block
|
||||
case DF_EntityKind_Thread:
|
||||
{
|
||||
CTRL_Unwind unwind = df_query_cached_unwind_from_thread(entity);
|
||||
U64 frame_idx = 0;
|
||||
if(frame_idx < unwind.frames.count)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
U64 regs_size = regs_block_size_from_architecture(df_architecture_from_entity(entity));
|
||||
Rng1U64 legal_range = r1u64(0, regs_size);
|
||||
Rng1U64 write_range = intersect_1u64(legal_range, range);
|
||||
U64 write_size = dim_1u64(write_range);
|
||||
CTRL_UnwindFrame *f = &unwind.frames.v[frame_idx];
|
||||
void *new_regs = push_array(scratch.arena, U8, regs_size);
|
||||
MemoryCopy(new_regs, f->regs, regs_size);
|
||||
MemoryCopy((U8 *)new_regs + write_range.min, in, write_size);
|
||||
result = ctrl_thread_write_reg_block(entity->ctrl_machine_id, entity->ctrl_handle, new_regs);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -4482,6 +4529,8 @@ df_commit_eval_value(E_Eval dst_eval, E_Eval src_eval)
|
||||
}
|
||||
|
||||
//- rjf: commit
|
||||
// TODO(rjf): @spaces
|
||||
#if 0
|
||||
if(result && commit_data.size != 0)
|
||||
{
|
||||
if(dst_eval.mode == E_Mode_Offset)
|
||||
@@ -4510,11 +4559,79 @@ df_commit_eval_value(E_Eval dst_eval, E_Eval src_eval)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal B32
|
||||
df_commit_eval_value_string(E_Eval dst_eval, String8 string)
|
||||
{
|
||||
B32 result = 0;
|
||||
if(dst_eval.mode == E_Mode_Offset)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
E_TypeKey type_key = e_type_unwrap(dst_eval.type_key);
|
||||
E_TypeKind type_kind = e_type_kind_from_key(type_key);
|
||||
E_TypeKey direct_type_key = e_type_unwrap(e_type_direct_from_key(e_type_unwrap(dst_eval.type_key)));
|
||||
E_TypeKind direct_type_kind = e_type_kind_from_key(direct_type_key);
|
||||
String8 commit_data = {0};
|
||||
B32 commit_at_ptr_dest = 0;
|
||||
if(E_TypeKind_FirstBasic <= type_kind && type_kind <= E_TypeKind_LastBasic)
|
||||
{
|
||||
E_Eval src_eval = e_eval_from_string(scratch.arena, string);
|
||||
commit_data = push_str8_copy(scratch.arena, str8_struct(&src_eval.value));
|
||||
commit_data.size = Min(commit_data.size, e_type_byte_size_from_key(type_key));
|
||||
}
|
||||
else if(type_kind == E_TypeKind_Ptr || type_kind == E_TypeKind_Array)
|
||||
{
|
||||
E_Eval src_eval = e_eval_from_string(scratch.arena, string);
|
||||
E_Eval src_eval_value = e_value_eval_from_eval(src_eval);
|
||||
E_TypeKind src_eval_value_type_kind = e_type_kind_from_key(src_eval_value.type_key);
|
||||
if(type_kind == E_TypeKind_Ptr &&
|
||||
(e_type_kind_is_pointer_or_ref(src_eval_value_type_kind) ||
|
||||
e_type_kind_is_integer(src_eval_value_type_kind)) &&
|
||||
src_eval_value.value.u64 != 0 && src_eval_value.mode == E_Mode_Value)
|
||||
{
|
||||
commit_data = push_str8_copy(scratch.arena, str8_struct(&src_eval.value));
|
||||
commit_data.size = Min(commit_data.size, e_type_byte_size_from_key(type_key));
|
||||
}
|
||||
else if(direct_type_kind == E_TypeKind_Char8 ||
|
||||
direct_type_kind == E_TypeKind_UChar8 ||
|
||||
e_type_kind_is_integer(direct_type_kind))
|
||||
{
|
||||
if(string.size >= 1 && string.str[0] == '"')
|
||||
{
|
||||
string = str8_skip(string, 1);
|
||||
}
|
||||
if(string.size >= 1 && string.str[string.size-1] == '"')
|
||||
{
|
||||
string = str8_chop(string, 1);
|
||||
}
|
||||
commit_data = e_raw_from_escaped_string(scratch.arena, string);
|
||||
commit_data.size += 1;
|
||||
if(type_kind == E_TypeKind_Ptr)
|
||||
{
|
||||
commit_at_ptr_dest = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(commit_data.size != 0 && e_type_byte_size_from_key(type_key) != 0)
|
||||
{
|
||||
U64 dst_offset = dst_eval.value.u64;
|
||||
if(dst_eval.mode == E_Mode_Offset && commit_at_ptr_dest)
|
||||
{
|
||||
E_Eval dst_value_eval = e_value_eval_from_eval(dst_eval);
|
||||
dst_offset = dst_value_eval.value.u64;
|
||||
}
|
||||
result = e_space_write(dst_eval.space, commit_data.str, r1u64(dst_offset, dst_offset + commit_data.size));
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//- rjf: type helpers
|
||||
|
||||
internal E_MemberArray
|
||||
@@ -8435,6 +8552,7 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt)
|
||||
E_ParseCtx *ctx = parse_ctx;
|
||||
ctx->ip_vaddr = rip_vaddr;
|
||||
ctx->ip_voff = rip_voff;
|
||||
ctx->ip_thread_space = (E_Space)thread;
|
||||
ctx->modules = eval_modules;
|
||||
ctx->modules_count = eval_modules_count;
|
||||
ctx->primary_module = eval_modules_primary;
|
||||
@@ -8491,20 +8609,16 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt)
|
||||
E_InterpretCtx *interpret_ctx = push_array(arena, E_InterpretCtx, 1);
|
||||
{
|
||||
E_InterpretCtx *ctx = interpret_ctx;
|
||||
ctx->space_read = df_eval_space_read;
|
||||
ctx->primary_space = eval_modules_primary->space;
|
||||
ctx->reg_arch = eval_modules_primary->arch;
|
||||
ctx->reg_size = regs_block_size_from_architecture(eval_modules_primary->arch);
|
||||
ctx->reg_data = push_array(arena, U8, ctx->reg_size);
|
||||
ctx->module_base = push_array(arena, U64, 1);
|
||||
ctx->module_base[0]= module->vaddr_rng.min;
|
||||
ctx->tls_base = push_array(arena, U64, 1);
|
||||
ctx->tls_base[0] = df_query_cached_tls_base_vaddr_from_process_root_rip(process, tls_root_vaddr, rip_vaddr);
|
||||
if(unwind_count < unwind.frames.count)
|
||||
{
|
||||
CTRL_UnwindFrame *f = &unwind.frames.v[unwind_count];
|
||||
MemoryCopy(ctx->reg_data, f->regs, ctx->reg_size);
|
||||
}
|
||||
ctx->space_read = df_eval_space_read;
|
||||
ctx->space_write = df_eval_space_write;
|
||||
ctx->primary_space = eval_modules_primary->space;
|
||||
ctx->reg_arch = eval_modules_primary->arch;
|
||||
ctx->reg_space = (E_Space)thread;
|
||||
ctx->reg_unwind_count = unwind_count;
|
||||
ctx->module_base = push_array(arena, U64, 1);
|
||||
ctx->module_base[0] = module->vaddr_rng.min;
|
||||
ctx->tls_base = push_array(arena, U64, 1);
|
||||
ctx->tls_base[0] = df_query_cached_tls_base_vaddr_from_process_root_rip(process, tls_root_vaddr, rip_vaddr);
|
||||
}
|
||||
e_select_interpret_ctx(interpret_ctx);
|
||||
|
||||
|
||||
@@ -1609,6 +1609,7 @@ internal B32 df_type_key_is_editable(E_TypeKey type_key);
|
||||
|
||||
//- rjf: writing values back to child processes
|
||||
internal B32 df_commit_eval_value(E_Eval dst_eval, E_Eval src_eval);
|
||||
internal B32 df_commit_eval_value_string(E_Eval dst_eval, String8 string);
|
||||
|
||||
//- rjf: type helpers
|
||||
internal E_MemberArray df_filtered_data_members_from_members_cfg_table(Arena *arena, E_MemberArray members, DF_CfgTable *cfg);
|
||||
|
||||
+6
-6
@@ -6135,7 +6135,8 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
|
||||
DF_ExpandKey parent_key = df_expand_key_make(5381, 1);
|
||||
DF_ExpandKey key = df_expand_key_make(df_hash_from_expand_key(parent_key), 1);
|
||||
DF_EvalVizBlockList viz_blocks = df_eval_viz_block_list_from_eval_view_expr_keys(scratch.arena, eval_view, &top_level_cfg_table, expr, parent_key, key);
|
||||
U32 default_radix = (eval.space == E_Space_Regs ? 16 : 10);
|
||||
DF_Entity *entity = eval.space ? (DF_Entity *)eval.space : &df_g_nil_entity;
|
||||
U32 default_radix = (entity->kind == DF_EntityKind_Thread ? 16 : 10);
|
||||
DF_EvalVizWindowedRowList viz_rows = df_eval_viz_windowed_row_list_from_viz_block_list(scratch.arena, eval_view, r1s64(0, 50), &viz_blocks);
|
||||
|
||||
//- rjf: animate
|
||||
@@ -6314,8 +6315,7 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
|
||||
if(ui_committed(sig))
|
||||
{
|
||||
String8 commit_string = str8(ws->hover_eval_txt_buffer, ws->hover_eval_txt_size);
|
||||
E_Eval write_eval = e_eval_from_string(scratch.arena, commit_string);
|
||||
B32 success = df_commit_eval_value(row_eval, write_eval);
|
||||
B32 success = df_commit_eval_value_string(row_eval, commit_string);
|
||||
if(success == 0)
|
||||
{
|
||||
DF_CmdParams params = df_cmd_params_from_window(ws);
|
||||
@@ -8383,9 +8383,11 @@ df_append_value_strings_from_eval(Arena *arena, DF_EvalVizStringFlags flags, U32
|
||||
|
||||
// rjf: special case: push strings for textual string content
|
||||
B32 did_content = 0;
|
||||
B32 did_string = 0;
|
||||
if(!did_content && ptee_has_string && !has_array)
|
||||
{
|
||||
did_content = 1;
|
||||
did_string = 1;
|
||||
U64 string_memory_addr = value_eval.value.u64;
|
||||
U64 element_size = e_type_byte_size_from_key(direct_type_key);
|
||||
U64 string_buffer_size = 1024;
|
||||
@@ -8415,14 +8417,12 @@ df_append_value_strings_from_eval(Arena *arena, DF_EvalVizStringFlags flags, U32
|
||||
}
|
||||
|
||||
// rjf: special case: push strings for symbols
|
||||
B32 did_string = 0;
|
||||
if(!did_content && symbol_name.size != 0 &&
|
||||
((type_kind == E_TypeKind_Ptr && direct_type_kind == E_TypeKind_Void) ||
|
||||
(type_kind == E_TypeKind_Ptr && direct_type_kind == E_TypeKind_Function) ||
|
||||
(type_kind == E_TypeKind_Function)))
|
||||
{
|
||||
did_content = 1;
|
||||
did_string = 1;
|
||||
str8_list_push(arena, out, symbol_name);
|
||||
space_taken += f_dim_from_tag_size_string(font, font_size, 0, 0, symbol_name).x;
|
||||
}
|
||||
@@ -8459,7 +8459,7 @@ df_append_value_strings_from_eval(Arena *arena, DF_EvalVizStringFlags flags, U32
|
||||
|
||||
// rjf: push pointer value
|
||||
B32 did_ptr_value = 0;
|
||||
if((!no_addr || !did_content) && (!(flags & DF_EvalVizStringFlag_ReadOnlyDisplayRules) || !did_string))
|
||||
if((!no_addr || !did_content) && ((flags & DF_EvalVizStringFlag_ReadOnlyDisplayRules) || !did_string))
|
||||
{
|
||||
did_ptr_value = 1;
|
||||
if(did_content)
|
||||
|
||||
+12
-10
@@ -1264,6 +1264,14 @@ df_string_from_eval_viz_row_column(Arena *arena, DF_EvalView *ev, DF_EvalVizRow
|
||||
result = df_value_string_from_eval(arena, !editable * DF_EvalVizStringFlag_ReadOnlyDisplayRules, default_radix, font, font_size, max_size_px, eval, row->member, row->cfg_table);
|
||||
}break;
|
||||
}
|
||||
if(col->dequote_string &&
|
||||
result.size >= 2 &&
|
||||
result.str[0] == '"' &&
|
||||
result.str[result.size-1] == '"')
|
||||
{
|
||||
result = str8_skip(str8_chop(result, 1), 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2169,10 +2177,12 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS
|
||||
|
||||
// rjf: commit edited cell string
|
||||
Vec2S64 tbl = v2s64(x, y);
|
||||
switch((DF_WatchViewColumnKind)x)
|
||||
DF_WatchViewColumn *col = df_watch_view_column_from_x(ewv, x);
|
||||
switch(col->kind)
|
||||
{
|
||||
default:{}break;
|
||||
case DF_WatchViewColumnKind_Expr:
|
||||
if(modifiable)
|
||||
{
|
||||
DF_WatchViewPoint pt = df_watch_view_point_from_tbl(&blocks, tbl);
|
||||
DF_Entity *watch = df_entity_from_expand_key_and_kind(pt.key, mutable_entity_kind);
|
||||
@@ -2202,8 +2212,7 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS
|
||||
if(rows.first != 0)
|
||||
{
|
||||
E_Eval dst_eval = e_eval_from_expr(scratch.arena, rows.first->expr);
|
||||
E_Eval src_eval = e_eval_from_string(scratch.arena, new_string);
|
||||
success = df_commit_eval_value(dst_eval, src_eval);
|
||||
success = df_commit_eval_value_string(dst_eval, new_string);
|
||||
}
|
||||
if(!success)
|
||||
{
|
||||
@@ -2800,13 +2809,6 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS
|
||||
DF_WatchViewTextEditState *cell_edit_state = df_watch_view_text_edit_state_from_pt(ewv, cell_pt);
|
||||
B32 cell_selected = (row_selected && selection_tbl.min.x <= cell_pt.x && cell_pt.x <= selection_tbl.max.x);
|
||||
String8 cell_pre_edit_string = df_string_from_eval_viz_row_column(scratch.arena, eval_view, row, col, 0, default_radix, ui_top_font(), ui_top_font_size(), row_string_max_size_px);
|
||||
if(col->dequote_string &&
|
||||
cell_pre_edit_string.size >= 2 &&
|
||||
cell_pre_edit_string.str[0] == '"' &&
|
||||
cell_pre_edit_string.str[cell_pre_edit_string.size-1] == '"')
|
||||
{
|
||||
cell_pre_edit_string = str8_skip(str8_chop(cell_pre_edit_string, 1), 1);
|
||||
}
|
||||
|
||||
//- rjf: unpack column-kind-specific info
|
||||
E_Eval cell_eval = row_eval;
|
||||
|
||||
@@ -45,7 +45,6 @@ e_autoresolved_eval_from_eval(E_Eval eval)
|
||||
e_interpret_ctx &&
|
||||
e_parse_ctx->modules_count > 0 &&
|
||||
e_interpret_ctx->module_base != 0 &&
|
||||
(eval.mode == E_Mode_Value || eval.space == E_Space_Regs) &&
|
||||
(e_type_key_match(eval.type_key, e_type_key_basic(E_TypeKind_S64)) ||
|
||||
e_type_key_match(eval.type_key, e_type_key_basic(E_TypeKind_U64)) ||
|
||||
e_type_key_match(eval.type_key, e_type_key_basic(E_TypeKind_S32)) ||
|
||||
@@ -152,7 +151,7 @@ e_value_eval_from_eval(E_Eval eval)
|
||||
{
|
||||
eval.mode = E_Mode_Value;
|
||||
}
|
||||
else if(e_interpret_ctx->space_read != 0)
|
||||
else
|
||||
{
|
||||
U64 type_byte_size = e_type_byte_size_from_key(type_key);
|
||||
Rng1U64 value_vaddr_range = r1u64(eval.value.u64, eval.value.u64 + type_byte_size);
|
||||
|
||||
@@ -78,7 +78,6 @@ typedef U64 E_Space;
|
||||
enum
|
||||
{
|
||||
E_Space_Null,
|
||||
E_Space_Regs,
|
||||
E_Space_FIXED_COUNT
|
||||
};
|
||||
|
||||
|
||||
+24
-19
@@ -28,18 +28,29 @@ e_space_read(E_Space space, void *out, Rng1U64 range)
|
||||
{
|
||||
case E_Space_FIXED_COUNT:
|
||||
case E_Space_Null:{}break;
|
||||
case E_Space_Regs:
|
||||
{
|
||||
Rng1U64 legal_range = r1u64(0, e_interpret_ctx->reg_size);
|
||||
Rng1U64 read_range = intersect_1u64(legal_range, range);
|
||||
U64 read_size = dim_1u64(read_range);
|
||||
MemoryCopy(out, (U8 *)e_interpret_ctx->reg_data + read_range.min, read_size);
|
||||
result = (read_size == dim_1u64(range));
|
||||
}break;
|
||||
default:
|
||||
if(e_interpret_ctx->space_read != 0)
|
||||
{
|
||||
result = e_interpret_ctx->space_read(e_interpret_ctx->space_read_user_data, space, out, range);
|
||||
result = e_interpret_ctx->space_read(e_interpret_ctx->space_rw_user_data, space, out, range);
|
||||
}break;
|
||||
}
|
||||
ProfEnd();
|
||||
return result;
|
||||
}
|
||||
|
||||
internal B32
|
||||
e_space_write(E_Space space, void *in, Rng1U64 range)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
B32 result = 0;
|
||||
switch(space)
|
||||
{
|
||||
case E_Space_FIXED_COUNT:
|
||||
case E_Space_Null:{}break;
|
||||
default:
|
||||
if(e_interpret_ctx->space_write != 0)
|
||||
{
|
||||
result = e_interpret_ctx->space_write(e_interpret_ctx->space_rw_user_data, space, in, range);
|
||||
}break;
|
||||
}
|
||||
ProfEnd();
|
||||
@@ -173,11 +184,8 @@ e_interpret(String8 bytecode)
|
||||
REGS_Rng rng = regs_reg_code_rng_table_from_architecture(e_interpret_ctx->reg_arch)[base_reg_code];
|
||||
U64 off = (U64)rng.byte_off + byte_off;
|
||||
U64 size = (U64)byte_size;
|
||||
if(off + size <= e_interpret_ctx->reg_size)
|
||||
{
|
||||
MemoryCopy(&nval, (U8*)e_interpret_ctx->reg_data + off, size);
|
||||
}
|
||||
else
|
||||
B32 good_read = e_space_read(e_interpret_ctx->reg_space, &nval, r1u64(off, off+size));
|
||||
if(!good_read)
|
||||
{
|
||||
result.code = E_InterpretationCode_BadRegRead;
|
||||
goto done;
|
||||
@@ -188,11 +196,8 @@ e_interpret(String8 bytecode)
|
||||
{
|
||||
U64 off = svals[0].u64;
|
||||
U64 size = bit_size_from_arch(e_interpret_ctx->reg_arch)/8;
|
||||
if(off + size <= e_interpret_ctx->reg_size)
|
||||
{
|
||||
MemoryCopy(&nval, (U8*)e_interpret_ctx->reg_data + off, size);
|
||||
}
|
||||
else
|
||||
B32 good_read = e_space_read(e_interpret_ctx->reg_space, &nval, r1u64(off, off+size));
|
||||
if(!good_read)
|
||||
{
|
||||
result.code = E_InterpretationCode_BadRegRead;
|
||||
goto done;
|
||||
|
||||
@@ -29,17 +29,18 @@ struct E_Interpretation
|
||||
////////////////////////////////
|
||||
//~ rjf: Interpretation Context
|
||||
|
||||
typedef B32 E_SpaceReadFunction(void *user_data, E_Space space, void *out, Rng1U64 offset_range);
|
||||
typedef B32 E_SpaceRWFunction(void *user_data, E_Space space, void *out, Rng1U64 offset_range);
|
||||
|
||||
typedef struct E_InterpretCtx E_InterpretCtx;
|
||||
struct E_InterpretCtx
|
||||
{
|
||||
void *space_read_user_data;
|
||||
E_SpaceReadFunction *space_read;
|
||||
void *space_rw_user_data;
|
||||
E_SpaceRWFunction *space_read;
|
||||
E_SpaceRWFunction *space_write;
|
||||
E_Space primary_space;
|
||||
Architecture reg_arch;
|
||||
void *reg_data;
|
||||
U64 reg_size;
|
||||
E_Space reg_space;
|
||||
U64 reg_unwind_count;
|
||||
U64 *module_base;
|
||||
U64 *frame_base;
|
||||
U64 *tls_base;
|
||||
@@ -60,6 +61,7 @@ internal void e_select_interpret_ctx(E_InterpretCtx *ctx);
|
||||
//~ rjf: Space Reading Helpers
|
||||
|
||||
internal B32 e_space_read(E_Space space, void *out, Rng1U64 range);
|
||||
internal B32 e_space_write(E_Space space, void *in, Rng1U64 range);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Interpretation Functions
|
||||
|
||||
+2
-5
@@ -363,10 +363,12 @@ e_irtree_resolve_to_value(Arena *arena, E_Space from_space, E_Mode from_mode, E_
|
||||
{
|
||||
switch(from_space)
|
||||
{
|
||||
#if 0
|
||||
case E_Space_Regs:
|
||||
{
|
||||
result = e_irtree_unary_op(arena, RDI_EvalOp_RegReadDyn, RDI_EvalTypeGroup_U, tree);
|
||||
}break;
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
result = e_irtree_mem_read_type(arena, from_space, tree, type_key);
|
||||
@@ -681,11 +683,6 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if(r_tree.mode != E_Mode_Offset || r_tree.space <= E_Space_Regs)
|
||||
{
|
||||
e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, r_expr->location, "Cannot take address of non-memory.");
|
||||
break;
|
||||
}
|
||||
|
||||
// rjf: generate
|
||||
result.root = r_tree.root;
|
||||
|
||||
@@ -1366,7 +1366,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
reg_code = reg_num;
|
||||
type_key = e_type_key_reg(e_parse_ctx->primary_module->arch, reg_code);
|
||||
mapped_identifier = 1;
|
||||
space = E_Space_Regs;
|
||||
space = e_parse_ctx->ip_thread_space;
|
||||
arch = e_parse_ctx->primary_module->arch;
|
||||
}
|
||||
}
|
||||
@@ -1380,7 +1380,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
alias_code = (REGS_AliasCode)alias_num;
|
||||
type_key = e_type_key_reg_alias(e_parse_ctx->primary_module->arch, alias_code);
|
||||
mapped_identifier = 1;
|
||||
space = E_Space_Regs;
|
||||
space = e_parse_ctx->ip_thread_space;
|
||||
arch = e_parse_ctx->primary_module->arch;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ struct E_ParseCtx
|
||||
// rjf: instruction pointer info
|
||||
U64 ip_vaddr;
|
||||
U64 ip_voff;
|
||||
E_Space ip_thread_space;
|
||||
|
||||
// rjf: modules
|
||||
E_Module *modules;
|
||||
|
||||
Reference in New Issue
Block a user