mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-09-24 02:00:05 +00:00
merge ctrl_init / d_init
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,4 +399,9 @@ struct D_TrapNet
|
||||
B32 good_read;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Layer Initialization
|
||||
|
||||
internal void d_init(void);
|
||||
|
||||
#endif // DBG_ENGINE_CORE_H
|
||||
|
||||
+137
-217
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user