From 1b26c3f180cbc3d10de1ef0fb032316e27516eec Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Wed, 14 May 2025 19:11:02 -0700 Subject: [PATCH] entity_ctx * entity_store -> entity_ctx, entity_ctx_rw_store, thread-local entity_ctx_lookup_accel --- src/ctrl/ctrl_core.c | 167 +++++++++++++++++-------------- src/ctrl/ctrl_core.h | 48 +++++---- src/dbg_engine/dbg_engine_core.c | 16 +-- src/dbg_engine/dbg_engine_core.h | 2 +- src/raddbg/raddbg_core.c | 30 +++--- src/raddbg/raddbg_eval.c | 6 +- src/raddbg/raddbg_views.c | 4 +- src/raddbg/raddbg_widgets.c | 4 +- 8 files changed, 153 insertions(+), 124 deletions(-) diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index b4d85938..1cf0ce94 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -846,20 +846,16 @@ ctrl_entity_tree_is_frozen(CTRL_Entity *root) return is_frozen; } -//- rjf: cache creation/destruction +//- rjf: entity ctx r/w store state functions -internal CTRL_EntityStore * -ctrl_entity_store_alloc(void) +internal CTRL_EntityCtxRWStore * +ctrl_entity_ctx_rw_store_alloc(void) { Arena *arena = arena_alloc(); - CTRL_EntityStore *store = push_array(arena, CTRL_EntityStore, 1); + CTRL_EntityCtxRWStore *store = push_array(arena, CTRL_EntityCtxRWStore, 1); store->arena = arena; store->ctx.hash_slots_count = 1024; store->ctx.hash_slots = push_array(arena, CTRL_EntityHashSlot, store->ctx.hash_slots_count); - for EachEnumVal(CTRL_EntityKind, k) - { - store->entity_kind_arrays_arenas[k] = arena_alloc(); - } CTRL_Entity *root = store->ctx.root = ctrl_entity_alloc(store, &ctrl_entity_nil, CTRL_EntityKind_Root, Arch_Null, ctrl_handle_zero(), 0); CTRL_Entity *local_machine = ctrl_entity_alloc(store, root, CTRL_EntityKind_Machine, arch_from_context(), ctrl_handle_make(CTRL_MachineID_Local, dmn_handle_zero()), 0); Temp scratch = scratch_begin(0, 0); @@ -870,9 +866,9 @@ ctrl_entity_store_alloc(void) } internal void -ctrl_entity_store_release(CTRL_EntityStore *cache) +ctrl_entity_ctx_rw_store_release(CTRL_EntityCtxRWStore *store) { - arena_release(cache->arena); + arena_release(store->arena); } //- rjf: string allocation/deletion @@ -896,7 +892,7 @@ ctrl_name_bucket_num_from_string_size(U64 size) } internal String8 -ctrl_entity_string_alloc(CTRL_EntityStore *store, String8 string) +ctrl_entity_string_alloc(CTRL_EntityCtxRWStore *store, String8 string) { //- rjf: allocate node CTRL_EntityStringChunkNode *node = 0; @@ -962,7 +958,7 @@ ctrl_entity_string_alloc(CTRL_EntityStore *store, String8 string) } internal void -ctrl_entity_string_release(CTRL_EntityStore *store, String8 string) +ctrl_entity_string_release(CTRL_EntityCtxRWStore *store, String8 string) { U64 bucket_num = ctrl_name_bucket_num_from_string_size(string.size); if(1 <= bucket_num && bucket_num <= ArrayCount(rd_name_bucket_chunk_sizes)) @@ -977,7 +973,7 @@ ctrl_entity_string_release(CTRL_EntityStore *store, String8 string) //- rjf: entity construction/deletion internal CTRL_Entity * -ctrl_entity_alloc(CTRL_EntityStore *store, CTRL_Entity *parent, CTRL_EntityKind kind, Arch arch, CTRL_Handle handle, U64 id) +ctrl_entity_alloc(CTRL_EntityCtxRWStore *store, CTRL_Entity *parent, CTRL_EntityKind kind, Arch arch, CTRL_Handle handle, U64 id) { CTRL_Entity *entity = &ctrl_entity_nil; { @@ -1041,14 +1037,14 @@ ctrl_entity_alloc(CTRL_EntityStore *store, CTRL_Entity *parent, CTRL_EntityKind } // rjf: bump counters - store->entity_kind_counts[kind] += 1; - store->entity_kind_alloc_gens[kind] += 1; + store->ctx.entity_kind_counts[kind] += 1; + store->ctx.entity_kind_alloc_gens[kind] += 1; } return entity; } internal void -ctrl_entity_release(CTRL_EntityStore *store, CTRL_Entity *entity) +ctrl_entity_release(CTRL_EntityCtxRWStore *store, CTRL_Entity *entity) { // rjf: unhook root if(entity->parent != &ctrl_entity_nil) @@ -1099,8 +1095,8 @@ ctrl_entity_release(CTRL_EntityStore *store, CTRL_Entity *entity) } // rjf: dec counter - store->entity_kind_counts[t->e->kind] -= 1; - store->entity_kind_alloc_gens[t->e->kind] += 1; + store->ctx.entity_kind_counts[t->e->kind] -= 1; + store->ctx.entity_kind_alloc_gens[t->e->kind] += 1; } scratch_end(scratch); } @@ -1109,7 +1105,7 @@ ctrl_entity_release(CTRL_EntityStore *store, CTRL_Entity *entity) //- rjf: entity equipment internal void -ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *entity, String8 string) +ctrl_entity_equip_string(CTRL_EntityCtxRWStore *store, CTRL_Entity *entity, String8 string) { if(entity->string.size != 0) { @@ -1118,37 +1114,54 @@ ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *entity, String8 s entity->string = ctrl_entity_string_alloc(store, string); } -//- rjf: entity store lookups +//- rjf: accelerated entity context lookups + +internal CTRL_EntityCtxLookupAccel * +ctrl_thread_entity_ctx_lookup_accel(void) +{ + if(ctrl_entity_ctx_lookup_accel == 0) + { + Arena *arena = arena_alloc(); + ctrl_entity_ctx_lookup_accel = push_array(arena, CTRL_EntityCtxLookupAccel, 1); + ctrl_entity_ctx_lookup_accel->arena = arena; + for EachEnumVal(CTRL_EntityKind, k) + { + ctrl_entity_ctx_lookup_accel->entity_kind_arrays_arenas[k] = arena_alloc(); + } + } + return ctrl_entity_ctx_lookup_accel; +} internal CTRL_EntityArray -ctrl_entity_array_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind) +ctrl_entity_array_from_kind(CTRL_EntityCtx *ctx, CTRL_EntityKind kind) { - if(store->entity_kind_arrays_gens[kind] != store->entity_kind_alloc_gens[kind]) + CTRL_EntityCtxLookupAccel *accel = ctrl_thread_entity_ctx_lookup_accel(); + if(accel->entity_kind_arrays_gens[kind] != ctx->entity_kind_alloc_gens[kind]) { Temp scratch = scratch_begin(0, 0); CTRL_EntityList entities = {0}; - for(CTRL_Entity *e = store->ctx.root; + for(CTRL_Entity *e = ctx->root; e != &ctrl_entity_nil; - e = ctrl_entity_rec_depth_first_pre(e, store->ctx.root).next) + e = ctrl_entity_rec_depth_first_pre(e, ctx->root).next) { if(e->kind == kind) { ctrl_entity_list_push(scratch.arena, &entities, e); } } - store->entity_kind_arrays_gens[kind] = store->entity_kind_alloc_gens[kind]; - arena_clear(store->entity_kind_arrays_arenas[kind]); - store->entity_kind_arrays[kind] = ctrl_entity_array_from_list(store->entity_kind_arrays_arenas[kind], &entities); + accel->entity_kind_arrays_gens[kind] = ctx->entity_kind_alloc_gens[kind]; + arena_clear(accel->entity_kind_arrays_arenas[kind]); + accel->entity_kind_arrays[kind] = ctrl_entity_array_from_list(accel->entity_kind_arrays_arenas[kind], &entities); scratch_end(scratch); } - return store->entity_kind_arrays[kind]; + return accel->entity_kind_arrays[kind]; } internal CTRL_EntityList -ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_key) +ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityCtx *ctx, DI_Key *dbgi_key) { CTRL_EntityList list = {0}; - CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(store, CTRL_EntityKind_Module); + CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(ctx, CTRL_EntityKind_Module); for EachIndex(idx, all_modules.count) { CTRL_Entity *module = all_modules.v[idx]; @@ -1162,10 +1175,10 @@ ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_k } internal CTRL_Entity * -ctrl_thread_from_id(CTRL_EntityStore *store, U64 id) +ctrl_thread_from_id(CTRL_EntityCtx *ctx, U64 id) { CTRL_Entity *thread = &ctrl_entity_nil; - CTRL_EntityArray threads = ctrl_entity_array_from_kind(store, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(ctx, CTRL_EntityKind_Thread); for EachIndex(idx, threads.count) { if(threads.v[idx]->id == id) @@ -1203,7 +1216,7 @@ ctrl_entity_rec_depth_first(CTRL_Entity *entity, CTRL_Entity *subtree_root, U64 //- rjf: applying events to entity caches internal void -ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) +ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *list) { //- rjf: scan events & construct entities for(CTRL_EventNode *n = list->first; n != 0; n = n->next) @@ -1245,7 +1258,7 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) { ctrl_entity_equip_string(store, thread, str8_lit("main_thread")); } - CTRL_EntityArray pending_thread_names = ctrl_entity_array_from_kind(store, CTRL_EntityKind_PendingThreadName); + CTRL_EntityArray pending_thread_names = ctrl_entity_array_from_kind(&store->ctx, CTRL_EntityKind_PendingThreadName); for EachIndex(idx, pending_thread_names.count) { CTRL_Entity *entity = pending_thread_names.v[idx]; @@ -1256,7 +1269,7 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) break; } } - CTRL_EntityArray pending_thread_colors = ctrl_entity_array_from_kind(store, CTRL_EntityKind_PendingThreadColor); + CTRL_EntityArray pending_thread_colors = ctrl_entity_array_from_kind(&store->ctx, CTRL_EntityKind_PendingThreadColor); for EachIndex(idx, pending_thread_colors.count) { CTRL_Entity *entity = pending_thread_colors.v[idx]; @@ -1285,7 +1298,7 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) } else { - thread = ctrl_thread_from_id(store, event->entity_id); + thread = ctrl_thread_from_id(&store->ctx, event->entity_id); } if(thread != &ctrl_entity_nil) { @@ -1307,7 +1320,7 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) } else { - thread = ctrl_thread_from_id(store, event->entity_id); + thread = ctrl_thread_from_id(&store->ctx, event->entity_id); } if(thread != &ctrl_entity_nil) { @@ -1471,7 +1484,7 @@ ctrl_init(void) scratch_end(scratch); } ctrl_state->ctrl_thread_entity_ctx_rw_mutex = os_rw_mutex_alloc(); - ctrl_state->ctrl_thread_entity_store = ctrl_entity_store_alloc(); + ctrl_state->ctrl_thread_entity_store = ctrl_entity_ctx_rw_store_alloc(); ctrl_state->ctrl_thread_eval_cache = e_cache_alloc(); ctrl_state->dmn_event_arena = arena_alloc(); ctrl_state->user_entry_point_arena = arena_alloc(); @@ -3404,7 +3417,10 @@ ctrl_c2u_push_events(CTRL_EventList *events) { if(events->count != 0) ProfScope("ctrl_c2u_push_events") { - ctrl_entity_store_apply_events(ctrl_state->ctrl_thread_entity_store, events); + OS_MutexScopeW(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) + { + ctrl_entity_store_apply_events(ctrl_state->ctrl_thread_entity_store, events); + } for(CTRL_EventNode *n = events->first; n != 0; n = n ->next) { Temp scratch = scratch_begin(0, 0); @@ -3525,12 +3541,14 @@ ctrl_thread__entry_point(void *p) }break; case CTRL_MsgKind_SetModuleDebugInfoPath: { + CTRL_EntityCtxRWStore *entity_store = ctrl_state->ctrl_thread_entity_store; + CTRL_EntityCtx *entity_ctx = &entity_store->ctx; String8 path = msg->path; - CTRL_Entity *module = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, msg->entity); + 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 = {debug_info_path->string, debug_info_path->timestamp}; di_close(&old_dbgi_key); - ctrl_entity_equip_string(ctrl_state->ctrl_thread_entity_store, debug_info_path, path); + OS_MutexScopeW(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) ctrl_entity_equip_string(entity_store, debug_info_path, path); U64 new_dbgi_timestamp = os_properties_from_file_path(path).modified; debug_info_path->timestamp = new_dbgi_timestamp; DI_Key new_dbgi_key = {debug_info_path->string, new_dbgi_timestamp}; @@ -3588,7 +3606,8 @@ ctrl_thread__append_resolved_module_user_bp_traps(Arena *arena, CTRL_EvalScope * if(user_bps->first == 0) { return; } Temp scratch = scratch_begin(&arena, 1); DI_Scope *di_scope = eval_scope->di_scope; - CTRL_Entity *module_entity = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, module); + CTRL_EntityCtx *entity_ctx = &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 = {debug_info_path_entity->string, debug_info_path_entity->timestamp}; RDI_Parsed *rdi = di_rdi_from_key(di_scope, &dbgi_key, max_U64); @@ -4086,6 +4105,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; //- rjf: loop -> try to get event, run, repeat U64 spoof_old_ip_value = 0; @@ -4158,7 +4178,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, (spoof == 0 || ev->instruction_pointer != spoof->new_ip_value)) { DI_Scope *di_scope = di_scope_open(); - CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, ev->process)); + CTRL_Entity *process = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, ev->process)); CTRL_Entity *module = &ctrl_entity_nil; for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next) { @@ -4249,7 +4269,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, U64 size_of_spoof = 0; if(do_spoof) ProfScope("prep spoof") { - CTRL_Entity *spoof_process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, spoof->process)); + CTRL_Entity *spoof_process = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, spoof->process)); Arch arch = spoof_process->arch; size_of_spoof = bit_size_from_arch(arch)/8; dmn_process_read(spoof_process->handle.dmn_handle, r1u64(spoof->vaddr, spoof->vaddr+size_of_spoof), &spoof_old_ip_value); @@ -4315,7 +4335,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, // simply been sent other debug events first if(spoof != 0) { - CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, spoof->thread)); + CTRL_Entity *thread = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, spoof->thread)); Arch arch = thread->arch; void *regs_block = push_array(scratch.arena, U8, regs_block_size_from_arch(arch)); dmn_thread_read_reg_block(spoof->thread, regs_block); @@ -4407,7 +4427,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, { CTRL_Event *out_evt = ctrl_event_list_push(scratch.arena, &evts); CTRL_Handle module_handle = ctrl_handle_make(CTRL_MachineID_Local, event->module); - CTRL_Entity *module_ent = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, module_handle); + CTRL_Entity *module_ent = ctrl_entity_from_handle(entity_ctx, module_handle); CTRL_Entity *process_ent = ctrl_process_from_entity(module_ent); String8 module_path = event->string; ctrl_thread__module_close(process_ent->handle, module_handle, module_ent->vaddr_range); @@ -4500,16 +4520,16 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, // dealing with insane-town projects) // if(event->kind == DMN_EventKind_LoadModule && - (ctrl_state->ctrl_thread_entity_store->entity_kind_counts[CTRL_EntityKind_Module] > 256 || - ctrl_state->ctrl_thread_entity_store->entity_kind_counts[CTRL_EntityKind_Module] == 1)) + (entity_ctx->entity_kind_counts[CTRL_EntityKind_Module] > 256 || + entity_ctx->entity_kind_counts[CTRL_EntityKind_Module] == 1)) { U64 endt_us = os_now_microseconds() + 1000000; //- rjf: unpack event CTRL_Handle process_handle = ctrl_handle_make(CTRL_MachineID_Local, event->process); CTRL_Handle loaded_module_handle = ctrl_handle_make(CTRL_MachineID_Local, event->module); - CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, process_handle); - CTRL_Entity *loaded_module = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, loaded_module_handle); + CTRL_Entity *process = ctrl_entity_from_handle(entity_ctx, process_handle); + CTRL_Entity *loaded_module = ctrl_entity_from_handle(entity_ctx, loaded_module_handle); //- rjf: for each module, use its full path as the start to a new limited recursive // directory search. cache each directory once traversed in the dbg_dir tree. if any @@ -4726,8 +4746,9 @@ ctrl_eval_space_read(void *u, 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; U64 regs_size = regs_block_size_from_arch(entity->arch); - void *regs = ctrl_reg_block_from_thread(scratch.arena, &ctrl_state->ctrl_thread_entity_store->ctx, entity->handle); + void *regs = ctrl_reg_block_from_thread(scratch.arena, entity_ctx, entity->handle); Rng1U64 legal_range = r1u64(0, regs_size); Rng1U64 read_range = intersect_1u64(legal_range, range); U64 read_size = dim_1u64(read_range); @@ -4752,6 +4773,7 @@ ctrl_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range) internal CTRL_EvalScope * ctrl_thread__eval_scope_begin(Arena *arena, CTRL_Entity *thread) { + CTRL_EntityCtx *entity_ctx = &ctrl_state->ctrl_thread_entity_store->ctx; CTRL_EvalScope *scope = push_array(arena, CTRL_EvalScope, 1); scope->di_scope = di_scope_open(); @@ -4767,14 +4789,14 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_Entity *thread) ////////////////////////////// //- rjf: gather evaluation modules // - U64 eval_modules_count = Max(1, ctrl_state->ctrl_thread_entity_store->entity_kind_counts[CTRL_EntityKind_Module]); + U64 eval_modules_count = Max(1, entity_ctx->entity_kind_counts[CTRL_EntityKind_Module]); E_Module *eval_modules = push_array(arena, E_Module, eval_modules_count); E_Module *eval_modules_primary = &eval_modules[0]; eval_modules_primary->rdi = &rdi_parsed_nil; eval_modules_primary->vaddr_range = r1u64(0, max_U64); { U64 eval_module_idx = 0; - for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->ctx.root->first; + for(CTRL_Entity *machine = entity_ctx->root->first; machine != &ctrl_entity_nil; machine = machine->next) { @@ -5065,9 +5087,10 @@ 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; //- rjf: gather all currently existing processes - CTRL_EntityArray initial_processes = ctrl_entity_array_from_kind(ctrl_state->ctrl_thread_entity_store, CTRL_EntityKind_Process); + CTRL_EntityArray initial_processes = ctrl_entity_array_from_kind(entity_ctx, CTRL_EntityKind_Process); typedef struct Task Task; struct Task { @@ -5112,7 +5135,7 @@ ctrl_thread__kill_all(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) default:{}break; case DMN_EventKind_CreateProcess: { - CTRL_Entity *new_process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); + CTRL_Entity *new_process = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); Task *t = push_array(scratch.arena, Task, 1); t->process = new_process; DLLPushBack(first_task, last_task, t); @@ -5122,7 +5145,7 @@ ctrl_thread__kill_all(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) } // rjf: end if all processes are gone - CTRL_EntityArray processes = ctrl_entity_array_from_kind(ctrl_state->ctrl_thread_entity_store, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(entity_ctx, CTRL_EntityKind_Process); if(processes.count == 0) { done = 1; @@ -5201,9 +5224,10 @@ 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_Handle target_thread = msg->entity; CTRL_Handle target_process = msg->parent; - CTRL_Entity *target_process_entity = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, target_process); + CTRL_Entity *target_process_entity = ctrl_entity_from_handle(entity_ctx, target_process); U64 spoof_ip_vaddr = 911; log_infof("ctrl_thread__run:\n{\n"); @@ -5212,9 +5236,9 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) // DMN_TrapChunkList user_traps = {0}; { - CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, target_thread); + CTRL_Entity *thread = ctrl_entity_from_handle(entity_ctx, target_thread); CTRL_EvalScope *eval_scope = ctrl_thread__eval_scope_begin(scratch.arena, thread); - for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->ctx.root->first; + for(CTRL_Entity *machine = entity_ctx->root->first; machine != &ctrl_entity_nil; machine = machine->next) { @@ -5527,7 +5551,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) }break; case DMN_EventKind_LoadModule: { - CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->thread)); + CTRL_Entity *thread = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, event->thread)); CTRL_EvalScope *eval_scope = ctrl_thread__eval_scope_begin(scratch.arena, thread); { DMN_TrapChunkList new_traps = {0}; @@ -5552,7 +5576,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) { CTRL_Entity *bp = &ctrl_entity_nil; { - CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); + CTRL_Entity *process = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next) { if(child->kind == CTRL_EntityKind_Breakpoint && @@ -5584,7 +5608,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) DI_Scope *di_scope = di_scope_open(); //- rjf: unpack process/module info - CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); + CTRL_Entity *process = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); CTRL_Entity *module = ctrl_entity_child_from_kind(process, CTRL_EntityKind_Module); U64 module_base_vaddr = module->vaddr_range.min; CTRL_Entity *dbg_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); @@ -5808,8 +5832,8 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) ////////////////////////// //- rjf: unpack info about thread attached to event // - CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->thread)); - CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); + CTRL_Entity *thread = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, event->thread)); + CTRL_Entity *process = ctrl_entity_from_handle(entity_ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process)); Arch arch = thread->arch; U64 thread_rip_vaddr = dmn_rip_from_thread(event->thread); CTRL_Entity *module = &ctrl_entity_nil; @@ -6631,23 +6655,20 @@ ASYNC_WORK_DEF(ctrl_call_stack_build_work) CTRL_CallStackCacheStripe *stripe = &cache->stripes[stripe_idx]; //- rjf: do task -#if 0 - OS_MutexScopeR(ctrl_state->call_stack_builder_entity_store_rw_mutex) + OS_MutexScopeR(ctrl_state->ctrl_thread_entity_ctx_rw_mutex) { Temp scratch = scratch_begin(0, 0); - CTRL_EntityStore *store = ctrl_state->call_stack_builder_entity_store; + CTRL_EntityCtx *ctx = &ctrl_state->ctrl_thread_entity_store->ctx; + CTRL_Entity *thread = ctrl_entity_from_handle(ctx, thread_handle); + CTRL_Entity *process = ctrl_process_from_entity(thread); //- rjf: compute unwind to find list of all concrete frames, then // call stack, to determine list of all concrete & inline frames - CTRL_Unwind unwind = ctrl_unwind_from_thread(scratch.arena, store, thread_handle, os_now_microseconds()+1000000); - CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena); - - //- rjf: use debug info to to list of all (concrete & inline) frames - + CTRL_Unwind unwind = ctrl_unwind_from_thread(scratch.arena, ctx, thread_handle, os_now_microseconds()+1000000); + CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, process, &unwind); scratch_end(scratch); } -#endif return 0; } diff --git a/src/ctrl/ctrl_core.h b/src/ctrl/ctrl_core.h index 1d455584..d7249831 100644 --- a/src/ctrl/ctrl_core.h +++ b/src/ctrl/ctrl_core.h @@ -182,23 +182,29 @@ typedef struct CTRL_EntityCtx CTRL_EntityCtx; struct CTRL_EntityCtx { CTRL_Entity *root; - CTRL_EntityHashSlot *hash_slots; U64 hash_slots_count; + CTRL_EntityHashSlot *hash_slots; + U64 entity_kind_counts[CTRL_EntityKind_COUNT]; + U64 entity_kind_alloc_gens[CTRL_EntityKind_COUNT]; }; -typedef struct CTRL_EntityStore CTRL_EntityStore; -struct CTRL_EntityStore +typedef struct CTRL_EntityCtxRWStore CTRL_EntityCtxRWStore; +struct CTRL_EntityCtxRWStore { Arena *arena; CTRL_EntityCtx ctx; CTRL_Entity *free; CTRL_EntityHashNode *hash_node_free; CTRL_EntityStringChunkNode *free_string_chunks[ArrayCount(ctrl_entity_string_bucket_chunk_sizes)]; - U64 entity_kind_counts[CTRL_EntityKind_COUNT]; +}; + +typedef struct CTRL_EntityCtxLookupAccel CTRL_EntityCtxLookupAccel; +struct CTRL_EntityCtxLookupAccel +{ + Arena *arena; Arena *entity_kind_arrays_arenas[CTRL_EntityKind_COUNT]; - U64 entity_kind_arrays_gens[CTRL_EntityKind_COUNT]; - U64 entity_kind_alloc_gens[CTRL_EntityKind_COUNT]; CTRL_EntityArray entity_kind_arrays[CTRL_EntityKind_COUNT]; + U64 entity_kind_arrays_gens[CTRL_EntityKind_COUNT]; }; //////////////////////////////// @@ -751,7 +757,7 @@ struct CTRL_State OS_Handle ctrl_thread; Log *ctrl_thread_log; OS_Handle ctrl_thread_entity_ctx_rw_mutex; - CTRL_EntityStore *ctrl_thread_entity_store; + CTRL_EntityCtxRWStore *ctrl_thread_entity_store; E_Cache *ctrl_thread_eval_cache; Arena *dmn_event_arena; DMN_EventNode *first_dmn_event_node; @@ -793,6 +799,7 @@ read_only global CTRL_Entity ctrl_entity_nil = &ctrl_entity_nil, &ctrl_entity_nil, }; +thread_static CTRL_EntityCtxLookupAccel *ctrl_entity_ctx_lookup_accel = 0; //////////////////////////////// //~ rjf: Logging Markup @@ -892,29 +899,30 @@ internal CTRL_EntityRec ctrl_entity_rec_depth_first(CTRL_Entity *entity, CTRL_En #define ctrl_entity_rec_depth_first_pre(entity, subtree_root) ctrl_entity_rec_depth_first((entity), (subtree_root), OffsetOf(CTRL_Entity, next), OffsetOf(CTRL_Entity, first)) #define ctrl_entity_rec_depth_first_post(entity, subtree_root) ctrl_entity_rec_depth_first((entity), (subtree_root), OffsetOf(CTRL_Entity, prev), OffsetOf(CTRL_Entity, last)) -//- rjf: cache creation/destruction -internal CTRL_EntityStore *ctrl_entity_store_alloc(void); -internal void ctrl_entity_store_release(CTRL_EntityStore *store); +//- rjf: entity ctx r/w store state functions +internal CTRL_EntityCtxRWStore *ctrl_entity_ctx_rw_store_alloc(void); +internal void ctrl_entity_ctx_rw_store_release(CTRL_EntityCtxRWStore *store); //- rjf: string allocation/deletion internal U64 ctrl_name_bucket_num_from_string_size(U64 size); -internal String8 ctrl_entity_string_alloc(CTRL_EntityStore *store, String8 string); -internal void ctrl_entity_string_release(CTRL_EntityStore *store, String8 string); +internal String8 ctrl_entity_string_alloc(CTRL_EntityCtxRWStore *store, String8 string); +internal void ctrl_entity_string_release(CTRL_EntityCtxRWStore *store, String8 string); //- rjf: entity construction/deletion -internal CTRL_Entity *ctrl_entity_alloc(CTRL_EntityStore *store, CTRL_Entity *parent, CTRL_EntityKind kind, Arch arch, CTRL_Handle handle, U64 id); -internal void ctrl_entity_release(CTRL_EntityStore *store, CTRL_Entity *entity); +internal CTRL_Entity *ctrl_entity_alloc(CTRL_EntityCtxRWStore *store, CTRL_Entity *parent, CTRL_EntityKind kind, Arch arch, CTRL_Handle handle, U64 id); +internal void ctrl_entity_release(CTRL_EntityCtxRWStore *store, CTRL_Entity *entity); //- rjf: entity equipment -internal void ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *entity, String8 string); +internal void ctrl_entity_equip_string(CTRL_EntityCtxRWStore *store, CTRL_Entity *entity, String8 string); -//- rjf: entity store lookups -internal CTRL_EntityArray ctrl_entity_array_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind); -internal CTRL_EntityList ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_key); -internal CTRL_Entity *ctrl_thread_from_id(CTRL_EntityStore *store, U64 id); +//- rjf: accelerated entity context lookups +internal CTRL_EntityCtxLookupAccel *ctrl_thread_entity_ctx_lookup_accel(void); +internal CTRL_EntityArray ctrl_entity_array_from_kind(CTRL_EntityCtx *ctx, CTRL_EntityKind kind); +internal CTRL_EntityList ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityCtx *ctx, DI_Key *dbgi_key); +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_EntityStore *store, CTRL_EventList *list); +internal void ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *list); //////////////////////////////// //~ rjf: Main Layer Initialization diff --git a/src/dbg_engine/dbg_engine_core.c b/src/dbg_engine/dbg_engine_core.c index e3dbf114..3a9e9bb8 100644 --- a/src/dbg_engine/dbg_engine_core.c +++ b/src/dbg_engine/dbg_engine_core.c @@ -1187,7 +1187,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, CTRL_EntityKind_Module); + CTRL_EntityArray modules = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); for EachIndex(idx, modules.count) { CTRL_Entity *module = modules.v[idx]; @@ -1484,7 +1484,7 @@ d_init(void) d_state->cmds_arena = arena_alloc(); d_state->output_log_key = hs_hash_from_data(str8_lit("output_log_key")); hs_submit_data(d_state->output_log_key, 0, str8_zero()); - d_state->ctrl_entity_store = ctrl_entity_store_alloc(); + 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(); @@ -1614,7 +1614,7 @@ 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, CTRL_EntityKind_Process); + CTRL_EntityArray existing_processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(existing_processes.count == 1) { MTX_Op op = {r1u64(0, 0xffffffffffffffffull), str8_lit("[new session]\n")}; @@ -1697,7 +1697,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, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); for EachIndex(idx, threads.count) { CTRL_Entity *thread = threads.v[idx]; @@ -1908,7 +1908,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, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); if(threads.count > 0) { for EachIndex(idx, threads.count) @@ -2064,7 +2064,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, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { d_cmd(D_CmdKind_Continue); @@ -2076,7 +2076,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, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { d_cmd(D_CmdKind_KillAll); @@ -2086,7 +2086,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, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { D_CmdKind step_cmd_kind = (cmd->kind == D_CmdKind_StepInto diff --git a/src/dbg_engine/dbg_engine_core.h b/src/dbg_engine/dbg_engine_core.h index 536f852b..4e7b2f04 100644 --- a/src/dbg_engine/dbg_engine_core.h +++ b/src/dbg_engine/dbg_engine_core.h @@ -343,7 +343,7 @@ struct D_State CTRL_MsgList ctrl_msgs; // rjf: ctrl -> user reading state - CTRL_EntityStore *ctrl_entity_store; + CTRL_EntityCtxRWStore *ctrl_entity_store; Arena *ctrl_stop_arena; CTRL_Event ctrl_last_stop_event; }; diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index f2330d73..04fb7fe3 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -2710,7 +2710,7 @@ rd_view_ui(Rng2F32 rect) UI_Padding(ui_pct(1, 0)) UI_Focus(UI_FocusKind_Null) { RD_CfgList targets = rd_cfg_top_level_list_from_string(scratch.arena, str8_lit("target")); - CTRL_EntityArray processes = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); //- rjf: icon & info UI_Padding(ui_em(2.f, 1.f)) UI_TagF("weak") @@ -6668,7 +6668,7 @@ rd_window_frame(void) { rd_cmd(RD_CmdKind_AddTarget, .file_path = n->string); } - CTRL_EntityArray processes = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { rd_cmd(RD_CmdKind_KillAll); @@ -6687,7 +6687,7 @@ rd_window_frame(void) { rd_cmd(RD_CmdKind_AddTarget, .file_path = n->string); } - CTRL_EntityArray processes = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count != 0) { rd_cmd(RD_CmdKind_KillAll); @@ -7839,7 +7839,7 @@ rd_window_frame(void) { Temp scratch = scratch_begin(0, 0); RD_CfgList targets = rd_cfg_top_level_list_from_string(scratch.arena, str8_lit("target")); - CTRL_EntityArray processes = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); B32 can_send_signal = !d_ctrl_targets_running(); typedef struct CenterButtonTask CenterButtonTask; struct CenterButtonTask @@ -11617,7 +11617,7 @@ rd_frame(void) 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); - CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Module); + CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(&d_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]; @@ -11977,7 +11977,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, kind); + CTRL_EntityArray array = ctrl_entity_array_from_kind(&d_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) { @@ -12303,7 +12303,7 @@ rd_frame(void) //- rjf: gather config from loaded modules // RD_CfgList immediate_type_views = {0}; - CTRL_EntityArray modules = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Module); + CTRL_EntityArray modules = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Module); for EachIndex(idx, modules.count) { CTRL_Entity *module = modules.v[idx]; @@ -12475,7 +12475,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, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count == 0 || kind == RD_CmdKind_Restart) { RD_CfgList bps = rd_cfg_top_level_list_from_string(scratch.arena, str8_lit("breakpoint")); @@ -12631,7 +12631,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, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_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)) { @@ -14008,7 +14008,7 @@ rd_frame(void) 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, &n->v.dbgi_key); + 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); if(module != &ctrl_entity_nil) { @@ -14466,7 +14466,7 @@ rd_frame(void) U64 vaddr = 0; if(voff_dbgi_key.path.size != 0) { - CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &voff_dbgi_key); + CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, &d_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) @@ -14564,7 +14564,7 @@ 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, &n->v.dbgi_key); + 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); vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); break; @@ -15507,7 +15507,7 @@ 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, &n->v.dbgi_key); + 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); if(module != &ctrl_entity_nil) { @@ -16372,7 +16372,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, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(evt->code == 0 && processes.count == 0) { rd_cmd(RD_CmdKind_Exit); @@ -16409,7 +16409,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, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_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 79094843..f1d37d5c 100644 --- a/src/raddbg/raddbg_eval.c +++ b/src/raddbg/raddbg_eval.c @@ -1323,7 +1323,7 @@ E_TYPE_EXPAND_INFO_FUNCTION_DEF(unattached_processes) } else { - machines = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Machine); + machines = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Machine); } //- rjf: gather system processes from this machine @@ -1428,7 +1428,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, kind); + CTRL_EntityArray entities = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, kind); if(0 <= rhs_idx && rhs_idx < entities.count) { entity = entities.v[rhs_idx]; @@ -1470,7 +1470,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, entity_kind); + array = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, entity_kind); } else { diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index 27fb0679..72413ee0 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -261,7 +261,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla 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, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); for EachIndex(idx, threads.count) { CTRL_Entity *thread = threads.v[idx]; @@ -337,7 +337,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla 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, CTRL_EntityKind_Thread); + CTRL_EntityArray threads = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Thread); for EachIndex(idx, threads.count) { CTRL_Entity *thread = threads.v[idx]; diff --git a/src/raddbg/raddbg_widgets.c b/src/raddbg/raddbg_widgets.c index 57218fb7..689e215c 100644 --- a/src/raddbg/raddbg_widgets.c +++ b/src/raddbg/raddbg_widgets.c @@ -483,7 +483,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, CTRL_EntityKind_Process); + CTRL_EntityArray processes = ctrl_entity_array_from_kind(&d_state->ctrl_entity_store->ctx, CTRL_EntityKind_Process); if(processes.count > 1) { CTRL_Entity *process = ctrl_entity_ancestor_from_kind(entity, CTRL_EntityKind_Process); @@ -2325,7 +2325,7 @@ 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, &n->v.dbgi_key); + 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); if(module != &ctrl_entity_nil) {