diff --git a/src/base/base_entry_point.c b/src/base/base_entry_point.c index db167e5a..a466e65d 100644 --- a/src/base/base_entry_point.c +++ b/src/base/base_entry_point.c @@ -72,8 +72,8 @@ main_thread_base_entry_point(int arguments_count, char **arguments) #if defined(DEMON_CORE_H) && !defined(DMN_INIT_MANUAL) dmn_init(); #endif -#if defined(CTRL_CORE_H) && !defined(CTRL_INIT_MANUAL) - ctrl_init(); +#if defined(DBG_ENGINE_CORE_H) && !defined(D_INIT_MANUAL) + d_init(); #endif #if defined(OS_GFX_H) && !defined(OS_GFX_INIT_MANUAL) os_gfx_init(); @@ -87,9 +87,6 @@ main_thread_base_entry_point(int arguments_count, char **arguments) #if defined(FONT_CACHE_H) && !defined(FNT_INIT_MANUAL) fnt_init(); #endif -#if defined(DBG_ENGINE_CORE_H) && !defined(D_INIT_MANUAL) - d_init(); -#endif #if defined(RADDBG_CORE_H) && !defined(RD_INIT_MANUAL) rd_init(&cmdline); #endif diff --git a/src/dbg_engine/dbg_engine_core.c b/src/dbg_engine/dbg_engine_core.c index d2143055..f61aaff8 100644 --- a/src/dbg_engine/dbg_engine_core.c +++ b/src/dbg_engine/dbg_engine_core.c @@ -5,3 +5,116 @@ //~ rjf: Generated Code #include "generated/dbg_engine.meta.c" + +//////////////////////////////// +//~ rjf: Layer Initialization + +internal void +d_init(void) +{ + //- rjf: set up ctrl state + { + Arena *arena = arena_alloc(); + d_ctrl_state = push_array(arena, D_CtrlState, 1); + d_ctrl_state->arena = arena; + for(Arch arch = (Arch)0; arch < Arch_COUNT; arch = (Arch)(arch+1)) + { + String8 *reg_names = regs_reg_code_string_table_from_arch(arch); + U64 reg_count = regs_reg_code_count_from_arch(arch); + String8 *alias_names = regs_alias_code_string_table_from_arch(arch); + U64 alias_count = regs_alias_code_count_from_arch(arch); + d_ctrl_state->arch_string2reg_tables[arch] = e_string2num_map_make(d_ctrl_state->arena, 256); + d_ctrl_state->arch_string2alias_tables[arch] = e_string2num_map_make(d_ctrl_state->arena, 256); + for(U64 idx = 1; idx < reg_count; idx += 1) + { + e_string2num_map_insert(d_ctrl_state->arena, &d_ctrl_state->arch_string2reg_tables[arch], reg_names[idx], idx); + } + for(U64 idx = 1; idx < alias_count; idx += 1) + { + e_string2num_map_insert(d_ctrl_state->arena, &d_ctrl_state->arch_string2alias_tables[arch], alias_names[idx], idx); + } + } + d_ctrl_state->thread_reg_cache.slots_count = 1024; + d_ctrl_state->thread_reg_cache.slots = push_array(arena, CTRL_ThreadRegCacheSlot, d_ctrl_state->thread_reg_cache.slots_count); + d_ctrl_state->thread_reg_cache.stripes_count = os_get_system_info()->logical_processor_count; + d_ctrl_state->thread_reg_cache.stripes = push_array(arena, CTRL_ThreadRegCacheStripe, d_ctrl_state->thread_reg_cache.stripes_count); + for(U64 idx = 0; idx < d_ctrl_state->thread_reg_cache.stripes_count; idx += 1) + { + d_ctrl_state->thread_reg_cache.stripes[idx].arena = arena_alloc(); + d_ctrl_state->thread_reg_cache.stripes[idx].rw_mutex = rw_mutex_alloc(); + } + d_ctrl_state->module_image_info_cache.slots_count = 1024; + d_ctrl_state->module_image_info_cache.slots = push_array(arena, CTRL_ModuleImageInfoCacheSlot, d_ctrl_state->module_image_info_cache.slots_count); + d_ctrl_state->module_image_info_cache.stripes_count = os_get_system_info()->logical_processor_count; + d_ctrl_state->module_image_info_cache.stripes = push_array(arena, CTRL_ModuleImageInfoCacheStripe, d_ctrl_state->module_image_info_cache.stripes_count); + for(U64 idx = 0; idx < d_ctrl_state->module_image_info_cache.stripes_count; idx += 1) + { + d_ctrl_state->module_image_info_cache.stripes[idx].arena = arena_alloc(); + d_ctrl_state->module_image_info_cache.stripes[idx].rw_mutex = rw_mutex_alloc(); + } + d_ctrl_state->u2c_ring_size = KB(64); + d_ctrl_state->u2c_ring_base = push_array_no_zero(arena, U8, d_ctrl_state->u2c_ring_size); + d_ctrl_state->u2c_ring_mutex = mutex_alloc(); + d_ctrl_state->u2c_ring_cv = cond_var_alloc(); + d_ctrl_state->c2u_ring_size = KB(64); + d_ctrl_state->c2u_ring_max_string_size = d_ctrl_state->c2u_ring_size/2; + d_ctrl_state->c2u_ring_base = push_array_no_zero(arena, U8, d_ctrl_state->c2u_ring_size); + d_ctrl_state->c2u_ring_mutex = mutex_alloc(); + d_ctrl_state->c2u_ring_cv = cond_var_alloc(); + { + Temp scratch = scratch_begin(0, 0); + String8 user_program_data_path = os_get_process_info()->user_program_data_path; + String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path); + os_make_directory(user_data_folder); + d_ctrl_state->ctrl_thread_log_path = push_str8f(d_ctrl_state->arena, "%S/ctrl_thread.raddbg_log", user_data_folder); + os_write_data_to_file_path(d_ctrl_state->ctrl_thread_log_path, str8_zero()); + scratch_end(scratch); + } + d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex = rw_mutex_alloc(); + d_ctrl_state->ctrl_thread_entity_store = ctrl_entity_ctx_rw_store_alloc(); + d_ctrl_state->ctrl_thread_eval_cache = e_cache_alloc(); + d_ctrl_state->ctrl_thread_msg_process_arena = arena_alloc(); + d_ctrl_state->dmn_event_arena = arena_alloc(); + d_ctrl_state->user_entry_point_arena = arena_alloc(); + d_ctrl_state->dbg_dir_arena = arena_alloc(); + for(CTRL_ExceptionCodeKind k = (CTRL_ExceptionCodeKind)0; k < CTRL_ExceptionCodeKind_COUNT; k = (CTRL_ExceptionCodeKind)(k+1)) + { + if(ctrl_exception_code_kind_default_enable_table[k]) + { + d_ctrl_state->exception_code_filters[k/64] |= 1ull<<(k%64); + } + } + d_ctrl_state->ctrl_thread_log = log_alloc(); + d_ctrl_state->ctrl_thread = thread_launch(ctrl_thread__entry_point, 0); + } + + //- rjf: set up user state + { + Arena *arena = arena_alloc(); + d_user_state = push_array(arena, D_UserState, 1); + d_user_state->arena = arena; + d_user_state->cmds_arena = arena_alloc(); + d_user_state->output_log_key = c_key_make(c_root_alloc(), c_id_make(0, 0)); + c_submit_data(d_user_state->output_log_key, 0, str8_zero()); + d_user_state->ctrl_entity_store = ctrl_entity_ctx_rw_store_alloc(); + d_user_state->ctrl_stop_arena = arena_alloc(); + d_user_state->ctrl_msg_arena = arena_alloc(); + + // rjf: set up caches + for(U64 idx = 0; idx < ArrayCount(d_user_state->tls_base_caches); idx += 1) + { + d_user_state->tls_base_caches[idx].arena = arena_alloc(); + } + for(U64 idx = 0; idx < ArrayCount(d_user_state->locals_caches); idx += 1) + { + d_user_state->locals_caches[idx].arena = arena_alloc(); + } + for(U64 idx = 0; idx < ArrayCount(d_user_state->member_caches); idx += 1) + { + d_user_state->member_caches[idx].arena = arena_alloc(); + } + + // rjf: set up run state + d_user_state->ctrl_last_run_arena = arena_alloc(); + } +} diff --git a/src/dbg_engine/dbg_engine_core.h b/src/dbg_engine/dbg_engine_core.h index 6fe61679..c133cf57 100644 --- a/src/dbg_engine/dbg_engine_core.h +++ b/src/dbg_engine/dbg_engine_core.h @@ -399,4 +399,9 @@ struct D_TrapNet B32 good_read; }; +//////////////////////////////// +//~ rjf: Layer Initialization + +internal void d_init(void); + #endif // DBG_ENGINE_CORE_H diff --git a/src/dbg_engine/dbg_engine_ctrl.c b/src/dbg_engine/dbg_engine_ctrl.c index 32357e0e..1f046cb2 100644 --- a/src/dbg_engine/dbg_engine_ctrl.c +++ b/src/dbg_engine/dbg_engine_ctrl.c @@ -1465,93 +1465,13 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis } } -//////////////////////////////// -//~ rjf: Main Layer Initialization - -internal void -ctrl_init(void) -{ - Arena *arena = arena_alloc(); - ctrl_state = push_array(arena, CTRL_State, 1); - ctrl_state->arena = arena; - for(Arch arch = (Arch)0; arch < Arch_COUNT; arch = (Arch)(arch+1)) - { - String8 *reg_names = regs_reg_code_string_table_from_arch(arch); - U64 reg_count = regs_reg_code_count_from_arch(arch); - String8 *alias_names = regs_alias_code_string_table_from_arch(arch); - U64 alias_count = regs_alias_code_count_from_arch(arch); - ctrl_state->arch_string2reg_tables[arch] = e_string2num_map_make(ctrl_state->arena, 256); - ctrl_state->arch_string2alias_tables[arch] = e_string2num_map_make(ctrl_state->arena, 256); - for(U64 idx = 1; idx < reg_count; idx += 1) - { - e_string2num_map_insert(ctrl_state->arena, &ctrl_state->arch_string2reg_tables[arch], reg_names[idx], idx); - } - for(U64 idx = 1; idx < alias_count; idx += 1) - { - e_string2num_map_insert(ctrl_state->arena, &ctrl_state->arch_string2alias_tables[arch], alias_names[idx], idx); - } - } - ctrl_state->thread_reg_cache.slots_count = 1024; - ctrl_state->thread_reg_cache.slots = push_array(arena, CTRL_ThreadRegCacheSlot, ctrl_state->thread_reg_cache.slots_count); - ctrl_state->thread_reg_cache.stripes_count = os_get_system_info()->logical_processor_count; - ctrl_state->thread_reg_cache.stripes = push_array(arena, CTRL_ThreadRegCacheStripe, ctrl_state->thread_reg_cache.stripes_count); - for(U64 idx = 0; idx < ctrl_state->thread_reg_cache.stripes_count; idx += 1) - { - ctrl_state->thread_reg_cache.stripes[idx].arena = arena_alloc(); - ctrl_state->thread_reg_cache.stripes[idx].rw_mutex = rw_mutex_alloc(); - } - ctrl_state->module_image_info_cache.slots_count = 1024; - ctrl_state->module_image_info_cache.slots = push_array(arena, CTRL_ModuleImageInfoCacheSlot, ctrl_state->module_image_info_cache.slots_count); - ctrl_state->module_image_info_cache.stripes_count = os_get_system_info()->logical_processor_count; - ctrl_state->module_image_info_cache.stripes = push_array(arena, CTRL_ModuleImageInfoCacheStripe, ctrl_state->module_image_info_cache.stripes_count); - for(U64 idx = 0; idx < ctrl_state->module_image_info_cache.stripes_count; idx += 1) - { - ctrl_state->module_image_info_cache.stripes[idx].arena = arena_alloc(); - ctrl_state->module_image_info_cache.stripes[idx].rw_mutex = rw_mutex_alloc(); - } - ctrl_state->u2c_ring_size = KB(64); - ctrl_state->u2c_ring_base = push_array_no_zero(arena, U8, ctrl_state->u2c_ring_size); - ctrl_state->u2c_ring_mutex = mutex_alloc(); - ctrl_state->u2c_ring_cv = cond_var_alloc(); - ctrl_state->c2u_ring_size = KB(64); - ctrl_state->c2u_ring_max_string_size = ctrl_state->c2u_ring_size/2; - ctrl_state->c2u_ring_base = push_array_no_zero(arena, U8, ctrl_state->c2u_ring_size); - ctrl_state->c2u_ring_mutex = mutex_alloc(); - ctrl_state->c2u_ring_cv = cond_var_alloc(); - { - Temp scratch = scratch_begin(0, 0); - String8 user_program_data_path = os_get_process_info()->user_program_data_path; - String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path); - os_make_directory(user_data_folder); - ctrl_state->ctrl_thread_log_path = push_str8f(ctrl_state->arena, "%S/ctrl_thread.raddbg_log", user_data_folder); - os_write_data_to_file_path(ctrl_state->ctrl_thread_log_path, str8_zero()); - scratch_end(scratch); - } - ctrl_state->ctrl_thread_entity_ctx_rw_mutex = rw_mutex_alloc(); - ctrl_state->ctrl_thread_entity_store = ctrl_entity_ctx_rw_store_alloc(); - ctrl_state->ctrl_thread_eval_cache = e_cache_alloc(); - ctrl_state->ctrl_thread_msg_process_arena = arena_alloc(); - ctrl_state->dmn_event_arena = arena_alloc(); - ctrl_state->user_entry_point_arena = arena_alloc(); - ctrl_state->dbg_dir_arena = arena_alloc(); - for(CTRL_ExceptionCodeKind k = (CTRL_ExceptionCodeKind)0; k < CTRL_ExceptionCodeKind_COUNT; k = (CTRL_ExceptionCodeKind)(k+1)) - { - if(ctrl_exception_code_kind_default_enable_table[k]) - { - ctrl_state->exception_code_filters[k/64] |= 1ull<<(k%64); - } - } - ctrl_state->ctrl_thread_log = log_alloc(); - ctrl_state->ctrl_thread = thread_launch(ctrl_thread__entry_point, 0); -} - //////////////////////////////// //~ rjf: Wakeup Callback Registration internal void ctrl_set_wakeup_hook(CTRL_WakeupFunctionType *wakeup_hook) { - ctrl_state->wakeup_hook = wakeup_hook; + d_ctrl_state->wakeup_hook = wakeup_hook; } //////////////////////////////// @@ -1562,7 +1482,7 @@ ctrl_set_wakeup_hook(CTRL_WakeupFunctionType *wakeup_hook) internal void * ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle handle) { - CTRL_ThreadRegCache *cache = &ctrl_state->thread_reg_cache; + CTRL_ThreadRegCache *cache = &d_ctrl_state->thread_reg_cache; CTRL_Entity *thread_entity = ctrl_entity_from_handle(ctx, handle); Arch arch = thread_entity->arch; U64 reg_block_size = regs_block_size_from_arch(arch); @@ -1659,7 +1579,7 @@ ctrl_thread_write_reg_block(CTRL_Handle thread, void *block) B32 good = dmn_thread_write_reg_block(thread.dmn_handle, block); if(good) { - ins_atomic_u64_inc_eval(&ctrl_state->reg_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->reg_gen); } return good; } @@ -1675,10 +1595,10 @@ ctrl_intel_pdata_from_module_voff(Arena *arena, CTRL_Handle module_handle, U64 v PE_IntelPdata *first_pdata = 0; { U64 hash = ctrl_hash_from_handle(module_handle); - U64 slot_idx = hash%ctrl_state->module_image_info_cache.slots_count; - U64 stripe_idx = slot_idx%ctrl_state->module_image_info_cache.stripes_count; - CTRL_ModuleImageInfoCacheSlot *slot = &ctrl_state->module_image_info_cache.slots[slot_idx]; - CTRL_ModuleImageInfoCacheStripe *stripe = &ctrl_state->module_image_info_cache.stripes[stripe_idx]; + U64 slot_idx = hash%d_ctrl_state->module_image_info_cache.slots_count; + U64 stripe_idx = slot_idx%d_ctrl_state->module_image_info_cache.stripes_count; + CTRL_ModuleImageInfoCacheSlot *slot = &d_ctrl_state->module_image_info_cache.slots[slot_idx]; + CTRL_ModuleImageInfoCacheStripe *stripe = &d_ctrl_state->module_image_info_cache.stripes[stripe_idx]; MutexScopeR(stripe->rw_mutex) for(CTRL_ModuleImageInfoCacheNode *n = slot->first; n != 0; n = n->next) { if(ctrl_handle_match(n->module, module_handle)) @@ -1741,10 +1661,10 @@ ctrl_entry_point_voff_from_module(CTRL_Handle module_handle) { U64 result = 0; U64 hash = ctrl_hash_from_handle(module_handle); - U64 slot_idx = hash%ctrl_state->module_image_info_cache.slots_count; - U64 stripe_idx = slot_idx%ctrl_state->module_image_info_cache.stripes_count; - CTRL_ModuleImageInfoCacheSlot *slot = &ctrl_state->module_image_info_cache.slots[slot_idx]; - CTRL_ModuleImageInfoCacheStripe *stripe = &ctrl_state->module_image_info_cache.stripes[stripe_idx]; + U64 slot_idx = hash%d_ctrl_state->module_image_info_cache.slots_count; + U64 stripe_idx = slot_idx%d_ctrl_state->module_image_info_cache.stripes_count; + CTRL_ModuleImageInfoCacheSlot *slot = &d_ctrl_state->module_image_info_cache.slots[slot_idx]; + CTRL_ModuleImageInfoCacheStripe *stripe = &d_ctrl_state->module_image_info_cache.stripes[stripe_idx]; MutexScopeR(stripe->rw_mutex) for(CTRL_ModuleImageInfoCacheNode *n = slot->first; n != 0; n = n->next) { if(ctrl_handle_match(n->module, module_handle)) @@ -1761,10 +1681,10 @@ ctrl_initial_debug_info_path_from_module(Arena *arena, CTRL_Handle module_handle { String8 result = {0}; U64 hash = ctrl_hash_from_handle(module_handle); - U64 slot_idx = hash%ctrl_state->module_image_info_cache.slots_count; - U64 stripe_idx = slot_idx%ctrl_state->module_image_info_cache.stripes_count; - CTRL_ModuleImageInfoCacheSlot *slot = &ctrl_state->module_image_info_cache.slots[slot_idx]; - CTRL_ModuleImageInfoCacheStripe *stripe = &ctrl_state->module_image_info_cache.stripes[stripe_idx]; + U64 slot_idx = hash%d_ctrl_state->module_image_info_cache.slots_count; + U64 stripe_idx = slot_idx%d_ctrl_state->module_image_info_cache.stripes_count; + CTRL_ModuleImageInfoCacheSlot *slot = &d_ctrl_state->module_image_info_cache.slots[slot_idx]; + CTRL_ModuleImageInfoCacheStripe *stripe = &d_ctrl_state->module_image_info_cache.stripes[stripe_idx]; MutexScopeR(stripe->rw_mutex) for(CTRL_ModuleImageInfoCacheNode *n = slot->first; n != 0; n = n->next) { if(ctrl_handle_match(n->module, module_handle)) @@ -1781,10 +1701,10 @@ ctrl_raddbg_data_from_module(Arena *arena, CTRL_Handle module_handle) { String8 result = {0}; U64 hash = ctrl_hash_from_handle(module_handle); - U64 slot_idx = hash%ctrl_state->module_image_info_cache.slots_count; - U64 stripe_idx = slot_idx%ctrl_state->module_image_info_cache.stripes_count; - CTRL_ModuleImageInfoCacheSlot *slot = &ctrl_state->module_image_info_cache.slots[slot_idx]; - CTRL_ModuleImageInfoCacheStripe *stripe = &ctrl_state->module_image_info_cache.stripes[stripe_idx]; + U64 slot_idx = hash%d_ctrl_state->module_image_info_cache.slots_count; + U64 stripe_idx = slot_idx%d_ctrl_state->module_image_info_cache.stripes_count; + CTRL_ModuleImageInfoCacheSlot *slot = &d_ctrl_state->module_image_info_cache.slots[slot_idx]; + CTRL_ModuleImageInfoCacheStripe *stripe = &d_ctrl_state->module_image_info_cache.stripes[stripe_idx]; MutexScopeR(stripe->rw_mutex) for(CTRL_ModuleImageInfoCacheNode *n = slot->first; n != 0; n = n->next) { if(ctrl_handle_match(n->module, module_handle)) @@ -1802,7 +1722,7 @@ ctrl_raddbg_data_from_module(Arena *arena, CTRL_Handle module_handle) internal Arch ctrl_arch_from_process_handle(CTRL_Handle process_handle) { - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; CTRL_Entity *process_entity = ctrl_entity_from_handle(entity_ctx, process_handle); return process_entity->arch; } @@ -1899,10 +1819,10 @@ ctrl_establish_frame_unwind_context__dwarf(Arena *arena, CTRL_Handle process_han EH_PtrCtx eh_ptr_ctx = {0}; { U64 hash = ctrl_hash_from_handle(module_handle); - U64 slot_idx = hash % ctrl_state->module_image_info_cache.slots_count; - U64 stripe_idx = slot_idx % ctrl_state->module_image_info_cache.stripes_count; - CTRL_ModuleImageInfoCacheSlot *slot = &ctrl_state->module_image_info_cache.slots[slot_idx]; - CTRL_ModuleImageInfoCacheStripe *stripe = &ctrl_state->module_image_info_cache.stripes[stripe_idx]; + U64 slot_idx = hash % d_ctrl_state->module_image_info_cache.slots_count; + U64 stripe_idx = slot_idx % d_ctrl_state->module_image_info_cache.stripes_count; + CTRL_ModuleImageInfoCacheSlot *slot = &d_ctrl_state->module_image_info_cache.slots[slot_idx]; + CTRL_ModuleImageInfoCacheStripe *stripe = &d_ctrl_state->module_image_info_cache.stripes[stripe_idx]; MutexScopeR(stripe->rw_mutex) for EachNode(n, CTRL_ModuleImageInfoCacheNode, slot->first) { if(ctrl_handle_match(n->module, module_handle)) @@ -3255,21 +3175,21 @@ ctrl_halt(void) internal U64 ctrl_run_gen(void) { - U64 result = ins_atomic_u64_eval(&ctrl_state->run_gen); + U64 result = ins_atomic_u64_eval(&d_ctrl_state->run_gen); return result; } internal U64 ctrl_mem_gen(void) { - U64 result = ins_atomic_u64_eval(&ctrl_state->mem_gen); + U64 result = ins_atomic_u64_eval(&d_ctrl_state->mem_gen); return result; } internal U64 ctrl_reg_gen(void) { - U64 result = ins_atomic_u64_eval(&ctrl_state->reg_gen); + U64 result = ins_atomic_u64_eval(&d_ctrl_state->reg_gen); return result; } @@ -3278,13 +3198,13 @@ ctrl_reg_gen(void) internal E_String2NumMap * ctrl_string2reg_from_arch(Arch arch) { - return &ctrl_state->arch_string2reg_tables[arch]; + return &d_ctrl_state->arch_string2reg_tables[arch]; } internal E_String2NumMap * ctrl_string2alias_from_arch(Arch arch) { - return &ctrl_state->arch_string2alias_tables[arch]; + return &d_ctrl_state->arch_string2alias_tables[arch]; } //////////////////////////////// @@ -3298,15 +3218,15 @@ ctrl_u2c_push_msgs(CTRL_MsgList *msgs, U64 endt_us) Temp scratch = scratch_begin(0, 0); String8 msgs_srlzed_baked = ctrl_serialized_string_from_msg_list(scratch.arena, msgs); B32 good = 0; - MutexScope(ctrl_state->u2c_ring_mutex) for(;;) + MutexScope(d_ctrl_state->u2c_ring_mutex) for(;;) { - U64 unconsumed_size = (ctrl_state->u2c_ring_write_pos-ctrl_state->u2c_ring_read_pos); - U64 available_size = ctrl_state->u2c_ring_size-unconsumed_size; + U64 unconsumed_size = (d_ctrl_state->u2c_ring_write_pos-d_ctrl_state->u2c_ring_read_pos); + U64 available_size = d_ctrl_state->u2c_ring_size-unconsumed_size; U64 needed_size = sizeof(msgs_srlzed_baked.size) + msgs_srlzed_baked.size; if(available_size >= needed_size) { - ctrl_state->u2c_ring_write_pos += ring_write_struct(ctrl_state->u2c_ring_base, ctrl_state->u2c_ring_size, ctrl_state->u2c_ring_write_pos, &msgs_srlzed_baked.size); - ctrl_state->u2c_ring_write_pos += ring_write(ctrl_state->u2c_ring_base, ctrl_state->u2c_ring_size, ctrl_state->u2c_ring_write_pos, msgs_srlzed_baked.str, msgs_srlzed_baked.size); + d_ctrl_state->u2c_ring_write_pos += ring_write_struct(d_ctrl_state->u2c_ring_base, d_ctrl_state->u2c_ring_size, d_ctrl_state->u2c_ring_write_pos, &msgs_srlzed_baked.size); + d_ctrl_state->u2c_ring_write_pos += ring_write(d_ctrl_state->u2c_ring_base, d_ctrl_state->u2c_ring_size, d_ctrl_state->u2c_ring_write_pos, msgs_srlzed_baked.str, msgs_srlzed_baked.size); good = 1; break; } @@ -3314,11 +3234,11 @@ ctrl_u2c_push_msgs(CTRL_MsgList *msgs, U64 endt_us) { break; } - cond_var_wait(ctrl_state->u2c_ring_cv, ctrl_state->u2c_ring_mutex, endt_us); + cond_var_wait(d_ctrl_state->u2c_ring_cv, d_ctrl_state->u2c_ring_mutex, endt_us); } if(good) { - cond_var_broadcast(ctrl_state->u2c_ring_cv); + cond_var_broadcast(d_ctrl_state->u2c_ring_cv); } scratch_end(scratch); return good; @@ -3329,21 +3249,21 @@ ctrl_u2c_pop_msgs(Arena *arena) { Temp scratch = scratch_begin(&arena, 1); String8 msgs_srlzed_baked = {0}; - MutexScope(ctrl_state->u2c_ring_mutex) for(;;) + MutexScope(d_ctrl_state->u2c_ring_mutex) for(;;) { - U64 unconsumed_size = (ctrl_state->u2c_ring_write_pos-ctrl_state->u2c_ring_read_pos); + U64 unconsumed_size = (d_ctrl_state->u2c_ring_write_pos-d_ctrl_state->u2c_ring_read_pos); if(unconsumed_size >= sizeof(U64)) { U64 size_to_decode = 0; - ctrl_state->u2c_ring_read_pos += ring_read_struct(ctrl_state->u2c_ring_base, ctrl_state->u2c_ring_size, ctrl_state->u2c_ring_read_pos, &size_to_decode); + d_ctrl_state->u2c_ring_read_pos += ring_read_struct(d_ctrl_state->u2c_ring_base, d_ctrl_state->u2c_ring_size, d_ctrl_state->u2c_ring_read_pos, &size_to_decode); msgs_srlzed_baked.size = size_to_decode; msgs_srlzed_baked.str = push_array_no_zero(scratch.arena, U8, msgs_srlzed_baked.size); - ctrl_state->u2c_ring_read_pos += ring_read(ctrl_state->u2c_ring_base, ctrl_state->u2c_ring_size, ctrl_state->u2c_ring_read_pos, msgs_srlzed_baked.str, size_to_decode); + d_ctrl_state->u2c_ring_read_pos += ring_read(d_ctrl_state->u2c_ring_base, d_ctrl_state->u2c_ring_size, d_ctrl_state->u2c_ring_read_pos, msgs_srlzed_baked.str, size_to_decode); break; } - cond_var_wait(ctrl_state->u2c_ring_cv, ctrl_state->u2c_ring_mutex, max_U64); + cond_var_wait(d_ctrl_state->u2c_ring_cv, d_ctrl_state->u2c_ring_mutex, max_U64); } - cond_var_broadcast(ctrl_state->u2c_ring_cv); + cond_var_broadcast(d_ctrl_state->u2c_ring_cv); CTRL_MsgList msgs = ctrl_msg_list_from_serialized_string(arena, msgs_srlzed_baked); scratch_end(scratch); return msgs; @@ -3356,31 +3276,31 @@ ctrl_c2u_push_events(CTRL_EventList *events) { if(events->count != 0) ProfScope("ctrl_c2u_push_events") { - MutexScopeW(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) + MutexScopeW(d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex) { - ctrl_entity_store_apply_events(ctrl_state->ctrl_thread_entity_store, events); + ctrl_entity_store_apply_events(d_ctrl_state->ctrl_thread_entity_store, events); } for(CTRL_EventNode *n = events->first; n != 0; n = n ->next) { Temp scratch = scratch_begin(0, 0); - String8 event_srlzed = ctrl_serialized_string_from_event(scratch.arena, &n->v, ctrl_state->c2u_ring_size-sizeof(U64)); - MutexScope(ctrl_state->c2u_ring_mutex) for(;;) + String8 event_srlzed = ctrl_serialized_string_from_event(scratch.arena, &n->v, d_ctrl_state->c2u_ring_size-sizeof(U64)); + MutexScope(d_ctrl_state->c2u_ring_mutex) for(;;) { - U64 unconsumed_size = (ctrl_state->c2u_ring_write_pos-ctrl_state->c2u_ring_read_pos); - U64 available_size = ctrl_state->c2u_ring_size-unconsumed_size; + U64 unconsumed_size = (d_ctrl_state->c2u_ring_write_pos-d_ctrl_state->c2u_ring_read_pos); + U64 available_size = d_ctrl_state->c2u_ring_size-unconsumed_size; U64 needed_size = sizeof(event_srlzed.size) + event_srlzed.size; if(available_size >= needed_size) { - ctrl_state->c2u_ring_write_pos += ring_write_struct(ctrl_state->c2u_ring_base, ctrl_state->c2u_ring_size, ctrl_state->c2u_ring_write_pos, &event_srlzed.size); - ctrl_state->c2u_ring_write_pos += ring_write(ctrl_state->c2u_ring_base, ctrl_state->c2u_ring_size, ctrl_state->c2u_ring_write_pos, event_srlzed.str, event_srlzed.size); + d_ctrl_state->c2u_ring_write_pos += ring_write_struct(d_ctrl_state->c2u_ring_base, d_ctrl_state->c2u_ring_size, d_ctrl_state->c2u_ring_write_pos, &event_srlzed.size); + d_ctrl_state->c2u_ring_write_pos += ring_write(d_ctrl_state->c2u_ring_base, d_ctrl_state->c2u_ring_size, d_ctrl_state->c2u_ring_write_pos, event_srlzed.str, event_srlzed.size); break; } - cond_var_wait(ctrl_state->c2u_ring_cv, ctrl_state->c2u_ring_mutex, os_now_microseconds()+100); + cond_var_wait(d_ctrl_state->c2u_ring_cv, d_ctrl_state->c2u_ring_mutex, os_now_microseconds()+100); } - cond_var_broadcast(ctrl_state->c2u_ring_cv); - if(ctrl_state->wakeup_hook != 0) + cond_var_broadcast(d_ctrl_state->c2u_ring_cv); + if(d_ctrl_state->wakeup_hook != 0) { - ctrl_state->wakeup_hook(); + d_ctrl_state->wakeup_hook(); } scratch_end(scratch); } @@ -3393,17 +3313,17 @@ ctrl_c2u_pop_events(Arena *arena) ProfBeginFunction(); Temp scratch = scratch_begin(&arena, 1); CTRL_EventList events = {0}; - MutexScope(ctrl_state->c2u_ring_mutex) for(;;) + MutexScope(d_ctrl_state->c2u_ring_mutex) for(;;) { - U64 unconsumed_size = (ctrl_state->c2u_ring_write_pos-ctrl_state->c2u_ring_read_pos); + U64 unconsumed_size = (d_ctrl_state->c2u_ring_write_pos-d_ctrl_state->c2u_ring_read_pos); if(unconsumed_size >= sizeof(U64)) { U64 size_to_decode = 0; - ctrl_state->c2u_ring_read_pos += ring_read_struct(ctrl_state->c2u_ring_base, ctrl_state->c2u_ring_size, ctrl_state->c2u_ring_read_pos, &size_to_decode); + d_ctrl_state->c2u_ring_read_pos += ring_read_struct(d_ctrl_state->c2u_ring_base, d_ctrl_state->c2u_ring_size, d_ctrl_state->c2u_ring_read_pos, &size_to_decode); String8 event_srlzed = {0}; event_srlzed.size = size_to_decode; event_srlzed.str = push_array_no_zero(scratch.arena, U8, event_srlzed.size); - ctrl_state->c2u_ring_read_pos += ring_read(ctrl_state->c2u_ring_base, ctrl_state->c2u_ring_size, ctrl_state->c2u_ring_read_pos, event_srlzed.str, event_srlzed.size); + d_ctrl_state->c2u_ring_read_pos += ring_read(d_ctrl_state->c2u_ring_base, d_ctrl_state->c2u_ring_size, d_ctrl_state->c2u_ring_read_pos, event_srlzed.str, event_srlzed.size); CTRL_Event *new_event = ctrl_event_list_push(arena, &events); *new_event = ctrl_event_from_serialized_string(arena, event_srlzed); } @@ -3412,7 +3332,7 @@ ctrl_c2u_pop_events(Arena *arena) break; } } - cond_var_broadcast(ctrl_state->c2u_ring_cv); + cond_var_broadcast(d_ctrl_state->c2u_ring_cv); scratch_end(scratch); ProfEnd(); return events; @@ -3426,7 +3346,7 @@ ctrl_thread__entry_point(void *p) ThreadNameF("ctrl_thread"); ProfBeginFunction(); DMN_CtrlCtx *ctrl_ctx = dmn_ctrl_begin(); - log_select(ctrl_state->ctrl_thread_log); + log_select(d_ctrl_state->ctrl_thread_log); //- rjf: loop Temp scratch = scratch_begin(0, 0); @@ -3441,7 +3361,7 @@ ctrl_thread__entry_point(void *p) //- rjf: process messages DMN_CtrlExclusiveAccessScope { - ins_atomic_u64_eval_assign(&ctrl_state->ctrl_thread_run_state, 1); + ins_atomic_u64_eval_assign(&d_ctrl_state->ctrl_thread_run_state, 1); for(CTRL_MsgNode *msg_n = msgs.first; msg_n != 0; msg_n = msg_n->next) { CTRL_Msg *msg = &msg_n->v; @@ -3452,12 +3372,12 @@ ctrl_thread__entry_point(void *p) //- rjf: reset per-message state ProfScope("reset per-message state") { - arena_clear(ctrl_state->ctrl_thread_msg_process_arena); - ctrl_state->module_req_cache_slots_count = 4096; - ctrl_state->module_req_cache_slots = push_array(ctrl_state->ctrl_thread_msg_process_arena, CTRL_ModuleReqCacheNode *, ctrl_state->module_req_cache_slots_count); - MemoryZeroStruct(&ctrl_state->msg_user_bp_touched_files); - MemoryZeroStruct(&ctrl_state->msg_user_bp_touched_symbols); - MemoryCopyArray(ctrl_state->exception_code_filters, msg->exception_code_filters); + arena_clear(d_ctrl_state->ctrl_thread_msg_process_arena); + d_ctrl_state->module_req_cache_slots_count = 4096; + d_ctrl_state->module_req_cache_slots = push_array(d_ctrl_state->ctrl_thread_msg_process_arena, CTRL_ModuleReqCacheNode *, d_ctrl_state->module_req_cache_slots_count); + MemoryZeroStruct(&d_ctrl_state->msg_user_bp_touched_files); + MemoryZeroStruct(&d_ctrl_state->msg_user_bp_touched_symbols); + MemoryCopyArray(d_ctrl_state->exception_code_filters, msg->exception_code_filters); } //- rjf: gather all touched symbols by user breakpoints @@ -3491,7 +3411,7 @@ ctrl_thread__entry_point(void *p) } if(expr->kind == E_ExprKind_LeafIdentifier) { - str8_list_push(ctrl_state->ctrl_thread_msg_process_arena, &ctrl_state->msg_user_bp_touched_symbols, expr->string); + str8_list_push(d_ctrl_state->ctrl_thread_msg_process_arena, &d_ctrl_state->msg_user_bp_touched_symbols, expr->string); } if(expr->next != &e_expr_nil) { @@ -3524,7 +3444,7 @@ ctrl_thread__entry_point(void *p) { continue; } - str8_list_push(ctrl_state->ctrl_thread_msg_process_arena, &ctrl_state->msg_user_bp_touched_files, n->v.string); + str8_list_push(d_ctrl_state->ctrl_thread_msg_process_arena, &d_ctrl_state->msg_user_bp_touched_files, n->v.string); } //- rjf: process message @@ -3545,24 +3465,24 @@ ctrl_thread__entry_point(void *p) //- rjf: configuration case CTRL_MsgKind_SetUserEntryPoints: { - arena_clear(ctrl_state->user_entry_point_arena); - MemoryZeroStruct(&ctrl_state->user_entry_points); + arena_clear(d_ctrl_state->user_entry_point_arena); + MemoryZeroStruct(&d_ctrl_state->user_entry_points); for(String8Node *n = msg->entry_points.first; n != 0; n = n->next) { - str8_list_push(ctrl_state->user_entry_point_arena, &ctrl_state->user_entry_points, n->string); + str8_list_push(d_ctrl_state->user_entry_point_arena, &d_ctrl_state->user_entry_points, n->string); } }break; case CTRL_MsgKind_SetModuleDebugInfoPath: { - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; String8 path = msg->path; CTRL_Entity *module = ctrl_entity_from_handle(entity_ctx, msg->entity); CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); DI_Key old_dbgi_key = di_key_from_path_timestamp(debug_info_path->string, debug_info_path->timestamp); di_close(old_dbgi_key, 0); - MutexScopeW(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) + MutexScopeW(d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex) { - ctrl_entity_equip_string(ctrl_state->ctrl_thread_entity_store, debug_info_path, path_normalized_from_string(scratch.arena, path)); + ctrl_entity_equip_string(d_ctrl_state->ctrl_thread_entity_store, debug_info_path, path_normalized_from_string(scratch.arena, path)); } U64 new_dbgi_timestamp = os_properties_from_file_path(path).modified; debug_info_path->timestamp = new_dbgi_timestamp; @@ -3594,16 +3514,16 @@ ctrl_thread__entry_point(void *p) }break; } } - ins_atomic_u64_eval_assign(&ctrl_state->ctrl_thread_run_state, 0); + ins_atomic_u64_eval_assign(&d_ctrl_state->ctrl_thread_run_state, 0); } - ins_atomic_u64_inc_eval(&ctrl_state->run_gen); - ins_atomic_u64_inc_eval(&ctrl_state->mem_gen); - ins_atomic_u64_inc_eval(&ctrl_state->reg_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->run_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->mem_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->reg_gen); //- rjf: update thread register cache ProfScope("update thread register cache") { - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; CTRL_EntityArray threads = ctrl_entity_array_from_kind(entity_ctx, CTRL_EntityKind_Thread); REGS_RegBlockX64 *blocks = push_array(scratch.arena, REGS_RegBlockX64, threads.count); { @@ -3633,7 +3553,7 @@ ctrl_thread__append_resolved_module_user_bp_traps(Arena *arena, CTRL_EvalScope * ProfBeginFunction(); Temp scratch = scratch_begin(&arena, 1); Access *access = eval_scope->access; - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; CTRL_Entity *module_entity = ctrl_entity_from_handle(entity_ctx, module); CTRL_Entity *debug_info_path_entity = ctrl_entity_child_from_kind(module_entity, CTRL_EntityKind_DebugInfoPath); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module_entity); @@ -4133,10 +4053,10 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_ // { U64 hash = ctrl_hash_from_handle(module); - U64 slot_idx = hash%ctrl_state->module_image_info_cache.slots_count; - U64 stripe_idx = slot_idx%ctrl_state->module_image_info_cache.stripes_count; - CTRL_ModuleImageInfoCacheSlot *slot = &ctrl_state->module_image_info_cache.slots[slot_idx]; - CTRL_ModuleImageInfoCacheStripe *stripe = &ctrl_state->module_image_info_cache.stripes[stripe_idx]; + U64 slot_idx = hash%d_ctrl_state->module_image_info_cache.slots_count; + U64 stripe_idx = slot_idx%d_ctrl_state->module_image_info_cache.stripes_count; + CTRL_ModuleImageInfoCacheSlot *slot = &d_ctrl_state->module_image_info_cache.slots[slot_idx]; + CTRL_ModuleImageInfoCacheStripe *stripe = &d_ctrl_state->module_image_info_cache.stripes[stripe_idx]; MutexScopeW(stripe->rw_mutex) { CTRL_ModuleImageInfoCacheNode *node = 0; @@ -4180,10 +4100,10 @@ ctrl_thread__module_close(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr U64 raddbg_attached_marker_voff = 0; { U64 hash = ctrl_hash_from_handle(module); - U64 slot_idx = hash%ctrl_state->module_image_info_cache.slots_count; - U64 stripe_idx = slot_idx%ctrl_state->module_image_info_cache.stripes_count; - CTRL_ModuleImageInfoCacheSlot *slot = &ctrl_state->module_image_info_cache.slots[slot_idx]; - CTRL_ModuleImageInfoCacheStripe *stripe = &ctrl_state->module_image_info_cache.stripes[stripe_idx]; + U64 slot_idx = hash%d_ctrl_state->module_image_info_cache.slots_count; + U64 stripe_idx = slot_idx%d_ctrl_state->module_image_info_cache.stripes_count; + CTRL_ModuleImageInfoCacheSlot *slot = &d_ctrl_state->module_image_info_cache.slots[slot_idx]; + CTRL_ModuleImageInfoCacheStripe *stripe = &d_ctrl_state->module_image_info_cache.stripes[stripe_idx]; MutexScopeW(stripe->rw_mutex) { CTRL_ModuleImageInfoCacheNode *node = 0; @@ -4222,7 +4142,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, ProfBeginFunction(); DMN_Event *event = push_array(arena, DMN_Event, 1); Temp scratch = scratch_begin(&arena, 1); - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; //- rjf: loop -> try to get event, run, repeat U64 spoof_old_ip_value = 0; @@ -4232,7 +4152,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, ProfScope("get next event") { // rjf: grab first event - DMN_EventNode *next_event_node = ctrl_state->first_dmn_event_node; + DMN_EventNode *next_event_node = d_ctrl_state->first_dmn_event_node; // rjf: log event if(next_event_node != 0) @@ -4282,7 +4202,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, // rjf: exception code kind -> shouldn't stop? if so, do not filter if(should_filter_event) { - B32 shouldnt_filter = !!(ctrl_state->exception_code_filters[code_kind/64] & (1ull<<(code_kind%64))); + B32 shouldnt_filter = !!(d_ctrl_state->exception_code_filters[code_kind/64] & (1ull<<(code_kind%64))); if(should_filter_event && shouldnt_filter) { should_filter_event = 0; @@ -4363,7 +4283,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, if(next_event_node != 0 && !should_filter_event) { got_event = 1; - SLLQueuePop(ctrl_state->first_dmn_event_node, ctrl_state->last_dmn_event_node); + SLLQueuePop(d_ctrl_state->first_dmn_event_node, d_ctrl_state->last_dmn_event_node); MemoryCopyStruct(event, &next_event_node->v); event->string = push_str8_copy(arena, event->string); run_ctrls->ignore_previous_exception = 1; @@ -4372,7 +4292,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, // rjf: good event but filtered? pop from queue if(next_event_node != 0 && should_filter_event) { - SLLQueuePop(ctrl_state->first_dmn_event_node, ctrl_state->last_dmn_event_node); + SLLQueuePop(d_ctrl_state->first_dmn_event_node, d_ctrl_state->last_dmn_event_node); run_ctrls->ignore_previous_exception = 0; } } @@ -4422,23 +4342,23 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, } DMN_EventList events = dmn_ctrl_run(scratch.arena, ctrl_ctx, run_ctrls); - ins_atomic_u64_inc_eval(&ctrl_state->mem_gen); - ins_atomic_u64_inc_eval(&ctrl_state->reg_gen); - ins_atomic_u64_inc_eval(&ctrl_state->run_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->mem_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->reg_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->run_gen); for(DMN_EventNode *src_n = events.first; src_n != 0; src_n = src_n->next) { - DMN_EventNode *dst_n = ctrl_state->free_dmn_event_node; + DMN_EventNode *dst_n = d_ctrl_state->free_dmn_event_node; if(dst_n != 0) { - SLLStackPop(ctrl_state->free_dmn_event_node); + SLLStackPop(d_ctrl_state->free_dmn_event_node); } else { - dst_n = push_array(ctrl_state->dmn_event_arena, DMN_EventNode, 1); + dst_n = push_array(d_ctrl_state->dmn_event_arena, DMN_EventNode, 1); } MemoryCopyStruct(&dst_n->v, &src_n->v); - dst_n->v.string = push_str8_copy(ctrl_state->dmn_event_arena, dst_n->v.string); - SLLQueuePush(ctrl_state->first_dmn_event_node, ctrl_state->last_dmn_event_node, dst_n); + dst_n->v.string = push_str8_copy(d_ctrl_state->dmn_event_arena, dst_n->v.string); + SLLQueuePush(d_ctrl_state->first_dmn_event_node, d_ctrl_state->last_dmn_event_node, dst_n); } } @@ -4482,7 +4402,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, out_evt->entity_id = event->code; out_evt->tls_model = ctrl_dynamic_linker_type_from_dmn(event->tls_model); out_evt->target_os = OperatingSystem_CURRENT; // TODO: operating system of the remote target machine - ctrl_state->process_counter += 1; + d_ctrl_state->process_counter += 1; }break; case DMN_EventKind_CreateThread: { @@ -4537,7 +4457,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, out_evt->msg_id = msg->msg_id; out_evt->entity = ctrl_handle_make(CTRL_MachineID_Local, event->process); out_evt->u64_code = event->code; - ctrl_state->process_counter -= 1; + d_ctrl_state->process_counter -= 1; }break; case DMN_EventKind_ExitThread: { @@ -4565,7 +4485,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, }break; case DMN_EventKind_DebugString: { - U64 num_strings = (event->string.size + ctrl_state->c2u_ring_max_string_size-1) / ctrl_state->c2u_ring_max_string_size; + U64 num_strings = (event->string.size + d_ctrl_state->c2u_ring_max_string_size-1) / d_ctrl_state->c2u_ring_max_string_size; for(U64 string_idx = 0; string_idx < num_strings; string_idx += 1) { CTRL_Event *out_evt = ctrl_event_list_push(scratch.arena, &evts); @@ -4573,7 +4493,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, out_evt->msg_id = msg->msg_id; out_evt->entity = ctrl_handle_make(CTRL_MachineID_Local, event->thread); out_evt->parent = ctrl_handle_make(CTRL_MachineID_Local, event->process); - out_evt->string = str8_substr(event->string, r1u64(string_idx*ctrl_state->c2u_ring_max_string_size, (string_idx+1)*ctrl_state->c2u_ring_max_string_size)); + out_evt->string = str8_substr(event->string, r1u64(string_idx*d_ctrl_state->c2u_ring_max_string_size, (string_idx+1)*d_ctrl_state->c2u_ring_max_string_size)); } }break; case DMN_EventKind_SetThreadName: @@ -4629,17 +4549,17 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, //- rjf: if this is the first process in a session, clear the debug directory // cache state - if(ctrl_state->process_counter == 1 && event->kind == DMN_EventKind_CreateProcess) + if(d_ctrl_state->process_counter == 1 && event->kind == DMN_EventKind_CreateProcess) { - arena_clear(ctrl_state->dbg_dir_arena); - ctrl_state->dbg_dir_root = push_array(ctrl_state->dbg_dir_arena, CTRL_DbgDirNode, 1); + arena_clear(d_ctrl_state->dbg_dir_arena); + d_ctrl_state->dbg_dir_root = push_array(d_ctrl_state->dbg_dir_arena, CTRL_DbgDirNode, 1); } //- rjf: out of queued up demon events -> clear event arena - if(ctrl_state->first_dmn_event_node == 0) + if(d_ctrl_state->first_dmn_event_node == 0) { - ctrl_state->free_dmn_event_node = 0; - arena_clear(ctrl_state->dmn_event_arena); + d_ctrl_state->free_dmn_event_node = 0; + arena_clear(d_ctrl_state->dmn_event_arena); } scratch_end(scratch); @@ -4687,7 +4607,7 @@ ctrl_eval_space_read(E_Space space, void *out, Rng1U64 range) case CTRL_EntityKind_Thread: { Temp scratch = scratch_begin(0, 0); - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; U64 regs_size = regs_block_size_from_arch(entity->arch); void *regs = ctrl_reg_block_from_thread(scratch.arena, entity_ctx, entity->handle); Rng1U64 legal_range = r1u64(0, regs_size); @@ -4709,7 +4629,7 @@ internal CTRL_EvalScope * ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, CTRL_Entity *thread) { ProfBeginFunction(); - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; CTRL_EvalScope *scope = push_array(arena, CTRL_EvalScope, 1); scope->access = access_open(); @@ -4769,8 +4689,8 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C { // rjf: find cached result U64 hash = ctrl_hash_from_handle(mod->handle); - U64 slot_idx = hash%ctrl_state->module_req_cache_slots_count; - CTRL_ModuleReqCacheNode *slot = ctrl_state->module_req_cache_slots[slot_idx]; + U64 slot_idx = hash%d_ctrl_state->module_req_cache_slots_count; + CTRL_ModuleReqCacheNode *slot = d_ctrl_state->module_req_cache_slots[slot_idx]; CTRL_ModuleReqCacheNode *node = 0; for(CTRL_ModuleReqCacheNode *n = slot; n != 0; n = n->next) { @@ -4824,16 +4744,16 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C void *file_base = os_file_map_view_open(map, OS_AccessFlag_Read, r1u64(0, props.size)); String8 file_data = str8(file_base, props.size); { - rdi_is_necessary = pdb_has_symbol_or_file_ref(file_data, ctrl_state->msg_user_bp_touched_symbols, ctrl_state->msg_user_bp_touched_files); + rdi_is_necessary = pdb_has_symbol_or_file_ref(file_data, d_ctrl_state->msg_user_bp_touched_symbols, d_ctrl_state->msg_user_bp_touched_files); } os_file_map_view_close(map, file_base, r1u64(0, props.size)); os_file_map_close(map); } } os_file_close(file); - node = push_array(ctrl_state->ctrl_thread_msg_process_arena, CTRL_ModuleReqCacheNode, 1); + node = push_array(d_ctrl_state->ctrl_thread_msg_process_arena, CTRL_ModuleReqCacheNode, 1); node->next = slot; - ctrl_state->module_req_cache_slots[slot_idx] = node; + d_ctrl_state->module_req_cache_slots[slot_idx] = node; node->module = mod->handle; node->required = rdi_is_necessary; } @@ -4873,7 +4793,7 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C ////////////////////////////// //- rjf: select evaluation cache // - e_select_cache(ctrl_state->ctrl_thread_eval_cache); + e_select_cache(d_ctrl_state->ctrl_thread_eval_cache); ////////////////////////////// //- rjf: build base evaluation context @@ -4958,7 +4878,7 @@ ctrl_thread__end_and_flush_log(void) { Temp scratch = scratch_begin(0, 0); LogScopeResult log = log_scope_end(scratch.arena); - os_append_data_to_file_path(ctrl_state->ctrl_thread_log_path, log.strings[LogMsgKind_Info]); + os_append_data_to_file_path(d_ctrl_state->ctrl_thread_log_path, log.strings[LogMsgKind_Info]); if(log.strings[LogMsgKind_UserError].size != 0) { CTRL_EventList evts = {0}; @@ -5023,8 +4943,8 @@ ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) os_file_close(stdin_handle); //- rjf: record (id -> entry points), so that we know custom entry points for this PID - CTRL_EntityCtxRWStore *entity_ctx_rw_store = ctrl_state->ctrl_thread_entity_store; - MutexScopeW(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) + CTRL_EntityCtxRWStore *entity_ctx_rw_store = d_ctrl_state->ctrl_thread_entity_store; + MutexScopeW(d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex) { for(String8Node *n = msg->entry_points.first; n != 0; n = n->next) { @@ -5152,7 +5072,7 @@ ctrl_thread__kill_all(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); U32 exit_code = msg->exit_code; - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; //- rjf: gather all currently existing processes CTRL_EntityArray initial_processes = ctrl_entity_array_from_kind(entity_ctx, CTRL_EntityKind_Process); @@ -5289,7 +5209,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) Temp scratch = scratch_begin(0, 0); DMN_Event *stop_event = 0; CTRL_EventCause stop_cause = CTRL_EventCause_Null; - CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; CTRL_Handle target_thread = msg->entity; CTRL_Handle target_process = msg->parent; CTRL_Entity *target_process_entity = ctrl_entity_from_handle(entity_ctx, target_process); @@ -5783,7 +5703,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) //- rjf: add traps for all custom user entry points if(!entries_found) { - for(String8Node *n = ctrl_state->user_entry_points.first; n != 0; n = n->next) + for(String8Node *n = d_ctrl_state->user_entry_points.first; n != 0; n = n->next) { U32 procedure_id = 0; { @@ -6476,7 +6396,7 @@ ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 void *range_base = 0; U64 zero_terminated_size = 0; U64 pre_read_mem_gen = ctrl_mem_gen(); - B32 pre_run_state = ins_atomic_u64_eval(&ctrl_state->ctrl_thread_run_state); + B32 pre_run_state = ins_atomic_u64_eval(&d_ctrl_state->ctrl_thread_run_state); if(range_size != 0) { // rjf: set up arena @@ -6545,7 +6465,7 @@ ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 } } U64 post_read_mem_gen = ctrl_mem_gen(); - B32 post_run_state = ins_atomic_u64_eval(&ctrl_state->ctrl_thread_run_state); + B32 post_run_state = ins_atomic_u64_eval(&d_ctrl_state->ctrl_thread_run_state); //- rjf: form content key C_Key content_key = {0}; @@ -6574,9 +6494,9 @@ ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 //- rjf: wakeup on new submissions if(!u128_match(u128_zero(), hash)) { - if(ctrl_state->wakeup_hook != 0) + if(d_ctrl_state->wakeup_hook != 0) { - ctrl_state->wakeup_hook(); + d_ctrl_state->wakeup_hook(); } } @@ -6809,7 +6729,7 @@ ctrl_process_write(CTRL_Handle process, Rng1U64 range, void *src) //- rjf: success -> bump generation if(result) { - ins_atomic_u64_inc_eval(&ctrl_state->mem_gen); + ins_atomic_u64_inc_eval(&d_ctrl_state->mem_gen); } //- rjf: success -> wait for cache updates, for small regions - prefer relatively seamless @@ -6852,9 +6772,9 @@ ctrl_call_stack_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, //- rjf: produce mini entity context for just this call stack build CTRL_EntityCtx *entity_ctx = push_array(scratch.arena, CTRL_EntityCtx, 1); - MutexScopeR(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) + MutexScopeR(d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex) { - CTRL_EntityCtx *src_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *src_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; CTRL_EntityCtx *dst_ctx = entity_ctx; { dst_ctx->root = &ctrl_entity_nil; @@ -6992,9 +6912,9 @@ ctrl_call_stack_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, } //- rjf: broadcast update - if(good && ctrl_state->wakeup_hook != 0) + if(good && d_ctrl_state->wakeup_hook != 0) { - ctrl_state->wakeup_hook(); + d_ctrl_state->wakeup_hook(); } //- rjf: bundle call stack as artifact @@ -7053,9 +6973,9 @@ ctrl_call_stack_tree_artifact_create(String8 key, B32 *cancel_signal, B32 *retry CTRL_Handle *threads = 0; CTRL_Handle *threads_processes = 0; Arch *threads_arches = 0; - MutexScopeR(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) + MutexScopeR(d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex) { - CTRL_EntityCtx *ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_EntityCtx *ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx; CTRL_EntityArray thread_entities = ctrl_entity_array_from_kind(ctx, CTRL_EntityKind_Thread); threads_count = thread_entities.count; threads = push_array(scratch.arena, CTRL_Handle, threads_count); diff --git a/src/dbg_engine/dbg_engine_ctrl.h b/src/dbg_engine/dbg_engine_ctrl.h index 895357f9..64a6651e 100644 --- a/src/dbg_engine/dbg_engine_ctrl.h +++ b/src/dbg_engine/dbg_engine_ctrl.h @@ -263,8 +263,8 @@ typedef CTRL_WAKEUP_FUNCTION_DEF(CTRL_WakeupFunctionType); //////////////////////////////// //~ rjf: Main State Types -typedef struct CTRL_State CTRL_State; -struct CTRL_State +typedef struct D_CtrlState D_CtrlState; +struct D_CtrlState { Arena *arena; CTRL_WakeupFunctionType *wakeup_hook; @@ -327,7 +327,7 @@ struct CTRL_State //////////////////////////////// //~ rjf: Globals -global CTRL_State *ctrl_state = 0; +global D_CtrlState *d_ctrl_state = 0; read_only global CTRL_Entity ctrl_entity_nil = { &ctrl_entity_nil, @@ -471,11 +471,6 @@ internal CTRL_Entity *ctrl_thread_from_id(CTRL_EntityCtx *ctx, U64 id); //- rjf: applying events to entity caches internal void ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *list); -//////////////////////////////// -//~ rjf: Main Layer Initialization - -internal void ctrl_init(void); - //////////////////////////////// //~ rjf: Wakeup Callback Registration diff --git a/src/dbg_engine/dbg_engine_user.c b/src/dbg_engine/dbg_engine_user.c index 84ee8b33..1bd5cee9 100644 --- a/src/dbg_engine/dbg_engine_user.c +++ b/src/dbg_engine/dbg_engine_user.c @@ -294,7 +294,7 @@ d_trap_net_from_thread__step_over_inst(Arena *arena, CTRL_Entity *thread) // rjf: thread => unpacked info CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); Arch arch = thread->arch; - U64 ip_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle); + U64 ip_vaddr = ctrl_rip_from_thread(&d_user_state->ctrl_entity_store->ctx, thread->handle); // rjf: ip => machine code String8 machine_code = {0}; @@ -333,7 +333,7 @@ d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread) // rjf: thread => info Arch arch = thread->arch; - U64 ip_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle); + U64 ip_vaddr = ctrl_rip_from_thread(&d_user_state->ctrl_entity_store->ctx, thread->handle); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ip_vaddr); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); @@ -546,7 +546,7 @@ d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread) // rjf: thread => info Arch arch = thread->arch; - U64 ip_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle); + U64 ip_vaddr = ctrl_rip_from_thread(&d_user_state->ctrl_entity_store->ctx, thread->handle); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ip_vaddr); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); @@ -1142,7 +1142,7 @@ d_tls_base_vaddr_from_process_root_rip(CTRL_Entity *process, U64 root_vaddr, U64 internal CTRL_Event d_ctrl_last_stop_event(void) { - return d_state->ctrl_last_stop_event; + return d_user_state->ctrl_last_stop_event; } //////////////////////////////// @@ -1153,7 +1153,7 @@ d_ctrl_last_stop_event(void) internal U64 d_frame_index(void) { - return d_state->frame_index; + return d_user_state->frame_index; } //- rjf: control state @@ -1161,19 +1161,19 @@ d_frame_index(void) internal D_RunKind d_ctrl_last_run_kind(void) { - return d_state->ctrl_last_run_kind; + return d_user_state->ctrl_last_run_kind; } internal U64 d_ctrl_last_run_frame_idx(void) { - return d_state->ctrl_last_run_frame_idx; + return d_user_state->ctrl_last_run_frame_idx; } internal B32 d_ctrl_targets_running(void) { - return d_state->ctrl_is_running; + return d_user_state->ctrl_is_running; } //- rjf: active entity based queries @@ -1182,7 +1182,7 @@ internal DI_KeyList d_push_active_dbgi_key_list(Arena *arena) { DI_KeyList dbgis = {0}; - CTRL_EntityArray modules = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); + CTRL_EntityArray modules = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); for EachIndex(idx, modules.count) { CTRL_Entity *module = modules.v[idx]; @@ -1207,7 +1207,7 @@ d_query_cached_rip_from_thread_unwind(CTRL_Entity *thread, U64 unwind_count) U64 result = 0; if(unwind_count == 0) { - result = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle); + result = ctrl_rip_from_thread(&d_user_state->ctrl_entity_store->ctx, thread->handle); } else { @@ -1240,9 +1240,9 @@ internal U64 d_query_cached_tls_base_vaddr_from_process_root_rip(CTRL_Entity *process, U64 root_vaddr, U64 rip_vaddr) { U64 result = 0; - for(U64 cache_idx = 0; cache_idx < ArrayCount(d_state->tls_base_caches); cache_idx += 1) + for(U64 cache_idx = 0; cache_idx < ArrayCount(d_user_state->tls_base_caches); cache_idx += 1) { - D_RunTLSBaseCache *cache = &d_state->tls_base_caches[(d_state->tls_base_cache_gen+cache_idx)%ArrayCount(d_state->tls_base_caches)]; + D_RunTLSBaseCache *cache = &d_user_state->tls_base_caches[(d_user_state->tls_base_cache_gen+cache_idx)%ArrayCount(d_user_state->tls_base_caches)]; if(cache_idx == 0 && cache->slots_count == 0) { cache->slots_count = 256; @@ -1292,9 +1292,9 @@ d_query_cached_locals_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff) { ProfBeginFunction(); E_String2NumMap *map = &e_string2num_map_nil; - for(U64 cache_idx = 0; cache_idx < ArrayCount(d_state->locals_caches); cache_idx += 1) + for(U64 cache_idx = 0; cache_idx < ArrayCount(d_user_state->locals_caches); cache_idx += 1) { - D_RunLocalsCache *cache = &d_state->locals_caches[(d_state->locals_cache_gen+cache_idx)%ArrayCount(d_state->locals_caches)]; + D_RunLocalsCache *cache = &d_user_state->locals_caches[(d_user_state->locals_cache_gen+cache_idx)%ArrayCount(d_user_state->locals_caches)]; if(cache_idx == 0 && cache->table_size == 0) { cache->table_size = 256; @@ -1346,9 +1346,9 @@ d_query_cached_member_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff) { ProfBeginFunction(); E_String2NumMap *map = &e_string2num_map_nil; - for(U64 cache_idx = 0; cache_idx < ArrayCount(d_state->member_caches); cache_idx += 1) + for(U64 cache_idx = 0; cache_idx < ArrayCount(d_user_state->member_caches); cache_idx += 1) { - D_RunLocalsCache *cache = &d_state->member_caches[(d_state->member_cache_gen+cache_idx)%ArrayCount(d_state->member_caches)]; + D_RunLocalsCache *cache = &d_user_state->member_caches[(d_user_state->member_cache_gen+cache_idx)%ArrayCount(d_user_state->member_caches)]; if(cache_idx == 0 && cache->table_size == 0) { cache->table_size = 256; @@ -1400,7 +1400,7 @@ d_query_cached_member_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff) internal void d_push_cmd(D_CmdKind kind, D_CmdParams *params) { - d_cmd_list_push_new(d_state->cmds_arena, &d_state->cmds, kind, params); + d_cmd_list_push_new(d_user_state->cmds_arena, &d_user_state->cmds, kind, params); } //- rjf: command iteration @@ -1408,7 +1408,7 @@ d_push_cmd(D_CmdKind kind, D_CmdParams *params) internal B32 d_next_cmd(D_Cmd **cmd) { - D_CmdNode *start_node = d_state->cmds.first; + D_CmdNode *start_node = d_user_state->cmds.first; if(cmd[0] != 0) { start_node = CastFromMember(D_CmdNode, cmd, cmd[0]); @@ -1425,50 +1425,13 @@ d_next_cmd(D_Cmd **cmd) //////////////////////////////// //~ rjf: Main Layer Top-Level Calls -#if !defined(XXH_IMPLEMENTATION) -# define XXH_IMPLEMENTATION -# define XXH_STATIC_LINKING_ONLY -# include "third_party/xxHash/xxhash.h" -#endif - -internal void -d_init(void) -{ - Arena *arena = arena_alloc(); - d_state = push_array(arena, D_State, 1); - d_state->arena = arena; - d_state->cmds_arena = arena_alloc(); - d_state->output_log_key = c_key_make(c_root_alloc(), c_id_make(0, 0)); - c_submit_data(d_state->output_log_key, 0, str8_zero()); - d_state->ctrl_entity_store = ctrl_entity_ctx_rw_store_alloc(); - d_state->ctrl_stop_arena = arena_alloc(); - d_state->ctrl_msg_arena = arena_alloc(); - - // rjf: set up caches - for(U64 idx = 0; idx < ArrayCount(d_state->tls_base_caches); idx += 1) - { - d_state->tls_base_caches[idx].arena = arena_alloc(); - } - for(U64 idx = 0; idx < ArrayCount(d_state->locals_caches); idx += 1) - { - d_state->locals_caches[idx].arena = arena_alloc(); - } - for(U64 idx = 0; idx < ArrayCount(d_state->member_caches); idx += 1) - { - d_state->member_caches[idx].arena = arena_alloc(); - } - - // rjf: set up run state - d_state->ctrl_last_run_arena = arena_alloc(); -} - internal D_EventList d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_PathMapArray *path_maps, U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64]) { ProfBeginFunction(); Temp scratch = scratch_begin(&arena, 1); D_EventList result = {0}; - d_state->frame_index += 1; + d_user_state->frame_index += 1; ////////////////////////////// //- rjf: sync with ctrl thread @@ -1481,7 +1444,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P //- rjf: consume & process events CTRL_EventList events = ctrl_c2u_pop_events(scratch.arena); - ctrl_entity_store_apply_events(d_state->ctrl_entity_store, &events); + ctrl_entity_store_apply_events(d_user_state->ctrl_entity_store, &events); for(CTRL_EventNode *event_n = events.first; event_n != 0; event_n = event_n->next) @@ -1505,16 +1468,16 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case CTRL_EventKind_Started: { - d_state->ctrl_is_running = 1; - d_state->ctrl_thread_run_state = 1; + d_user_state->ctrl_is_running = 1; + d_user_state->ctrl_thread_run_state = 1; }break; case CTRL_EventKind_Stopped: { - B32 should_snap = !(d_state->ctrl_soft_halt_issued); - d_state->ctrl_is_running = 0; - d_state->ctrl_thread_run_state = 0; - d_state->ctrl_soft_halt_issued = 0; + B32 should_snap = !(d_user_state->ctrl_soft_halt_issued); + d_user_state->ctrl_is_running = 0; + d_user_state->ctrl_thread_run_state = 0; + d_user_state->ctrl_soft_halt_issued = 0; // rjf: exception or unexpected trap -> push error if(event->cause == CTRL_EventCause_InterruptedByException || @@ -1525,15 +1488,15 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P // rjf: gather stop info { - arena_clear(d_state->ctrl_stop_arena); - MemoryCopyStruct(&d_state->ctrl_last_stop_event, event); - d_state->ctrl_last_stop_event.string = push_str8_copy(d_state->ctrl_stop_arena, d_state->ctrl_last_stop_event.string); + arena_clear(d_user_state->ctrl_stop_arena); + MemoryCopyStruct(&d_user_state->ctrl_last_stop_event, event); + d_user_state->ctrl_last_stop_event.string = push_str8_copy(d_user_state->ctrl_stop_arena, d_user_state->ctrl_last_stop_event.string); } // rjf: push stop event to caller, if this is not a soft-halt if(should_snap) { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, event->entity); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, event->entity); D_EventCause cause = D_EventCause_Null; switch(event->cause) { @@ -1568,11 +1531,11 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case CTRL_EventKind_NewProc: { // rjf: the first process? -> clear session output - CTRL_EntityArray existing_processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray existing_processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(existing_processes.count == 1) { MTX_Op op = {r1u64(0, 0xffffffffffffffffull), str8_lit("[new session]\n")}; - mtx_push_op(d_state->output_log_key, op); + mtx_push_op(d_user_state->output_log_key, op); } }break; @@ -1601,7 +1564,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case CTRL_EventKind_DebugString: { MTX_Op op = {r1u64(max_U64, max_U64), event->string}; - mtx_push_op(d_state->output_log_key, op); + mtx_push_op(d_user_state->output_log_key, op); }break; //- rjf: memory @@ -1615,41 +1578,41 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P } //- rjf: clear tls base cache - if((d_state->tls_base_cache_reggen_idx != new_reg_gen || - d_state->tls_base_cache_memgen_idx != new_mem_gen) && + if((d_user_state->tls_base_cache_reggen_idx != new_reg_gen || + d_user_state->tls_base_cache_memgen_idx != new_mem_gen) && !d_ctrl_targets_running()) { - d_state->tls_base_cache_gen += 1; - D_RunTLSBaseCache *cache = &d_state->tls_base_caches[d_state->tls_base_cache_gen%ArrayCount(d_state->tls_base_caches)]; + d_user_state->tls_base_cache_gen += 1; + D_RunTLSBaseCache *cache = &d_user_state->tls_base_caches[d_user_state->tls_base_cache_gen%ArrayCount(d_user_state->tls_base_caches)]; arena_clear(cache->arena); cache->slots_count = 0; cache->slots = 0; - d_state->tls_base_cache_reggen_idx = new_reg_gen; - d_state->tls_base_cache_memgen_idx = new_mem_gen; + d_user_state->tls_base_cache_reggen_idx = new_reg_gen; + d_user_state->tls_base_cache_memgen_idx = new_mem_gen; } //- rjf: clear locals cache - if(d_state->locals_cache_reggen_idx != new_reg_gen && + if(d_user_state->locals_cache_reggen_idx != new_reg_gen && !d_ctrl_targets_running()) { - d_state->locals_cache_gen += 1; - D_RunLocalsCache *cache = &d_state->locals_caches[d_state->locals_cache_gen%ArrayCount(d_state->locals_caches)]; + d_user_state->locals_cache_gen += 1; + D_RunLocalsCache *cache = &d_user_state->locals_caches[d_user_state->locals_cache_gen%ArrayCount(d_user_state->locals_caches)]; arena_clear(cache->arena); cache->table_size = 0; cache->table = 0; - d_state->locals_cache_reggen_idx = new_reg_gen; + d_user_state->locals_cache_reggen_idx = new_reg_gen; } //- rjf: clear members cache - if(d_state->member_cache_reggen_idx != new_reg_gen && + if(d_user_state->member_cache_reggen_idx != new_reg_gen && !d_ctrl_targets_running()) { - d_state->member_cache_gen += 1; - D_RunLocalsCache *cache = &d_state->member_caches[d_state->member_cache_gen%ArrayCount(d_state->member_caches)]; + d_user_state->member_cache_gen += 1; + D_RunLocalsCache *cache = &d_user_state->member_caches[d_user_state->member_cache_gen%ArrayCount(d_user_state->member_caches)]; arena_clear(cache->arena); cache->table_size = 0; cache->table = 0; - d_state->member_cache_reggen_idx = new_reg_gen; + d_user_state->member_cache_reggen_idx = new_reg_gen; } } @@ -1661,7 +1624,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P // rjf: build data strings of all param data String8List strings = {0}; { - CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); for EachIndex(idx, threads.count) { CTRL_Entity *thread = threads.v[idx]; @@ -1693,7 +1656,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P // halt-refresh to inform the ctrl thread about the updated // state // - if(d_ctrl_targets_running() && !u128_match(ctrl_param_state_hash, d_state->ctrl_last_run_param_state_hash)) + if(d_ctrl_targets_running() && !u128_match(ctrl_param_state_hash, d_user_state->ctrl_last_run_param_state_hash)) { d_cmd(D_CmdKind_SoftHaltRefresh); } @@ -1816,7 +1779,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P }break; case D_CmdKind_Kill: { - CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->process); + CTRL_Entity *process = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->process); if(process == &ctrl_entity_nil) { log_user_error(str8_lit("Cannot kill; no process was specified.")); @@ -1839,7 +1802,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P }break; case D_CmdKind_Detach: { - CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->process); + CTRL_Entity *process = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->process); if(process == &ctrl_entity_nil) { log_user_error(str8_lit("Cannot detach; no process specified.")); @@ -1855,7 +1818,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case D_CmdKind_Continue: { B32 good_to_run = 0; - CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); if(threads.count > 0) { for EachIndex(idx, threads.count) @@ -1871,7 +1834,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P { need_run = 1; run_kind = D_RunKind_Run; - run_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->thread); + run_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->thread); } else { @@ -1885,7 +1848,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case D_CmdKind_StepOverLine: case D_CmdKind_StepOut: { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->thread); if(thread == &ctrl_entity_nil) { log_user_error(str8_lit("Must have a selected thread to step.")); @@ -1972,16 +1935,16 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P if(d_ctrl_targets_running()) { need_run = 1; - run_kind = d_state->ctrl_last_run_kind; - run_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, d_state->ctrl_last_run_thread_handle); - run_flags = d_state->ctrl_last_run_flags; - run_traps = d_state->ctrl_last_run_traps; + run_kind = d_user_state->ctrl_last_run_kind; + run_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, d_user_state->ctrl_last_run_thread_handle); + run_flags = d_user_state->ctrl_last_run_flags; + run_traps = d_user_state->ctrl_last_run_traps; }break; case D_CmdKind_SetThreadIP: { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->thread); U64 vaddr = params->vaddr; - void *block = ctrl_reg_block_from_thread(scratch.arena, &d_state->ctrl_entity_store->ctx, thread->handle); + void *block = ctrl_reg_block_from_thread(scratch.arena, &d_user_state->ctrl_entity_store->ctx, thread->handle); regs_arch_block_write_rip(thread->arch, block, vaddr); B32 result = ctrl_thread_write_reg_block(thread->handle, block); (void)result; @@ -2005,7 +1968,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P }break; case D_CmdKind_Run: { - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { d_cmd(D_CmdKind_Continue, .machine = params->machine, .process = params->process, .thread = params->thread); @@ -2017,7 +1980,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P }break; case D_CmdKind_Restart: { - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { d_cmd(D_CmdKind_KillAll); @@ -2027,7 +1990,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case D_CmdKind_StepInto: case D_CmdKind_StepOver: { - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { D_CmdKind step_cmd_kind = (cmd->kind == D_CmdKind_StepInto @@ -2077,7 +2040,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case D_CmdKind_ThawEntity: { B32 should_freeze = (cmd->kind == D_CmdKind_FreezeEntity); - CTRL_Entity *root = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->entity); + CTRL_Entity *root = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->entity); for(CTRL_Entity *e = root; e != &ctrl_entity_nil; e = ctrl_entity_rec_depth_first_pre(e, root).next) { if(e->kind == CTRL_EntityKind_Thread) @@ -2091,23 +2054,23 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P if(d_ctrl_targets_running()) { need_run = 1; - run_kind = d_state->ctrl_last_run_kind; - run_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, d_state->ctrl_last_run_thread_handle); - run_flags = d_state->ctrl_last_run_flags; - run_traps = d_state->ctrl_last_run_traps; + run_kind = d_user_state->ctrl_last_run_kind; + run_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, d_user_state->ctrl_last_run_thread_handle); + run_flags = d_user_state->ctrl_last_run_flags; + run_traps = d_user_state->ctrl_last_run_traps; } }break; //- rjf: entity decoration case D_CmdKind_SetEntityColor: { - CTRL_Entity *entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->entity); + CTRL_Entity *entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->entity); entity->rgba = params->rgba; }break; case D_CmdKind_SetEntityName: { - CTRL_Entity *entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->entity); - ctrl_entity_equip_string(d_state->ctrl_entity_store, entity, params->string); + CTRL_Entity *entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, params->entity); + ctrl_entity_equip_string(d_user_state->ctrl_entity_store, entity, params->string); }break; //- rjf: attaching @@ -2129,7 +2092,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P { // rjf: compute hash of all run-parameterization entities, store { - d_state->ctrl_last_run_param_state_hash = ctrl_param_state_hash; + d_user_state->ctrl_last_run_param_state_hash = ctrl_param_state_hash; } // rjf: push & fill run message @@ -2193,19 +2156,19 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P } } - // rjf: copy run traps to scratch (needed, if run_traps can be `d_state->ctrl_last_run_traps`) + // rjf: copy run traps to scratch (needed, if run_traps can be `d_user_state->ctrl_last_run_traps`) CTRL_TrapList run_traps_copy = ctrl_trap_list_copy(scratch.arena, &run_traps); D_BreakpointArray run_extra_bps_copy = d_breakpoint_array_copy(scratch.arena, &run_extra_bps); // rjf: store last run info - arena_clear(d_state->ctrl_last_run_arena); - d_state->ctrl_last_run_kind = run_kind; - d_state->ctrl_last_run_frame_idx = d_frame_index(); - d_state->ctrl_last_run_thread_handle = run_thread->handle; - d_state->ctrl_last_run_flags = run_flags; - d_state->ctrl_last_run_traps = ctrl_trap_list_copy(d_state->ctrl_last_run_arena, &run_traps_copy); - d_state->ctrl_last_run_extra_bps = d_breakpoint_array_copy(d_state->ctrl_last_run_arena, &run_extra_bps_copy); - d_state->ctrl_is_running = 1; + arena_clear(d_user_state->ctrl_last_run_arena); + d_user_state->ctrl_last_run_kind = run_kind; + d_user_state->ctrl_last_run_frame_idx = d_frame_index(); + d_user_state->ctrl_last_run_thread_handle = run_thread->handle; + d_user_state->ctrl_last_run_flags = run_flags; + d_user_state->ctrl_last_run_traps = ctrl_trap_list_copy(d_user_state->ctrl_last_run_arena, &run_traps_copy); + d_user_state->ctrl_last_run_extra_bps = d_breakpoint_array_copy(d_user_state->ctrl_last_run_arena, &run_extra_bps_copy); + d_user_state->ctrl_is_running = 1; } } } @@ -2214,8 +2177,8 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P //- rjf: clear command batch // { - arena_clear(d_state->cmds_arena); - MemoryZeroStruct(&d_state->cmds); + arena_clear(d_user_state->cmds_arena); + MemoryZeroStruct(&d_user_state->cmds); } ////////////////////////////// @@ -2223,7 +2186,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P // for EachNode(n, D_CmdNode, deferred_cmds.first) { - d_cmd_list_push_new(d_state->cmds_arena, &d_state->cmds, n->cmd.kind, &n->cmd.params); + d_cmd_list_push_new(d_user_state->cmds_arena, &d_user_state->cmds, n->cmd.kind, &n->cmd.params); } ////////////////////////////// @@ -2232,19 +2195,19 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P // the next tick) // { - CTRL_MsgList msgs_copy = ctrl_msg_list_deep_copy(d_state->ctrl_msg_arena, &ctrl_msgs); - ctrl_msg_list_concat_in_place(&d_state->ctrl_msgs, &msgs_copy); - if(d_state->ctrl_msgs.count != 0) + CTRL_MsgList msgs_copy = ctrl_msg_list_deep_copy(d_user_state->ctrl_msg_arena, &ctrl_msgs); + ctrl_msg_list_concat_in_place(&d_user_state->ctrl_msgs, &msgs_copy); + if(d_user_state->ctrl_msgs.count != 0) { - if(!d_state->ctrl_soft_halt_issued && d_state->ctrl_thread_run_state) + if(!d_user_state->ctrl_soft_halt_issued && d_user_state->ctrl_thread_run_state) { - d_state->ctrl_soft_halt_issued = 1; + d_user_state->ctrl_soft_halt_issued = 1; ctrl_halt(); } - if(ctrl_u2c_push_msgs(&d_state->ctrl_msgs, os_now_microseconds()+100)) + if(ctrl_u2c_push_msgs(&d_user_state->ctrl_msgs, os_now_microseconds()+100)) { - MemoryZeroStruct(&d_state->ctrl_msgs); - arena_clear(d_state->ctrl_msg_arena); + MemoryZeroStruct(&d_user_state->ctrl_msgs); + arena_clear(d_user_state->ctrl_msg_arena); } } } diff --git a/src/dbg_engine/dbg_engine_user.h b/src/dbg_engine/dbg_engine_user.h index 9f92e12a..ba48f5ad 100644 --- a/src/dbg_engine/dbg_engine_user.h +++ b/src/dbg_engine/dbg_engine_user.h @@ -332,8 +332,8 @@ struct CTRL_EventList //////////////////////////////// //~ rjf: Main State Types -typedef struct D_State D_State; -struct D_State +typedef struct D_UserState D_UserState; +struct D_UserState { // rjf: top-level state Arena *arena; @@ -382,7 +382,7 @@ struct D_State //////////////////////////////// //~ rjf: Globals -global D_State *d_state = 0; +global D_UserState *d_user_state = 0; //////////////////////////////// //~ rjf: Basic Helpers @@ -480,7 +480,6 @@ internal B32 d_next_cmd(D_Cmd **cmd); //////////////////////////////// //~ rjf: Main Layer Top-Level Calls -internal void d_init(void); internal D_EventList d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_PathMapArray *path_maps, U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64]); #endif // DBG_ENGINE_USER_H diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 7eed0982..a2255f67 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -689,7 +689,7 @@ rd_ctrl_entity_from_eval_space(E_Space space) CTRL_Handle handle; handle.machine_id = space.u64s[0]; handle.dmn_handle.u64[0] = space.u64s[1]; - entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, handle); + entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, handle); } return entity; } @@ -1007,7 +1007,7 @@ rd_eval_space_write(E_Space space, void *in, Rng1U64 range) Rng1U64 legal_range = r1u64(0, regs_size); Rng1U64 write_range = intersect_1u64(legal_range, range); U64 write_size = dim_1u64(write_range); - void *new_regs = ctrl_reg_block_from_thread(scratch.arena, &d_state->ctrl_entity_store->ctx, entity->handle); + void *new_regs = ctrl_reg_block_from_thread(scratch.arena, &d_user_state->ctrl_entity_store->ctx, entity->handle); MemoryCopy((U8 *)new_regs + write_range.min, in, write_size); result = ctrl_thread_write_reg_block(entity->handle, new_regs); scratch_end(scratch); @@ -1090,7 +1090,7 @@ rd_eval_space_write(E_Space space, void *in, Rng1U64 range) if(str8_match(child_schema->string, str8_lit("label"), 0)) { result = 1; - ctrl_entity_equip_string(d_state->ctrl_entity_store, entity, write_string); + ctrl_entity_equip_string(d_user_state->ctrl_entity_store, entity, write_string); rd_cmd(D_CmdKind_SetEntityName, .ctrl_entity = entity->handle, .string = write_string); } else if(str8_match(child_schema->string, str8_lit("dbg"), 0)) @@ -1703,7 +1703,7 @@ rd_view_ui(Rng2F32 rect) UI_Padding(ui_pct(1, 0)) UI_Focus(UI_FocusKind_Null) { CFG_NodePtrList targets = cfg_node_top_level_list_from_string(scratch.arena, str8_lit("target")); - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); //- rjf: icon & info UI_Padding(ui_em(2.f, 1.f)) UI_TagF("weak") @@ -2361,7 +2361,7 @@ rd_view_ui(Rng2F32 rect) String8 name = {0}; { U64 vaddr = eval.value.u64; - CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process); + CTRL_Entity *process = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->process); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); U64 voff = ctrl_voff_from_vaddr(module, vaddr); @@ -4740,7 +4740,7 @@ rd_arch_from_eval(E_Eval eval) CTRL_Entity *process = ctrl_process_from_entity(ctrl_entity); if(process == &ctrl_entity_nil) { - process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process); + process = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->process); } Arch arch = process->arch; if(arch == Arch_Null) @@ -5498,11 +5498,11 @@ rd_window_frame(void) //////////////////////// //- rjf: control entity tooltips // - case RD_RegSlot_Machine: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->machine); }goto ctrl_entity_tooltip; - case RD_RegSlot_Process: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->process); }goto ctrl_entity_tooltip; - case RD_RegSlot_Module: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->module); }goto ctrl_entity_tooltip; - case RD_RegSlot_Thread: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->thread); }goto ctrl_entity_tooltip; - case RD_RegSlot_CtrlEntity:{ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->ctrl_entity); }goto ctrl_entity_tooltip; + case RD_RegSlot_Machine: {ctrl_entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, regs->machine); }goto ctrl_entity_tooltip; + case RD_RegSlot_Process: {ctrl_entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, regs->process); }goto ctrl_entity_tooltip; + case RD_RegSlot_Module: {ctrl_entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, regs->module); }goto ctrl_entity_tooltip; + case RD_RegSlot_Thread: {ctrl_entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, regs->thread); }goto ctrl_entity_tooltip; + case RD_RegSlot_CtrlEntity:{ctrl_entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, regs->ctrl_entity); }goto ctrl_entity_tooltip; ctrl_entity_tooltip:; UI_Tooltip { @@ -7037,7 +7037,7 @@ rd_window_frame(void) { Temp scratch = scratch_begin(0, 0); CFG_NodePtrList targets = cfg_node_top_level_list_from_string(scratch.arena, str8_lit("target")); - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); B32 can_send_signal = !d_ctrl_targets_running(); typedef struct CenterButtonTask CenterButtonTask; struct CenterButtonTask @@ -9577,7 +9577,7 @@ rd_string_from_exception_code(U32 code) internal DR_FStrList rd_stop_explanation_fstrs_from_ctrl_event(Arena *arena, CTRL_Event *event) { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, event->entity); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, event->entity); DR_FStrList thread_fstrs = rd_title_fstrs_from_ctrl_entity(arena, thread, 0); DR_FStrList fstrs = {0}; DR_FStrParams params = {ui_top_font(), ui_top_text_raster_flags(), ui_color_from_name(str8_lit("text")), ui_top_font_size()}; @@ -11102,14 +11102,14 @@ rd_frame(void) //- rjf: unpack basic evaluation context // ProfBegin("unpack eval-dependent info"); - CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process); - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *process = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->process); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); Arch arch = thread->arch; U64 unwind_count = rd_regs()->unwind_count; U64 rip_vaddr = d_query_cached_rip_from_thread_unwind(thread, unwind_count); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, rip_vaddr); U64 rip_voff = ctrl_voff_from_vaddr(module, rip_vaddr); - U64 tls_root_vaddr = ctrl_tls_root_vaddr_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle); + U64 tls_root_vaddr = ctrl_tls_root_vaddr_from_thread(&d_user_state->ctrl_entity_store->ctx, thread->handle); ProfEnd(); //////////////////////////// @@ -11132,7 +11132,7 @@ rd_frame(void) //////////////////////////// //- rjf: produce all eval modules // - CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); + CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); U64 eval_modules_count = Max(1, all_modules.count); E_Module *eval_modules = push_array(scratch.arena, E_Module, eval_modules_count); E_Module *eval_modules_primary = &eval_modules[0]; @@ -11514,7 +11514,7 @@ rd_frame(void) { String8 name = evallable_ctrl_names[idx]; CTRL_EntityKind kind = ctrl_entity_kind_from_string(name); - CTRL_EntityArray array = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, kind); + CTRL_EntityArray array = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, kind); E_TypeKey type_key = e_string2typekey_map_lookup(rd_state->meta_name2type_map, name); for EachIndex(idx, array.count) { @@ -11743,7 +11743,7 @@ rd_frame(void) //- rjf: add macro for output log { Access *access = access_open(); - C_Key key = d_state->output_log_key; + C_Key key = d_user_state->output_log_key; U128 hash = c_hash_from_key(key, 0); String8 data = c_data_from_hash(access, hash); E_Space space = e_space_make(E_SpaceKind_HashStoreKey); @@ -11880,7 +11880,7 @@ rd_frame(void) //- rjf: gather config from loaded modules // CFG_NodePtrList immediate_type_views = {0}; - CTRL_EntityArray modules = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); + CTRL_EntityArray modules = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); ProfScope("gather config from loaded modules") { for EachIndex(idx, modules.count) @@ -12072,7 +12072,7 @@ rd_frame(void) case RD_CmdKind_Restart: { // rjf: reset hit counts - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count == 0 || kind == RD_CmdKind_Restart) { CFG_NodePtrList bps = cfg_node_top_level_list_from_string(scratch.arena, str8_lit("breakpoint")); @@ -12292,7 +12292,7 @@ rd_frame(void) { // rjf: if control processes are live, but this is not force-confirmed, then // get confirmation from user - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); UI_Key key = ui_key_from_string(ui_key_zero(), str8_lit("lossy_exit_confirmation")); if(processes.count != 0 && !rd_regs()->force_confirm && !ui_key_match(rd_state->popup_key, key)) { @@ -13679,12 +13679,12 @@ rd_frame(void) //- rjf: source <-> disasm case RD_CmdKind_GoToDisassembly: { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); U64 vaddr = 0; for(D_LineNode *n = rd_regs()->lines.first; n != 0; n = n->next) { - CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_state->ctrl_entity_store->ctx, n->v.dbgi_key); - CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules); + CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_user_state->ctrl_entity_store->ctx, n->v.dbgi_key); + CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_user_state->ctrl_entity_store->ctx, thread, &modules); if(module != &ctrl_entity_nil) { vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); @@ -13967,7 +13967,7 @@ rd_frame(void) Access *access = access_open(); //- rjf: unpack thread info - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); U64 unwind_index = rd_regs()->unwind_count; U64 inline_depth = rd_regs()->inline_depth; U64 rip_vaddr = d_query_cached_rip_from_thread_unwind(thread, unwind_index); @@ -14031,7 +14031,7 @@ rd_frame(void) }break; case RD_CmdKind_FindSelectedThread: { - CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread); + CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_base_regs()->thread); rd_cmd(RD_CmdKind_FindThread, .thread = selected_thread->handle, .unwind_count = rd_base_regs()->unwind_count, @@ -14140,7 +14140,7 @@ rd_frame(void) { CTRL_Entity *process = &ctrl_entity_nil; U64 vaddr = 0; - CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_state->ctrl_entity_store->ctx, voff_dbgi_key); + CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_user_state->ctrl_entity_store->ctx, voff_dbgi_key); CTRL_Entity *module = ctrl_entity_list_first(&modules); process = ctrl_entity_ancestor_from_kind(module, CTRL_EntityKind_Process); if(process != &ctrl_entity_nil) @@ -14220,8 +14220,8 @@ rd_frame(void) { file_path = rd_mapped_from_file_path(scratch.arena, rd_regs()->file_path); point = rd_regs()->cursor; - thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); - process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process); + thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); + process = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->process); vaddr = rd_regs()->vaddr; prefer_new_tab = rd_regs()->prefer_new_tab; if(file_path.size == 0) @@ -14237,8 +14237,8 @@ rd_frame(void) D_LineList lines = d_lines_from_file_path_line_num(scratch.arena, file_path, point.line); for(D_LineNode *n = lines.first; n != 0; n = n->next) { - CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_state->ctrl_entity_store->ctx, n->v.dbgi_key); - CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules); + CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_user_state->ctrl_entity_store->ctx, n->v.dbgi_key); + CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_user_state->ctrl_entity_store->ctx, thread, &modules); vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); break; } @@ -15179,7 +15179,7 @@ rd_frame(void) case RD_CmdKind_ClearOutput: { MTX_Op op = {r1u64(0, 0xffffffffffffffffull), str8_lit("")}; - mtx_push_op(d_state->output_log_key, op); + mtx_push_op(d_user_state->output_log_key, op); }break; //- rjf: watch pins @@ -15441,7 +15441,7 @@ rd_frame(void) }break; case RD_CmdKind_SetNextStatement: { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); String8 file_path = rd_regs()->file_path; U64 new_rip_vaddr = rd_regs()->vaddr_range.min; if(file_path.size != 0) @@ -15449,8 +15449,8 @@ rd_frame(void) D_LineList *lines = &rd_regs()->lines; for(D_LineNode *n = lines->first; n != 0; n = n->next) { - CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_state->ctrl_entity_store->ctx, n->v.dbgi_key); - CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules); + CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_user_state->ctrl_entity_store->ctx, n->v.dbgi_key); + CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_user_state->ctrl_entity_store->ctx, thread, &modules); if(module != &ctrl_entity_nil) { new_rip_vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); @@ -15566,9 +15566,9 @@ rd_frame(void) }break; case RD_CmdKind_SelectThread: { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); - CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle)); + CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ctrl_rip_from_thread(&d_user_state->ctrl_entity_store->ctx, thread->handle)); CTRL_Entity *machine = ctrl_entity_ancestor_from_kind(process, CTRL_EntityKind_Machine); rd_state->base_regs.v.unwind_count = 0; rd_state->base_regs.v.inline_depth = 0; @@ -15581,7 +15581,7 @@ rd_frame(void) case RD_CmdKind_SelectUnwind: { Access *access = access_open(); - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_base_regs()->thread); CTRL_CallStack call_stack = ctrl_call_stack_from_thread(access, thread->handle, 1, os_now_microseconds()+10000); CTRL_CallStackFrame *frame = ctrl_call_stack_frame_from_unwind_and_inline_depth(&call_stack, rd_regs()->unwind_count, rd_regs()->inline_depth); if(frame == 0) @@ -15600,7 +15600,7 @@ rd_frame(void) case RD_CmdKind_DownOneFrame: { Access *access = access_open(); - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_base_regs()->thread); CTRL_CallStack call_stack = ctrl_call_stack_from_thread(access, thread->handle, 1, os_now_microseconds()+10000); CTRL_CallStackFrame *current_frame = ctrl_call_stack_frame_from_unwind_and_inline_depth(&call_stack, rd_regs()->unwind_count, rd_regs()->inline_depth); CTRL_CallStackFrame *next_frame = current_frame; @@ -16330,7 +16330,7 @@ rd_frame(void) default:{}break; case D_EventKind_ModuleLoad: { - CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, evt->module); + CTRL_Entity *module = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, evt->module); CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); String8 new_path = debug_info_path->string; if(new_path.size != 0 && os_file_path_exists(new_path)) @@ -16368,7 +16368,7 @@ rd_frame(void) case D_EventKind_ProcessEnd: if(rd_state->quit_after_success) { - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(evt->code == 0 && processes.count == 0) { rd_cmd(RD_CmdKind_Exit); @@ -16381,12 +16381,12 @@ rd_frame(void) case D_EventKind_Stop: { B32 need_refocus = (evt->cause != D_EventCause_SoftHalt); - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, evt->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, evt->thread); U64 vaddr = evt->vaddr; CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr); U64 voff = ctrl_voff_from_vaddr(module, vaddr); - U64 test_cached_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle); + U64 test_cached_vaddr = ctrl_rip_from_thread(&d_user_state->ctrl_entity_store->ctx, thread->handle); // rjf: valid stop thread? -> select & snap if(need_refocus && thread != &ctrl_entity_nil && evt->cause != D_EventCause_Halt) @@ -16395,7 +16395,7 @@ rd_frame(void) } // rjf: no stop-causing thread, but have selected thread? -> snap to selected - CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread); + CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_base_regs()->thread); if(need_refocus && (evt->cause == D_EventCause_Halt || thread == &ctrl_entity_nil) && selected_thread != &ctrl_entity_nil) { rd_cmd(RD_CmdKind_SelectThread, .thread = selected_thread->handle); @@ -16404,7 +16404,7 @@ rd_frame(void) // rjf: no stop-causing thread, but don't have selected thread? -> snap to first available thread if(need_refocus && thread == &ctrl_entity_nil && selected_thread == &ctrl_entity_nil) { - CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); CTRL_Entity *first_available_thread = ctrl_entity_array_first(&threads); rd_cmd(RD_CmdKind_SelectThread, .thread = first_available_thread->handle); } diff --git a/src/raddbg/raddbg_eval.c b/src/raddbg/raddbg_eval.c index bc82c903..0f03eeff 100644 --- a/src/raddbg/raddbg_eval.c +++ b/src/raddbg/raddbg_eval.c @@ -205,7 +205,7 @@ E_TYPE_EXPAND_RANGE_FUNCTION_DEF(locals) E_TYPE_EXPAND_INFO_FUNCTION_DEF(registers) { Temp scratch = scratch_begin(&arena, 1); - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); Arch arch = thread->arch; U64 reg_count = regs_reg_code_count_from_arch(arch); String8 *reg_strings = regs_reg_code_string_table_from_arch(arch); @@ -659,7 +659,7 @@ E_TYPE_ACCESS_FUNCTION_DEF(control) str8_match(str8_prefix(rhs->string, 1), str8_lit("$"), 0)) { CTRL_Handle handle = ctrl_handle_from_string(rhs->string); - CTRL_Entity *entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, handle); + CTRL_Entity *entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, handle); E_Space space = rd_eval_space_from_ctrl_entity(entity, RD_EvalSpaceKind_MetaCtrlEntity); result.root = e_irtree_set_space(arena, space, e_irtree_const_u(arena, 0)); result.type_key = e_string2typekey_map_lookup(rd_state->meta_name2type_map, ctrl_entity_kind_code_name_table[entity->kind]); @@ -978,7 +978,7 @@ E_TYPE_ACCESS_FUNCTION_DEF(call_stack) CTRL_CallStack *call_stack = &accel->call_stack; if(0 <= rhs_value.u64 && rhs_value.u64 < call_stack->frames_count) { - CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, accel->process); + CTRL_Entity *process = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, accel->process); CTRL_CallStackFrame *f = &call_stack->frames[rhs_value.u64]; result.root = e_irtree_set_space(arena, rd_eval_space_from_ctrl_entity(process, CTRL_EvalSpaceKind_Entity), e_irtree_const_u(arena, regs_rip_from_arch_block(accel->arch, f->regs))); result.type_key = e_type_key_cons(.arch = process->arch, .kind = E_TypeKind_Ptr, .direct_key = e_type_key_basic(E_TypeKind_Function), .count = 1, .depth = f->inline_depth); @@ -1438,7 +1438,7 @@ E_TYPE_EXPAND_INFO_FUNCTION_DEF(unattached_processes) } else { - machines = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Machine); + machines = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Machine); } //- rjf: gather system processes from this machine @@ -1535,7 +1535,7 @@ E_TYPE_ACCESS_FUNCTION_DEF(ctrl_entities) { String8 rhs_name = expr->first->next->string; CTRL_Handle handle = ctrl_handle_from_string(rhs_name); - entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, handle); + entity = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, handle); }break; case E_ExprKind_ArrayIndex: { @@ -1543,7 +1543,7 @@ E_TYPE_ACCESS_FUNCTION_DEF(ctrl_entities) CTRL_EntityKind kind = ctrl_entity_kind_from_string(rd_singular_from_code_name_plural(type->name)); E_Value rhs_value = e_value_from_expr(expr->first->next); U64 rhs_idx = rhs_value.u64; - CTRL_EntityArray entities = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, kind); + CTRL_EntityArray entities = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, kind); if(0 <= rhs_idx && rhs_idx < entities.count) { entity = entities.v[rhs_idx]; @@ -1585,7 +1585,7 @@ E_TYPE_EXPAND_INFO_FUNCTION_DEF(ctrl_entities) CTRL_EntityArray array = {0}; if(scoping_entity == &ctrl_entity_nil) { - array = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, entity_kind); + array = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, entity_kind); } else { diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index 3b054c55..a5be5e98 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -243,12 +243,11 @@ #define OS_FEATURE_GRAPHICAL 1 #define DMN_INIT_MANUAL 1 -#define CTRL_INIT_MANUAL 1 +#define D_INIT_MANUAL 1 #define OS_GFX_INIT_MANUAL 1 #define FP_INIT_MANUAL 1 #define R_INIT_MANUAL 1 #define FNT_INIT_MANUAL 1 -#define D_INIT_MANUAL 1 #define RD_INIT_MANUAL 1 //////////////////////////////// @@ -540,12 +539,11 @@ entry_point(CmdLine *cmd_line) //- rjf: manual layer initialization { dmn_init(); - ctrl_init(); + d_init(); os_gfx_init(); fp_init(); r_init(cmd_line); fnt_init(); - d_init(); rd_init(cmd_line); ctrl_set_wakeup_hook(wakeup_hook_ctrl); } diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index 5885076a..b2774480 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -44,7 +44,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla F32 scroll_bar_dim = floor_f32(main_font_size*1.5f); Vec2F32 code_area_dim = v2f32(panel_box_dim.x - scroll_bar_dim, panel_box_dim.y - scroll_bar_dim); S64 num_possible_visible_lines = (S64)(code_area_dim.y/code_line_height)+1; - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); B32 do_line_numbers = rd_setting_b32_from_name(str8_lit("show_line_numbers")); @@ -277,8 +277,8 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla // rjf: find live threads mapping to source code if(!dasm_lines) ProfScope("find live threads mapping to this file") { - CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); - CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); + CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); for EachIndex(idx, threads.count) { CTRL_Entity *thread = threads.v[idx]; @@ -340,7 +340,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla if(!dasm_lines) ProfScope("find all src -> dasm info for source code") { String8 file_path = rd_regs()->file_path; - CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->module); + CTRL_Entity *module = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); D_LineListArray lines_array = d_lines_array_from_dbgi_key_file_path_line_range(scratch.arena, dbgi_key, file_path, visible_line_num_range); if(lines_array.count != 0) @@ -353,8 +353,8 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla // rjf: find live threads mapping to disasm if(dasm_lines) ProfScope("find live threads mapping to this disassembly") { - CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); - CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); + CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); for EachIndex(idx, threads.count) { CTRL_Entity *thread = threads.v[idx]; @@ -2099,7 +2099,7 @@ RD_VIEW_UI_FUNCTION_DEF(text) if(rd_regs()->lang_kind == TXT_LangKind_Null) { Access *access = access_open(); - CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->module); + CTRL_Entity *module = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); RDI_Parsed *rdi = di_rdi_from_key(access, dbgi_key, 0, 0); if(rdi != &rdi_parsed_nil) @@ -2223,7 +2223,7 @@ RD_VIEW_UI_FUNCTION_DEF(text) // if(rd_regs()->file_path.size != 0) { - CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->module); + CTRL_Entity *module = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); rd_regs()->lines = d_lines_from_dbgi_key_file_path_line_num(rd_frame_arena(), dbgi_key, rd_regs()->file_path, rd_regs()->cursor.line); } @@ -2433,13 +2433,13 @@ RD_VIEW_UI_FUNCTION_DEF(disasm) if(dv->temp_look_vaddr != 0 && dv->temp_look_run_gen == ctrl_run_gen()) { auto_selected = 1; - auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, dv->temp_look_process), CTRL_EvalSpaceKind_Entity); + auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, dv->temp_look_process), CTRL_EvalSpaceKind_Entity); eval = e_eval_from_stringf("(0x%I64x & (~(0x4000 - 1)))", dv->temp_look_vaddr); } else { auto_selected = 1; - auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process), CTRL_EvalSpaceKind_Entity); + auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->process), CTRL_EvalSpaceKind_Entity); eval = e_eval_from_stringf("(reg:rip & (~(0x4000 - 1)))"); } } @@ -2680,7 +2680,7 @@ RD_VIEW_UI_FUNCTION_DEF(memory) Rng1U64 view_range = rd_space_range_from_eval(eval); if(eval.space.kind == 0) { - eval.space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process), CTRL_EvalSpaceKind_Entity); + eval.space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->process), CTRL_EvalSpaceKind_Entity); view_range = rd_whole_range_from_eval_space(eval.space); } @@ -3258,7 +3258,7 @@ RD_VIEW_UI_FUNCTION_DEF(memory) AnnotationList *visible_memory_annotations = push_array(scratch.arena, AnnotationList, visible_memory_size); { Access *access = access_open(); - CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); CTRL_Entity *selected_process = ctrl_entity_ancestor_from_kind(selected_thread, CTRL_EntityKind_Process); CTRL_CallStack selected_call_stack = ctrl_call_stack_from_thread(access, selected_thread->handle, 1, 0); CTRL_Entity *eval_process = &ctrl_entity_nil; diff --git a/src/raddbg/raddbg_widgets.c b/src/raddbg/raddbg_widgets.c index 78c738a7..e5d09971 100644 --- a/src/raddbg/raddbg_widgets.c +++ b/src/raddbg/raddbg_widgets.c @@ -108,7 +108,7 @@ rd_title_fstrs_from_cfg(Arena *arena, CFG_Node *cfg, B32 include_extras) CFG_Node *bp = cfg_node_from_id(stop_event.u64_code); if(bp == cfg) { - CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, stop_event.entity); + CTRL_Entity *thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, stop_event.entity); Vec4F32 thread_color = rd_color_from_ctrl_entity(thread); if(thread_color.w == 0) { @@ -509,7 +509,7 @@ rd_title_fstrs_from_ctrl_entity(Arena *arena, CTRL_Entity *entity, B32 include_e if(entity->kind == CTRL_EntityKind_Thread || entity->kind == CTRL_EntityKind_Module) { - CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_user_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count > 1) { CTRL_Entity *process = ctrl_entity_ancestor_from_kind(entity, CTRL_EntityKind_Process); @@ -1254,12 +1254,12 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe RD_CodeSliceSignal result = {0}; ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); - CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); + CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_regs()->thread); CTRL_Entity *selected_thread_process = ctrl_entity_ancestor_from_kind(selected_thread, CTRL_EntityKind_Process); U64 selected_thread_rip_unwind_vaddr = d_query_cached_rip_from_thread_unwind(selected_thread, rd_regs()->unwind_count); CTRL_Entity *selected_thread_module = ctrl_module_from_process_vaddr(selected_thread_process, selected_thread_rip_unwind_vaddr); CTRL_Event stop_event = d_ctrl_last_stop_event(); - CTRL_Entity *stopper_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, stop_event.entity); + CTRL_Entity *stopper_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, stop_event.entity); B32 is_focused = ui_is_focus_active(); B32 ctrlified = (os_get_modifiers() & OS_Modifier_Ctrl); Vec4F32 code_line_bgs[] = @@ -1336,7 +1336,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe if(rd_state->drag_drop_regs_slot == RD_RegSlot_Thread) { drop_can_hit_lines = 1; - drop_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_state->drag_drop_regs->thread); + drop_thread = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, rd_state->drag_drop_regs->thread); drop_color = rd_color_from_ctrl_entity(drop_thread); if(drop_color.w == 0) { @@ -2272,8 +2272,8 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe D_LineList *lines = ¶ms->line_infos[line_idx]; for(D_LineNode *n = lines->first; n != 0; n = n->next) { - CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_state->ctrl_entity_store->ctx, n->v.dbgi_key); - CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules); + CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_user_state->ctrl_entity_store->ctx, n->v.dbgi_key); + CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_user_state->ctrl_entity_store->ctx, thread, &modules); if(module != &ctrl_entity_nil) { new_rip_vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); @@ -2659,7 +2659,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe Rng1U64 hover_voff_range = hover_regs->voff_range; if(hover_voff_range.min == 0 && hover_voff_range.max == 0) { - CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, hover_regs->module); + CTRL_Entity *module = ctrl_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, hover_regs->module); hover_voff_range = ctrl_voff_range_from_vaddr_range(module, hover_regs->vaddr_range); } ui_set_next_pref_height(ui_px(params->line_height_px*(dim_1s64(params->line_num_range)+1), 1.f)); diff --git a/src/torture/torture_main.c b/src/torture/torture_main.c index e38f8199..c58da570 100644 --- a/src/torture/torture_main.c +++ b/src/torture/torture_main.c @@ -9,12 +9,11 @@ #define BUILD_CONSOLE_INTERFACE 1 #define OS_FEATURE_GRAPHICAL 1 #define DMN_INIT_MANUAL 1 -#define CTRL_INIT_MANUAL 1 +#define D_INIT_MANUAL 1 #define OS_GFX_INIT_MANUAL 1 #define FP_INIT_MANUAL 1 #define R_INIT_MANUAL 1 #define FNT_INIT_MANUAL 1 -#define D_INIT_MANUAL 1 #define RD_INIT_MANUAL 1 #define NO_ASYNC 1 @@ -69,14 +68,13 @@ #include "stap/stap_parse.h" #include "demon/demon_inc.h" #include "eval/eval_inc.h" +#include "dbg_engine/dbg_engine_inc.h" #include "eval_visualization/eval_visualization_inc.h" -#include "ctrl/ctrl_inc.h" #include "font_provider/font_provider_inc.h" #include "render/render_inc.h" #include "font_cache/font_cache.h" #include "draw/draw.h" #include "ui/ui_inc.h" -#include "dbg_engine/dbg_engine_inc.h" #include "raddbg/raddbg_inc.h" #include "linker/base_ext/base_crc32.h" #include "linker/base_ext/base_core.h" @@ -142,14 +140,13 @@ #include "stap/stap_parse.c" #include "demon/demon_inc.c" #include "eval/eval_inc.c" +#include "dbg_engine/dbg_engine_inc.c" #include "eval_visualization/eval_visualization_inc.c" -#include "ctrl/ctrl_inc.c" #include "font_provider/font_provider_inc.c" #include "render/render_inc.c" #include "font_cache/font_cache.c" #include "draw/draw.c" #include "ui/ui_inc.c" -#include "dbg_engine/dbg_engine_inc.c" #include "raddbg/raddbg_inc.c" #include "linker/base_ext/base_core.c" #include "linker/base_ext/base_arena.c"