From fee500578a5bef189ec5b98e10f3aee73a01f450 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Sun, 8 Sep 2024 10:50:00 -0700 Subject: [PATCH] get trap net generation off of d_entities and onto ctrl entities; decouple debug engine stepping/running from d_entities --- src/ctrl/ctrl_core.c | 159 +++++++++++++++++++++++++++++++ src/ctrl/ctrl_core.h | 42 ++++++++ src/dbg_engine/dbg_engine_core.c | 106 +++++++++------------ src/dbg_engine/dbg_engine_core.h | 10 +- 4 files changed, 252 insertions(+), 65 deletions(-) diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 60a115be..93aea4b1 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -520,6 +520,10 @@ ctrl_entity_store_alloc(void) store->arena = arena; store->hash_slots_count = 1024; store->hash_slots = push_array(arena, CTRL_EntityHashSlot, store->hash_slots_count); + for(EachEnumVal(CTRL_EntityKind, k)) + { + store->entity_kind_lists_arenas[k] = arena_alloc(); + } CTRL_Entity *root = store->root = ctrl_entity_alloc(store, &ctrl_entity_nil, CTRL_EntityKind_Root, Arch_Null, 0, dmn_handle_zero(), 0); CTRL_Entity *local_machine = ctrl_entity_alloc(store, root, CTRL_EntityKind_Machine, arch_from_context(), CTRL_MachineID_Local, dmn_handle_zero(), 0); (void)local_machine; @@ -808,6 +812,161 @@ ctrl_entity_child_from_kind(CTRL_Entity *parent, CTRL_EntityKind kind) return result; } +internal CTRL_Entity * +ctrl_entity_ancestor_from_kind(CTRL_Entity *entity, CTRL_EntityKind kind) +{ + CTRL_Entity *result = &ctrl_entity_nil; + for(CTRL_Entity *p = entity->parent; p != &ctrl_entity_nil; p = p->parent) + { + if(p->kind == kind) + { + result = p; + break; + } + } + return result; +} + +internal CTRL_Entity * +ctrl_module_from_process_vaddr(CTRL_Entity *process, U64 vaddr) +{ + CTRL_Entity *result = &ctrl_entity_nil; + for(CTRL_Entity *child = process->first; + child != &ctrl_entity_nil; + child = child->next) + { + if(child->kind == CTRL_EntityKind_Module && contains_1u64(child->vaddr_range, vaddr)) + { + result = child; + break; + } + } + return result; +} + +internal DI_Key +ctrl_dbgi_key_from_module(CTRL_Entity *module) +{ + CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); + DI_Key dbgi_key = {debug_info_path->string, debug_info_path->timestamp}; + return dbgi_key; +} + +internal CTRL_EntityList +ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_key) +{ + CTRL_EntityList list = {0}; + CTRL_EntityList all_modules = ctrl_entity_list_from_kind(store, CTRL_EntityKind_Module); + for(CTRL_EntityNode *n = all_modules.first; n != 0; n = n->next) + { + CTRL_Entity *module = n->v; + DI_Key module_dbgi_key = ctrl_dbgi_key_from_module(module); + if(di_key_match(&module_dbgi_key, dbgi_key)) + { + ctrl_entity_list_push(arena, &list, module); + } + } + return list; +} + +internal CTRL_Entity * +ctrl_module_from_thread_candidates(CTRL_EntityStore *store, CTRL_Entity *thread, CTRL_EntityList *candidates) +{ + CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); + U64 thread_rip_vaddr = ctrl_query_cached_rip_from_thread(store, thread->machine_id, thread->handle); + CTRL_Entity *src_module = ctrl_module_from_process_vaddr(process, thread_rip_vaddr); + CTRL_Entity *module = &ctrl_entity_nil; + for(CTRL_EntityNode *n = candidates->first; n != 0; n = n->next) + { + CTRL_Entity *candidate_module = n->v; + CTRL_Entity *candidate_process = ctrl_entity_ancestor_from_kind(candidate_module, CTRL_EntityKind_Process); + if(candidate_process == process) + { + module = candidate_module; + } + if(candidate_module == src_module) + { + break; + } + } + return module; +} + +internal CTRL_EntityList +ctrl_entity_list_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind) +{ + if(store->entity_kind_lists_gens[kind] != store->entity_kind_alloc_gens[kind]) + { + arena_clear(store->entity_kind_lists_arenas[kind]); + for(CTRL_Entity *e = store->root; + e != &ctrl_entity_nil; + e = ctrl_entity_rec_depth_first_pre(e, store->root).next) + { + if(e->kind == kind) + { + ctrl_entity_list_push(store->entity_kind_lists_arenas[kind], &store->entity_kind_lists[kind], e); + } + } + store->entity_kind_lists_gens[kind] = store->entity_kind_alloc_gens[kind]; + } + return store->entity_kind_lists[kind]; +} + +internal U64 +ctrl_vaddr_from_voff(CTRL_Entity *module, U64 voff) +{ + U64 result = voff + module->vaddr_range.min; + return result; +} + +internal U64 +ctrl_voff_from_vaddr(CTRL_Entity *module, U64 vaddr) +{ + U64 result = vaddr - module->vaddr_range.min; + return result; +} + +internal Rng1U64 +ctrl_vaddr_range_from_voff_range(CTRL_Entity *module, Rng1U64 voff_range) +{ + U64 dim = dim_1u64(voff_range); + U64 min = ctrl_vaddr_from_voff(module, voff_range.min); + Rng1U64 result = {min, min+dim}; + return result; +} + +internal Rng1U64 +ctrl_voff_range_from_vaddr_range(CTRL_Entity *module, Rng1U64 vaddr_range) +{ + U64 dim = dim_1u64(vaddr_range); + U64 min = ctrl_voff_from_vaddr(module, vaddr_range.min); + Rng1U64 result = {min, min+dim}; + return result; +} + +//- rjf: entity tree iteration + +internal CTRL_EntityRec +ctrl_entity_rec_depth_first(CTRL_Entity *entity, CTRL_Entity *subtree_root, U64 sib_off, U64 child_off) +{ + CTRL_EntityRec result = {0}; + if((*MemberFromOffset(CTRL_Entity **, entity, child_off)) != &ctrl_entity_nil) + { + result.next = *MemberFromOffset(CTRL_Entity **, entity, child_off); + result.push_count = 1; + } + else for(CTRL_Entity *parent = entity; parent != subtree_root && parent != &ctrl_entity_nil; parent = parent->parent) + { + if(parent != subtree_root && (*MemberFromOffset(CTRL_Entity **, parent, sib_off)) != &ctrl_entity_nil) + { + result.next = *MemberFromOffset(CTRL_Entity **, parent, sib_off); + break; + } + result.pop_count += 1; + } + return result; +} + //- rjf: applying events to entity caches internal void diff --git a/src/ctrl/ctrl_core.h b/src/ctrl/ctrl_core.h index 4c849997..346f257d 100644 --- a/src/ctrl/ctrl_core.h +++ b/src/ctrl/ctrl_core.h @@ -72,6 +72,29 @@ struct CTRL_Entity String8 string; }; +typedef struct CTRL_EntityNode CTRL_EntityNode; +struct CTRL_EntityNode +{ + CTRL_EntityNode *next; + CTRL_Entity *v; +}; + +typedef struct CTRL_EntityList CTRL_EntityList; +struct CTRL_EntityList +{ + CTRL_EntityNode *first; + CTRL_EntityNode *last; + U64 count; +}; + +typedef struct CTRL_EntityRec CTRL_EntityRec; +struct CTRL_EntityRec +{ + CTRL_Entity *next; + S32 push_count; + S64 pop_count; +}; + typedef struct CTRL_EntityHashNode CTRL_EntityHashNode; struct CTRL_EntityHashNode { @@ -105,6 +128,10 @@ struct CTRL_EntityStore U64 hash_slots_count; CTRL_EntityStringChunkNode *free_string_chunks[8]; U64 entity_kind_counts[CTRL_EntityKind_COUNT]; + Arena *entity_kind_lists_arenas[CTRL_EntityKind_COUNT]; + U64 entity_kind_lists_gens[CTRL_EntityKind_COUNT]; + U64 entity_kind_alloc_gens[CTRL_EntityKind_COUNT]; + CTRL_EntityList entity_kind_lists[CTRL_EntityKind_COUNT]; }; //////////////////////////////// @@ -705,6 +732,21 @@ internal void ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *ent //- rjf: entity store lookups internal CTRL_Entity *ctrl_entity_from_machine_id_handle(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle handle); internal CTRL_Entity *ctrl_entity_child_from_kind(CTRL_Entity *parent, CTRL_EntityKind kind); +internal CTRL_Entity *ctrl_entity_ancestor_from_kind(CTRL_Entity *entity, CTRL_EntityKind kind); +internal CTRL_Entity *ctrl_module_from_process_vaddr(CTRL_Entity *process, U64 vaddr); +internal DI_Key ctrl_dbgi_key_from_module(CTRL_Entity *module); +internal CTRL_EntityList ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_key); +internal CTRL_Entity *ctrl_module_from_thread_candidates(CTRL_EntityStore *store, CTRL_Entity *thread, CTRL_EntityList *candidates); +internal CTRL_EntityList ctrl_entity_list_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind); +internal U64 ctrl_vaddr_from_voff(CTRL_Entity *module, U64 voff); +internal U64 ctrl_voff_from_vaddr(CTRL_Entity *module, U64 vaddr); +internal Rng1U64 ctrl_vaddr_range_from_voff_range(CTRL_Entity *module, Rng1U64 voff_range); +internal Rng1U64 ctrl_voff_range_from_vaddr_range(CTRL_Entity *module, Rng1U64 vaddr_range); + +//- rjf: entity tree iteration +internal CTRL_EntityRec ctrl_entity_rec_depth_first(CTRL_Entity *entity, CTRL_Entity *subtree_root, U64 sib_off, U64 child_off); +#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: applying events to entity caches internal void ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list); diff --git a/src/dbg_engine/dbg_engine_core.c b/src/dbg_engine/dbg_engine_core.c index d66fe8fe..bff2c66f 100644 --- a/src/dbg_engine/dbg_engine_core.c +++ b/src/dbg_engine/dbg_engine_core.c @@ -1991,22 +1991,6 @@ d_entity_from_name_and_kind(String8 string, D_EntityKind kind) return result; } -internal D_Entity * -d_entity_from_u64_and_kind(U64 u64, D_EntityKind kind) -{ - D_Entity *result = &d_nil_entity; - D_EntityList all_of_this_kind = d_query_cached_entity_list_with_kind(kind); - for(D_EntityNode *n = all_of_this_kind.first; n != 0; n = n->next) - { - if(n->entity->u64 == u64) - { - result = n->entity; - break; - } - } - return result; -} - //- rjf: entity freezing state internal void @@ -2299,21 +2283,21 @@ d_view_rule_spec_from_string(String8 string) // at them with the "save-stack-pointer | single-step-after" behaviors. internal CTRL_TrapList -d_trap_net_from_thread__step_over_inst(Arena *arena, D_Entity *thread) +d_trap_net_from_thread__step_over_inst(Arena *arena, CTRL_Entity *thread) { Temp scratch = scratch_begin(&arena, 1); CTRL_TrapList result = {0}; // rjf: thread => unpacked info - D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); - Arch arch = d_arch_from_entity(thread); - U64 ip_vaddr = ctrl_query_cached_rip_from_thread(d_state->ctrl_entity_store, thread->ctrl_machine_id, thread->ctrl_handle); + CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); + Arch arch = thread->arch; + U64 ip_vaddr = ctrl_query_cached_rip_from_thread(d_state->ctrl_entity_store, thread->machine_id, thread->handle); // rjf: ip => machine code String8 machine_code = {0}; { Rng1U64 rng = r1u64(ip_vaddr, ip_vaddr+max_instruction_size_from_arch(arch)); - CTRL_ProcessMemorySlice machine_code_slice = ctrl_query_cached_data_from_process_vaddr_range(scratch.arena, process->ctrl_machine_id, process->ctrl_handle, rng, os_now_microseconds()+5000); + CTRL_ProcessMemorySlice machine_code_slice = ctrl_query_cached_data_from_process_vaddr_range(scratch.arena, process->machine_id, process->handle, rng, os_now_microseconds()+5000); machine_code = machine_code_slice.data; } @@ -2336,31 +2320,31 @@ d_trap_net_from_thread__step_over_inst(Arena *arena, D_Entity *thread) } internal CTRL_TrapList -d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread) +d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread) { Temp scratch = scratch_begin(&arena, 1); log_infof("step_over_line:\n{\n"); CTRL_TrapList result = {0}; // rjf: thread => info - D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); - D_Entity *module = d_module_from_thread(thread); - DI_Key dbgi_key = d_dbgi_key_from_module(module); - Arch arch = d_arch_from_entity(thread); - U64 ip_vaddr = ctrl_query_cached_rip_from_thread(d_state->ctrl_entity_store, thread->ctrl_machine_id, thread->ctrl_handle); + Arch arch = thread->arch; + U64 ip_vaddr = ctrl_query_cached_rip_from_thread(d_state->ctrl_entity_store, thread->machine_id, 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); log_infof("ip_vaddr: 0x%I64x\n", ip_vaddr); log_infof("dbgi_key: {%S, 0x%I64x}\n", dbgi_key.path, dbgi_key.min_timestamp); // rjf: ip => line vaddr range Rng1U64 line_vaddr_rng = {0}; { - U64 ip_voff = d_voff_from_vaddr(module, ip_vaddr); + U64 ip_voff = ctrl_voff_from_vaddr(module, ip_vaddr); D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, &dbgi_key, ip_voff); Rng1U64 line_voff_rng = {0}; if(lines.first != 0) { line_voff_rng = lines.first->v.voff_range; - line_vaddr_rng = d_vaddr_range_from_voff_range(module, line_voff_rng); + line_vaddr_rng = ctrl_vaddr_range_from_voff_range(module, line_voff_rng); log_infof("line: {%S:%I64i}\n", lines.first->v.file_path, lines.first->v.pt.line); } log_infof("voff_range: {0x%I64x, 0x%I64x}\n", line_voff_rng.min, line_voff_rng.max); @@ -2372,11 +2356,11 @@ d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread) // MSVC exports line info at these line numbers when /JMC (Just My Code) debugging // is enabled. This is enabled by default normally. { - U64 opl_line_voff_rng = d_voff_from_vaddr(module, line_vaddr_rng.max); + U64 opl_line_voff_rng = ctrl_voff_from_vaddr(module, line_vaddr_rng.max); D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, &dbgi_key, opl_line_voff_rng); if(lines.first != 0 && (lines.first->v.pt.line == 0xf00f00 || lines.first->v.pt.line == 0xfeefee)) { - line_vaddr_rng.max = d_vaddr_from_voff(module, lines.first->v.voff_range.max); + line_vaddr_rng.max = ctrl_vaddr_from_voff(module, lines.first->v.voff_range.max); } } @@ -2387,7 +2371,7 @@ d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread) String8 machine_code = {0}; if(good_line_info) { - CTRL_ProcessMemorySlice machine_code_slice = ctrl_query_cached_data_from_process_vaddr_range(scratch.arena, process->ctrl_machine_id, process->ctrl_handle, line_vaddr_rng, os_now_microseconds()+50000); + CTRL_ProcessMemorySlice machine_code_slice = ctrl_query_cached_data_from_process_vaddr_range(scratch.arena, process->machine_id, process->handle, line_vaddr_rng, os_now_microseconds()+50000); machine_code = machine_code_slice.data; LogInfoNamedBlockF("machine_code_slice") { @@ -2498,28 +2482,28 @@ d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread) } internal CTRL_TrapList -d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread) +d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread) { Temp scratch = scratch_begin(&arena, 1); CTRL_TrapList result = {0}; // rjf: thread => info - D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process); - D_Entity *module = d_module_from_thread(thread); - DI_Key dbgi_key = d_dbgi_key_from_module(module); - Arch arch = d_arch_from_entity(thread); - U64 ip_vaddr = ctrl_query_cached_rip_from_thread(d_state->ctrl_entity_store, thread->ctrl_machine_id, thread->ctrl_handle); + Arch arch = thread->arch; + U64 ip_vaddr = ctrl_query_cached_rip_from_thread(d_state->ctrl_entity_store, thread->machine_id, thread->handle); + CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); + CTRL_Entity *module = ctrl_module_from_process_vaddr(thread, ip_vaddr); + DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); // rjf: ip => line vaddr range Rng1U64 line_vaddr_rng = {0}; { - U64 ip_voff = d_voff_from_vaddr(module, ip_vaddr); + U64 ip_voff = ctrl_voff_from_vaddr(module, ip_vaddr); D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, &dbgi_key, ip_voff); Rng1U64 line_voff_rng = {0}; if(lines.first != 0) { line_voff_rng = lines.first->v.voff_range; - line_vaddr_rng = d_vaddr_range_from_voff_range(module, line_voff_rng); + line_vaddr_rng = ctrl_vaddr_range_from_voff_range(module, line_voff_rng); } } @@ -2528,11 +2512,11 @@ d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread) // MSVC exports line info at these line numbers when /JMC (Just My Code) debugging // is enabled. This is enabled by default normally. { - U64 opl_line_voff_rng = d_voff_from_vaddr(module, line_vaddr_rng.max); + U64 opl_line_voff_rng = ctrl_voff_from_vaddr(module, line_vaddr_rng.max); D_LineList lines = d_lines_from_dbgi_key_voff(scratch.arena, &dbgi_key, opl_line_voff_rng); if(lines.first != 0 && (lines.first->v.pt.line == 0xf00f00 || lines.first->v.pt.line == 0xfeefee)) { - line_vaddr_rng.max = d_vaddr_from_voff(module, lines.first->v.voff_range.max); + line_vaddr_rng.max = ctrl_vaddr_from_voff(module, lines.first->v.voff_range.max); } } @@ -2543,7 +2527,7 @@ d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread) String8 machine_code = {0}; if(good_line_info) { - CTRL_ProcessMemorySlice machine_code_slice = ctrl_query_cached_data_from_process_vaddr_range(scratch.arena, process->ctrl_machine_id, process->ctrl_handle, line_vaddr_rng, os_now_microseconds()+5000); + CTRL_ProcessMemorySlice machine_code_slice = ctrl_query_cached_data_from_process_vaddr_range(scratch.arena, process->machine_id, process->handle, line_vaddr_rng, os_now_microseconds()+5000); machine_code = machine_code_slice.data; } @@ -6788,7 +6772,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ // rjf: prep ctrl running arguments B32 need_run = 0; D_RunKind run_kind = D_RunKind_Run; - D_Entity *run_thread = &d_nil_entity; + CTRL_Entity *run_thread = &ctrl_entity_nil; CTRL_RunFlags run_flags = 0; CTRL_TrapList run_traps = {0}; @@ -6887,7 +6871,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ // rjf: run need_run = 1; run_kind = D_RunKind_Run; - run_thread = &d_nil_entity; + run_thread = &ctrl_entity_nil; run_flags = (core_cmd_kind == D_CmdKind_LaunchAndInit) ? CTRL_RunFlag_StopOnEntryPoint : 0; } @@ -6991,7 +6975,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ { need_run = 1; run_kind = D_RunKind_Run; - run_thread = &d_nil_entity; + run_thread = &ctrl_entity_nil; } else { @@ -7006,7 +6990,8 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ case D_CmdKind_StepOverLine: case D_CmdKind_StepOut: { - D_Entity *thread = d_entity_from_handle(params.entity); + D_Entity *d_thread = d_entity_from_handle(params.entity); + CTRL_Entity *thread = ctrl_entity_from_machine_id_handle(d_state->ctrl_entity_store, d_thread->ctrl_machine_id, d_thread->ctrl_handle); if(d_ctrl_targets_running()) { if(d_ctrl_last_run_kind() == D_RunKind_Run) @@ -7016,7 +7001,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ d_cmd_list_push(arena, cmds, &p, d_cmd_spec_from_kind(D_CmdKind_Error)); } } - else if(d_entity_is_frozen(thread)) + else if(d_entity_is_frozen(d_thread)) { D_CmdParams p = params; p.string = str8_lit("Must thaw selected thread before stepping."); @@ -7036,7 +7021,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ case D_CmdKind_StepOut: { // rjf: thread => full unwind - CTRL_Unwind unwind = ctrl_unwind_from_thread(scratch.arena, d_state->ctrl_entity_store, thread->ctrl_machine_id, thread->ctrl_handle, os_now_microseconds()+10000); + CTRL_Unwind unwind = ctrl_unwind_from_thread(scratch.arena, d_state->ctrl_entity_store, thread->machine_id, thread->handle, os_now_microseconds()+10000); // rjf: use first unwind frame to generate trap if(unwind.flags == 0 && unwind.frames.count > 1) @@ -7083,7 +7068,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ { need_run = 1; run_kind = d_state->ctrl_last_run_kind; - run_thread = d_entity_from_handle(d_state->ctrl_last_run_thread); + run_thread = ctrl_entity_from_machine_id_handle(d_state->ctrl_entity_store, d_state->ctrl_last_run_thread_machine_id, d_state->ctrl_last_run_thread_handle); run_flags = d_state->ctrl_last_run_flags; run_traps = d_state->ctrl_last_run_traps; } @@ -8374,11 +8359,11 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ // rjf: build run message CTRL_Msg msg = {(run_kind == D_RunKind_Run || run_kind == D_RunKind_Step) ? CTRL_MsgKind_Run : CTRL_MsgKind_SingleStep}; { - D_Entity *process = d_entity_ancestor_from_kind(run_thread, D_EntityKind_Process); + CTRL_Entity *process = ctrl_entity_ancestor_from_kind(run_thread, CTRL_EntityKind_Process); msg.run_flags = run_flags; - msg.machine_id = run_thread->ctrl_machine_id; - msg.entity = run_thread->ctrl_handle; - msg.parent = process->ctrl_handle; + msg.machine_id = run_thread->machine_id; + msg.entity = run_thread->handle; + msg.parent = process->handle; MemoryCopyArray(msg.exception_code_filters, d_state->ctrl_exception_code_filters); MemoryCopyStruct(&msg.traps, &run_traps); for(U64 idx = 0; idx < breakpoints->count; idx += 1) @@ -8438,12 +8423,13 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, DI_ // 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 = d_handle_from_entity(run_thread); - 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_is_running = 1; + d_state->ctrl_last_run_kind = run_kind; + d_state->ctrl_last_run_frame_idx = d_frame_index(); + d_state->ctrl_last_run_thread_machine_id = run_thread->machine_id; + 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_is_running = 1; // rjf: reset selected frame to top unwind d_state->base_regs.v.unwind_count = 0; diff --git a/src/dbg_engine/dbg_engine_core.h b/src/dbg_engine/dbg_engine_core.h index 77545e20..1f3da902 100644 --- a/src/dbg_engine/dbg_engine_core.h +++ b/src/dbg_engine/dbg_engine_core.h @@ -1055,7 +1055,8 @@ struct D_State Arena *ctrl_last_run_arena; D_RunKind ctrl_last_run_kind; U64 ctrl_last_run_frame_idx; - D_Handle ctrl_last_run_thread; + CTRL_MachineID ctrl_last_run_thread_machine_id; + DMN_Handle ctrl_last_run_thread_handle; CTRL_RunFlags ctrl_last_run_flags; CTRL_TrapList ctrl_last_run_traps; U128 ctrl_last_run_param_state_hash; @@ -1303,7 +1304,6 @@ internal D_Entity *d_machine_entity_from_machine_id(CTRL_MachineID machine_id); internal D_Entity *d_entity_from_ctrl_handle(CTRL_MachineID machine_id, DMN_Handle handle); internal D_Entity *d_entity_from_ctrl_id(CTRL_MachineID machine_id, U32 id); internal D_Entity *d_entity_from_name_and_kind(String8 string, D_EntityKind kind); -internal D_Entity *d_entity_from_u64_and_kind(U64 u64, D_EntityKind kind); //- rjf: entity freezing state internal void d_set_thread_freeze_state(D_Entity *thread, B32 frozen); @@ -1327,9 +1327,9 @@ internal D_ViewRuleSpec *d_view_rule_spec_from_string(String8 string); //////////////////////////////// //~ rjf: Stepping "Trap Net" Builders -internal CTRL_TrapList d_trap_net_from_thread__step_over_inst(Arena *arena, D_Entity *thread); -internal CTRL_TrapList d_trap_net_from_thread__step_over_line(Arena *arena, D_Entity *thread); -internal CTRL_TrapList d_trap_net_from_thread__step_into_line(Arena *arena, D_Entity *thread); +internal CTRL_TrapList d_trap_net_from_thread__step_over_inst(Arena *arena, CTRL_Entity *thread); +internal CTRL_TrapList d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread); +internal CTRL_TrapList d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread); //////////////////////////////// //~ rjf: Modules & Debug Info Mappings