split read-only ctrl entity operations from read-write ctrl entity operations, represent in type system via EntityCtx vs. EntityStore

This commit is contained in:
Ryan Fleury
2025-05-14 18:35:25 -07:00
parent e513af5361
commit 1e6b3ee2e6
7 changed files with 407 additions and 359 deletions
+292 -249
View File
@@ -653,12 +653,12 @@ ctrl_entity_list_push(Arena *arena, CTRL_EntityList *list, CTRL_Entity *entity)
} }
internal CTRL_EntityList internal CTRL_EntityList
ctrl_entity_list_from_handle_list(Arena *arena, CTRL_EntityStore *store, CTRL_HandleList *list) ctrl_entity_list_from_handle_list(Arena *arena, CTRL_EntityCtx *ctx, CTRL_HandleList *list)
{ {
CTRL_EntityList result = {0}; CTRL_EntityList result = {0};
for(CTRL_HandleNode *n = list->first; n != 0; n = n->next) for(CTRL_HandleNode *n = list->first; n != 0; n = n->next)
{ {
CTRL_Entity *entity = ctrl_entity_from_handle(store, n->v); CTRL_Entity *entity = ctrl_entity_from_handle(ctx, n->v);
ctrl_entity_list_push(arena, &result, entity); ctrl_entity_list_push(arena, &result, entity);
} }
return result; return result;
@@ -680,6 +680,172 @@ ctrl_entity_array_from_list(Arena *arena, CTRL_EntityList *list)
return result; return result;
} }
//- rjf: entity context (entity group read-only) functions
internal CTRL_Entity *
ctrl_entity_from_handle(CTRL_EntityCtx *ctx, CTRL_Handle handle)
{
CTRL_Entity *entity = &ctrl_entity_nil;
if(!ctrl_handle_match(handle, ctrl_handle_zero()))
{
U64 hash = ctrl_hash_from_handle(handle);
U64 slot_idx = hash%ctx->hash_slots_count;
CTRL_EntityHashSlot *slot = &ctx->hash_slots[slot_idx];
CTRL_EntityHashNode *node = 0;
for(CTRL_EntityHashNode *n = slot->first; n != 0; n = n->next)
{
if(ctrl_handle_match(n->entity->handle, handle))
{
entity = n->entity;
break;
}
}
}
return entity;
}
internal CTRL_Entity *
ctrl_entity_child_from_kind(CTRL_Entity *parent, CTRL_EntityKind kind)
{
CTRL_Entity *result = &ctrl_entity_nil;
for(CTRL_Entity *child = parent->first;
child != &ctrl_entity_nil;
child = child->next)
{
if(child->kind == kind)
{
result = child;
break;
}
}
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_process_from_entity(CTRL_Entity *entity)
{
CTRL_Entity *result = &ctrl_entity_nil;
if(entity->kind == CTRL_EntityKind_Process)
{
result = entity;
}
else
{
result = ctrl_entity_ancestor_from_kind(entity, CTRL_EntityKind_Process);
}
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_Entity *
ctrl_module_from_thread_candidates(CTRL_EntityCtx *ctx, CTRL_Entity *thread, CTRL_EntityList *candidates)
{
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
U64 thread_rip_vaddr = ctrl_rip_from_thread(ctx, 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 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;
}
internal B32
ctrl_entity_tree_is_frozen(CTRL_Entity *root)
{
B32 is_frozen = 1;
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 && !e->is_frozen)
{
is_frozen = 0;
break;
}
}
return is_frozen;
}
//- rjf: cache creation/destruction //- rjf: cache creation/destruction
internal CTRL_EntityStore * internal CTRL_EntityStore *
@@ -688,13 +854,13 @@ ctrl_entity_store_alloc(void)
Arena *arena = arena_alloc(); Arena *arena = arena_alloc();
CTRL_EntityStore *store = push_array(arena, CTRL_EntityStore, 1); CTRL_EntityStore *store = push_array(arena, CTRL_EntityStore, 1);
store->arena = arena; store->arena = arena;
store->hash_slots_count = 1024; store->ctx.hash_slots_count = 1024;
store->hash_slots = push_array(arena, CTRL_EntityHashSlot, store->hash_slots_count); store->ctx.hash_slots = push_array(arena, CTRL_EntityHashSlot, store->ctx.hash_slots_count);
for EachEnumVal(CTRL_EntityKind, k) for EachEnumVal(CTRL_EntityKind, k)
{ {
store->entity_kind_arrays_arenas[k] = arena_alloc(); store->entity_kind_arrays_arenas[k] = arena_alloc();
} }
CTRL_Entity *root = store->root = ctrl_entity_alloc(store, &ctrl_entity_nil, CTRL_EntityKind_Root, Arch_Null, ctrl_handle_zero(), 0); CTRL_Entity *root = store->ctx.root = ctrl_entity_alloc(store, &ctrl_entity_nil, CTRL_EntityKind_Root, Arch_Null, ctrl_handle_zero(), 0);
CTRL_Entity *local_machine = ctrl_entity_alloc(store, root, CTRL_EntityKind_Machine, arch_from_context(), ctrl_handle_make(CTRL_MachineID_Local, dmn_handle_zero()), 0); CTRL_Entity *local_machine = ctrl_entity_alloc(store, root, CTRL_EntityKind_Machine, arch_from_context(), ctrl_handle_make(CTRL_MachineID_Local, dmn_handle_zero()), 0);
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
String8 local_machine_name = push_str8f(scratch.arena, "This PC (%S)", os_get_system_info()->machine_name); String8 local_machine_name = push_str8f(scratch.arena, "This PC (%S)", os_get_system_info()->machine_name);
@@ -846,8 +1012,8 @@ ctrl_entity_alloc(CTRL_EntityStore *store, CTRL_Entity *parent, CTRL_EntityKind
// rjf: insert into hash map // rjf: insert into hash map
{ {
U64 hash = ctrl_hash_from_handle(handle); U64 hash = ctrl_hash_from_handle(handle);
U64 slot_idx = hash%store->hash_slots_count; U64 slot_idx = hash%store->ctx.hash_slots_count;
CTRL_EntityHashSlot *slot = &store->hash_slots[slot_idx]; CTRL_EntityHashSlot *slot = &store->ctx.hash_slots[slot_idx];
CTRL_EntityHashNode *node = 0; CTRL_EntityHashNode *node = 0;
for(CTRL_EntityHashNode *n = slot->first; n != 0; n = n->next) for(CTRL_EntityHashNode *n = slot->first; n != 0; n = n->next)
{ {
@@ -918,8 +1084,8 @@ ctrl_entity_release(CTRL_EntityStore *store, CTRL_Entity *entity)
// rjf: remove from hash map // rjf: remove from hash map
{ {
U64 hash = ctrl_hash_from_handle(t->e->handle); U64 hash = ctrl_hash_from_handle(t->e->handle);
U64 slot_idx = hash%store->hash_slots_count; U64 slot_idx = hash%store->ctx.hash_slots_count;
CTRL_EntityHashSlot *slot = &store->hash_slots[slot_idx]; CTRL_EntityHashSlot *slot = &store->ctx.hash_slots[slot_idx];
CTRL_EntityHashNode *node = 0; CTRL_EntityHashNode *node = 0;
for(CTRL_EntityHashNode *n = slot->first; n != 0; n = n->next) for(CTRL_EntityHashNode *n = slot->first; n != 0; n = n->next)
{ {
@@ -954,113 +1120,28 @@ ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *entity, String8 s
//- rjf: entity store lookups //- rjf: entity store lookups
internal CTRL_Entity * internal CTRL_EntityArray
ctrl_entity_from_handle(CTRL_EntityStore *store, CTRL_Handle handle) ctrl_entity_array_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind)
{ {
CTRL_Entity *entity = &ctrl_entity_nil; if(store->entity_kind_arrays_gens[kind] != store->entity_kind_alloc_gens[kind])
if(!ctrl_handle_match(handle, ctrl_handle_zero()))
{ {
U64 hash = ctrl_hash_from_handle(handle); Temp scratch = scratch_begin(0, 0);
U64 slot_idx = hash%store->hash_slots_count; CTRL_EntityList entities = {0};
CTRL_EntityHashSlot *slot = &store->hash_slots[slot_idx]; for(CTRL_Entity *e = store->ctx.root;
CTRL_EntityHashNode *node = 0; e != &ctrl_entity_nil;
for(CTRL_EntityHashNode *n = slot->first; n != 0; n = n->next) e = ctrl_entity_rec_depth_first_pre(e, store->ctx.root).next)
{ {
if(ctrl_handle_match(n->entity->handle, handle)) if(e->kind == kind)
{ {
entity = n->entity; ctrl_entity_list_push(scratch.arena, &entities, e);
break;
} }
} }
store->entity_kind_arrays_gens[kind] = store->entity_kind_alloc_gens[kind];
arena_clear(store->entity_kind_arrays_arenas[kind]);
store->entity_kind_arrays[kind] = ctrl_entity_array_from_list(store->entity_kind_arrays_arenas[kind], &entities);
scratch_end(scratch);
} }
return entity; return store->entity_kind_arrays[kind];
}
internal CTRL_Entity *
ctrl_entity_child_from_kind(CTRL_Entity *parent, CTRL_EntityKind kind)
{
CTRL_Entity *result = &ctrl_entity_nil;
for(CTRL_Entity *child = parent->first;
child != &ctrl_entity_nil;
child = child->next)
{
if(child->kind == kind)
{
result = child;
break;
}
}
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_process_from_entity(CTRL_Entity *entity)
{
CTRL_Entity *result = &ctrl_entity_nil;
if(entity->kind == CTRL_EntityKind_Process)
{
result = entity;
}
else
{
result = ctrl_entity_ancestor_from_kind(entity, CTRL_EntityKind_Process);
}
return result;
}
internal CTRL_Entity *
ctrl_thread_from_id(CTRL_EntityStore *store, U64 id)
{
CTRL_Entity *thread = &ctrl_entity_nil;
CTRL_EntityArray threads = ctrl_entity_array_from_kind(store, CTRL_EntityKind_Thread);
for EachIndex(idx, threads.count)
{
if(threads.v[idx]->id == id)
{
thread = threads.v[idx];
}
}
return thread;
}
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 internal CTRL_EntityList
@@ -1081,97 +1162,18 @@ ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_k
} }
internal CTRL_Entity * internal CTRL_Entity *
ctrl_module_from_thread_candidates(CTRL_EntityStore *store, CTRL_Entity *thread, CTRL_EntityList *candidates) ctrl_thread_from_id(CTRL_EntityStore *store, U64 id)
{ {
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *thread = &ctrl_entity_nil;
U64 thread_rip_vaddr = ctrl_rip_from_thread(store, thread->handle); CTRL_EntityArray threads = ctrl_entity_array_from_kind(store, CTRL_EntityKind_Thread);
CTRL_Entity *src_module = ctrl_module_from_process_vaddr(process, thread_rip_vaddr); for EachIndex(idx, threads.count)
CTRL_Entity *module = &ctrl_entity_nil;
for(CTRL_EntityNode *n = candidates->first; n != 0; n = n->next)
{ {
CTRL_Entity *candidate_module = n->v; if(threads.v[idx]->id == id)
CTRL_Entity *candidate_process = ctrl_entity_ancestor_from_kind(candidate_module, CTRL_EntityKind_Process);
if(candidate_process == process)
{ {
module = candidate_module; thread = threads.v[idx];
}
if(candidate_module == src_module)
{
break;
} }
} }
return module; return thread;
}
internal CTRL_EntityArray
ctrl_entity_array_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind)
{
if(store->entity_kind_arrays_gens[kind] != store->entity_kind_alloc_gens[kind])
{
Temp scratch = scratch_begin(0, 0);
CTRL_EntityList entities = {0};
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(scratch.arena, &entities, e);
}
}
store->entity_kind_arrays_gens[kind] = store->entity_kind_alloc_gens[kind];
arena_clear(store->entity_kind_arrays_arenas[kind]);
store->entity_kind_arrays[kind] = ctrl_entity_array_from_list(store->entity_kind_arrays_arenas[kind], &entities);
scratch_end(scratch);
}
return store->entity_kind_arrays[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;
}
internal B32
ctrl_entity_tree_is_frozen(CTRL_Entity *root)
{
B32 is_frozen = 1;
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 && !e->is_frozen)
{
is_frozen = 0;
break;
}
}
return is_frozen;
} }
//- rjf: entity tree iteration //- rjf: entity tree iteration
@@ -1214,14 +1216,14 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
//- rjf: processes //- rjf: processes
case CTRL_EventKind_NewProc: case CTRL_EventKind_NewProc:
{ {
CTRL_Entity *machine = ctrl_entity_from_handle(store, ctrl_handle_make(event->entity.machine_id, dmn_handle_zero())); CTRL_Entity *machine = ctrl_entity_from_handle(&store->ctx, ctrl_handle_make(event->entity.machine_id, dmn_handle_zero()));
CTRL_Entity *process = ctrl_entity_alloc(store, machine, CTRL_EntityKind_Process, event->arch, event->entity, (U64)event->entity_id); CTRL_Entity *process = ctrl_entity_alloc(store, machine, CTRL_EntityKind_Process, event->arch, event->entity, (U64)event->entity_id);
}break; }break;
case CTRL_EventKind_EndProc: case CTRL_EventKind_EndProc:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(store, event->entity); CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->entity);
ctrl_entity_release(store, process); ctrl_entity_release(store, process);
for(CTRL_Entity *entry = store->root->first, *next = &ctrl_entity_nil; for(CTRL_Entity *entry = store->ctx.root->first, *next = &ctrl_entity_nil;
entry != &ctrl_entity_nil; entry != &ctrl_entity_nil;
entry = next) entry = next)
{ {
@@ -1236,7 +1238,7 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
//- rjf: threads //- rjf: threads
case CTRL_EventKind_NewThread: case CTRL_EventKind_NewThread:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
CTRL_Entity *thread = ctrl_entity_alloc(store, process, CTRL_EntityKind_Thread, event->arch, event->entity, (U64)event->entity_id); CTRL_Entity *thread = ctrl_entity_alloc(store, process, CTRL_EntityKind_Thread, event->arch, event->entity, (U64)event->entity_id);
CTRL_Entity *first_thread = ctrl_entity_child_from_kind(process, CTRL_EntityKind_Thread); CTRL_Entity *first_thread = ctrl_entity_child_from_kind(process, CTRL_EntityKind_Thread);
if(first_thread == thread) if(first_thread == thread)
@@ -1266,20 +1268,20 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
} }
} }
thread->stack_base = event->stack_base; thread->stack_base = event->stack_base;
ctrl_rip_from_thread(store, event->entity); ctrl_rip_from_thread(&store->ctx, event->entity);
}break; }break;
case CTRL_EventKind_EndThread: case CTRL_EventKind_EndThread:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(store, event->entity); CTRL_Entity *thread = ctrl_entity_from_handle(&store->ctx, event->entity);
ctrl_entity_release(store, thread); ctrl_entity_release(store, thread);
}break; }break;
case CTRL_EventKind_ThreadName: case CTRL_EventKind_ThreadName:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
CTRL_Entity *thread = &ctrl_entity_nil; CTRL_Entity *thread = &ctrl_entity_nil;
if(event->entity_id == 0) if(event->entity_id == 0)
{ {
thread = ctrl_entity_from_handle(store, event->entity); thread = ctrl_entity_from_handle(&store->ctx, event->entity);
} }
else else
{ {
@@ -1297,11 +1299,11 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
}break; }break;
case CTRL_EventKind_ThreadColor: case CTRL_EventKind_ThreadColor:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
CTRL_Entity *thread = &ctrl_entity_nil; CTRL_Entity *thread = &ctrl_entity_nil;
if(event->entity_id == 0) if(event->entity_id == 0)
{ {
thread = ctrl_entity_from_handle(store, event->entity); thread = ctrl_entity_from_handle(&store->ctx, event->entity);
} }
else else
{ {
@@ -1319,12 +1321,12 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
}break; }break;
case CTRL_EventKind_ThreadFrozen: case CTRL_EventKind_ThreadFrozen:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(store, event->entity); CTRL_Entity *thread = ctrl_entity_from_handle(&store->ctx, event->entity);
thread->is_frozen = 1; thread->is_frozen = 1;
}break; }break;
case CTRL_EventKind_ThreadThawed: case CTRL_EventKind_ThreadThawed:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(store, event->entity); CTRL_Entity *thread = ctrl_entity_from_handle(&store->ctx, event->entity);
thread->is_frozen = 0; thread->is_frozen = 0;
}break; }break;
@@ -1332,7 +1334,7 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
case CTRL_EventKind_NewModule: case CTRL_EventKind_NewModule:
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
CTRL_Entity *module = ctrl_entity_alloc(store, process, CTRL_EntityKind_Module, event->arch, event->entity, event->vaddr_rng.min); CTRL_Entity *module = ctrl_entity_alloc(store, process, CTRL_EntityKind_Module, event->arch, event->entity, event->vaddr_rng.min);
ctrl_entity_equip_string(store, module, event->string); ctrl_entity_equip_string(store, module, event->string);
module->timestamp = event->timestamp; module->timestamp = event->timestamp;
@@ -1346,12 +1348,12 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
}break; }break;
case CTRL_EventKind_EndModule: case CTRL_EventKind_EndModule:
{ {
CTRL_Entity *module = ctrl_entity_from_handle(store, event->entity); CTRL_Entity *module = ctrl_entity_from_handle(&store->ctx, event->entity);
ctrl_entity_release(store, module); ctrl_entity_release(store, module);
}break; }break;
case CTRL_EventKind_ModuleDebugInfoPathChange: case CTRL_EventKind_ModuleDebugInfoPathChange:
{ {
CTRL_Entity *module = ctrl_entity_from_handle(store, event->entity); CTRL_Entity *module = ctrl_entity_from_handle(&store->ctx, event->entity);
CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath);
if(debug_info_path == &ctrl_entity_nil) if(debug_info_path == &ctrl_entity_nil)
{ {
@@ -1364,14 +1366,14 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
//- rjf: dynamic, program-created breakpoints //- rjf: dynamic, program-created breakpoints
case CTRL_EventKind_SetBreakpoint: case CTRL_EventKind_SetBreakpoint:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
CTRL_Entity *bp = ctrl_entity_alloc(store, process, CTRL_EntityKind_Breakpoint, Arch_Null, ctrl_handle_zero(), 0); CTRL_Entity *bp = ctrl_entity_alloc(store, process, CTRL_EntityKind_Breakpoint, Arch_Null, ctrl_handle_zero(), 0);
bp->vaddr_range = event->vaddr_rng; bp->vaddr_range = event->vaddr_rng;
bp->bp_flags = event->bp_flags; bp->bp_flags = event->bp_flags;
}break; }break;
case CTRL_EventKind_UnsetBreakpoint: case CTRL_EventKind_UnsetBreakpoint:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next) for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next)
{ {
if(child->kind == CTRL_EntityKind_Breakpoint && if(child->kind == CTRL_EntityKind_Breakpoint &&
@@ -1468,6 +1470,7 @@ ctrl_init(void)
os_write_data_to_file_path(ctrl_state->ctrl_thread_log_path, str8_zero()); os_write_data_to_file_path(ctrl_state->ctrl_thread_log_path, str8_zero());
scratch_end(scratch); scratch_end(scratch);
} }
ctrl_state->ctrl_thread_entity_ctx_rw_mutex = os_rw_mutex_alloc();
ctrl_state->ctrl_thread_entity_store = ctrl_entity_store_alloc(); ctrl_state->ctrl_thread_entity_store = ctrl_entity_store_alloc();
ctrl_state->ctrl_thread_eval_cache = e_cache_alloc(); ctrl_state->ctrl_thread_eval_cache = e_cache_alloc();
ctrl_state->dmn_event_arena = arena_alloc(); ctrl_state->dmn_event_arena = arena_alloc();
@@ -1937,10 +1940,10 @@ ctrl_process_write(CTRL_Handle process, Rng1U64 range, void *src)
//- rjf: thread register cache reading //- rjf: thread register cache reading
internal void * internal void *
ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle handle) ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle handle)
{ {
CTRL_ThreadRegCache *cache = &ctrl_state->thread_reg_cache; CTRL_ThreadRegCache *cache = &ctrl_state->thread_reg_cache;
CTRL_Entity *thread_entity = ctrl_entity_from_handle(store, handle); CTRL_Entity *thread_entity = ctrl_entity_from_handle(ctx, handle);
Arch arch = thread_entity->arch; Arch arch = thread_entity->arch;
U64 reg_block_size = regs_block_size_from_arch(arch); U64 reg_block_size = regs_block_size_from_arch(arch);
U64 hash = ctrl_hash_from_handle(handle); U64 hash = ctrl_hash_from_handle(handle);
@@ -1996,31 +1999,31 @@ ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle ha
} }
internal U64 internal U64
ctrl_tls_root_vaddr_from_thread(CTRL_EntityStore *store, CTRL_Handle handle) ctrl_tls_root_vaddr_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle)
{ {
U64 result = dmn_tls_root_vaddr_from_thread(handle.dmn_handle); U64 result = dmn_tls_root_vaddr_from_thread(handle.dmn_handle);
return result; return result;
} }
internal U64 internal U64
ctrl_rip_from_thread(CTRL_EntityStore *store, CTRL_Handle handle) ctrl_rip_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
CTRL_Entity *thread_entity = ctrl_entity_from_handle(store, handle); CTRL_Entity *thread_entity = ctrl_entity_from_handle(ctx, handle);
Arch arch = thread_entity->arch; Arch arch = thread_entity->arch;
void *block = ctrl_reg_block_from_thread(scratch.arena, store, handle); void *block = ctrl_reg_block_from_thread(scratch.arena, ctx, handle);
U64 result = regs_rip_from_arch_block(arch, block); U64 result = regs_rip_from_arch_block(arch, block);
scratch_end(scratch); scratch_end(scratch);
return result; return result;
} }
internal U64 internal U64
ctrl_rsp_from_thread(CTRL_EntityStore *store, CTRL_Handle handle) ctrl_rsp_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
CTRL_Entity *thread_entity = ctrl_entity_from_handle(store, handle); CTRL_Entity *thread_entity = ctrl_entity_from_handle(ctx, handle);
Arch arch = thread_entity->arch; Arch arch = thread_entity->arch;
void *block = ctrl_reg_block_from_thread(scratch.arena, store, handle); void *block = ctrl_reg_block_from_thread(scratch.arena, ctx, handle);
U64 result = regs_rsp_from_arch_block(arch, block); U64 result = regs_rsp_from_arch_block(arch, block);
scratch_end(scratch); scratch_end(scratch);
return result; return result;
@@ -3071,7 +3074,7 @@ ctrl_unwind_step(CTRL_Handle process, CTRL_Handle module, U64 module_base_vaddr,
//- rjf: abstracted full unwind //- rjf: abstracted full unwind
internal CTRL_Unwind internal CTRL_Unwind
ctrl_unwind_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle thread, U64 endt_us) ctrl_unwind_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle thread, U64 endt_us)
{ {
ProfBeginFunction(); ProfBeginFunction();
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -3079,13 +3082,13 @@ ctrl_unwind_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle threa
unwind.flags |= CTRL_UnwindFlag_Error; unwind.flags |= CTRL_UnwindFlag_Error;
//- rjf: unpack args //- rjf: unpack args
CTRL_Entity *thread_entity = ctrl_entity_from_handle(store, thread); CTRL_Entity *thread_entity = ctrl_entity_from_handle(ctx, thread);
CTRL_Entity *process_entity = thread_entity->parent; CTRL_Entity *process_entity = thread_entity->parent;
Arch arch = thread_entity->arch; Arch arch = thread_entity->arch;
U64 arch_reg_block_size = regs_block_size_from_arch(arch); U64 arch_reg_block_size = regs_block_size_from_arch(arch);
//- rjf: grab initial register block //- rjf: grab initial register block
void *regs_block = ctrl_reg_block_from_thread(scratch.arena, store, thread); void *regs_block = ctrl_reg_block_from_thread(scratch.arena, ctx, thread);
B32 regs_block_good = (arch != Arch_Null && regs_block != 0); B32 regs_block_good = (arch != Arch_Null && regs_block != 0);
//- rjf: loop & unwind //- rjf: loop & unwind
@@ -3158,9 +3161,10 @@ ctrl_unwind_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle threa
//~ rjf: Call Stack Building Functions //~ rjf: Call Stack Building Functions
internal CTRL_CallStack internal CTRL_CallStack
ctrl_call_stack_from_unwind(Arena *arena, DI_Scope *di_scope, CTRL_Entity *process, CTRL_Unwind *base_unwind) ctrl_call_stack_from_unwind(Arena *arena, CTRL_Entity *process, CTRL_Unwind *base_unwind)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
DI_Scope *di_scope = di_scope_open();
Arch arch = process->arch; Arch arch = process->arch;
CTRL_CallStack result = {0}; CTRL_CallStack result = {0};
{ {
@@ -3237,6 +3241,7 @@ ctrl_call_stack_from_unwind(Arena *arena, DI_Scope *di_scope, CTRL_Entity *proce
} }
} }
} }
di_scope_close(di_scope);
scratch_end(scratch); scratch_end(scratch);
return result; return result;
} }
@@ -3267,6 +3272,20 @@ ctrl_call_stack_frame_from_unwind_and_inline_depth(CTRL_CallStack *call_stack, U
return f; return f;
} }
////////////////////////////////
//~ rjf: Call Stack Cache Functions
internal CTRL_CallStack
ctrl_call_stack_from_thread(HS_Scope *hs_scope, CTRL_Entity *thread, U64 endt_us)
{
CTRL_CallStack call_stack = {0};
{
CTRL_Handle handle = thread->handle;
}
return call_stack;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Halting All Attached Processes //~ rjf: Halting All Attached Processes
@@ -3507,7 +3526,7 @@ ctrl_thread__entry_point(void *p)
case CTRL_MsgKind_SetModuleDebugInfoPath: case CTRL_MsgKind_SetModuleDebugInfoPath:
{ {
String8 path = msg->path; String8 path = msg->path;
CTRL_Entity *module = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, msg->entity); CTRL_Entity *module = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, msg->entity);
CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath);
DI_Key old_dbgi_key = {debug_info_path->string, debug_info_path->timestamp}; DI_Key old_dbgi_key = {debug_info_path->string, debug_info_path->timestamp};
di_close(&old_dbgi_key); di_close(&old_dbgi_key);
@@ -3569,7 +3588,7 @@ ctrl_thread__append_resolved_module_user_bp_traps(Arena *arena, CTRL_EvalScope *
if(user_bps->first == 0) { return; } if(user_bps->first == 0) { return; }
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
DI_Scope *di_scope = eval_scope->di_scope; DI_Scope *di_scope = eval_scope->di_scope;
CTRL_Entity *module_entity = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, module); CTRL_Entity *module_entity = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, module);
CTRL_Entity *debug_info_path_entity = ctrl_entity_child_from_kind(module_entity, CTRL_EntityKind_DebugInfoPath); CTRL_Entity *debug_info_path_entity = ctrl_entity_child_from_kind(module_entity, CTRL_EntityKind_DebugInfoPath);
DI_Key dbgi_key = {debug_info_path_entity->string, debug_info_path_entity->timestamp}; DI_Key dbgi_key = {debug_info_path_entity->string, debug_info_path_entity->timestamp};
RDI_Parsed *rdi = di_rdi_from_key(di_scope, &dbgi_key, max_U64); RDI_Parsed *rdi = di_rdi_from_key(di_scope, &dbgi_key, max_U64);
@@ -4139,7 +4158,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
(spoof == 0 || ev->instruction_pointer != spoof->new_ip_value)) (spoof == 0 || ev->instruction_pointer != spoof->new_ip_value))
{ {
DI_Scope *di_scope = di_scope_open(); DI_Scope *di_scope = di_scope_open();
CTRL_Entity *process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, ev->process)); CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, ev->process));
CTRL_Entity *module = &ctrl_entity_nil; CTRL_Entity *module = &ctrl_entity_nil;
for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next) for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next)
{ {
@@ -4230,7 +4249,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
U64 size_of_spoof = 0; U64 size_of_spoof = 0;
if(do_spoof) ProfScope("prep spoof") if(do_spoof) ProfScope("prep spoof")
{ {
CTRL_Entity *spoof_process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, spoof->process)); CTRL_Entity *spoof_process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, spoof->process));
Arch arch = spoof_process->arch; Arch arch = spoof_process->arch;
size_of_spoof = bit_size_from_arch(arch)/8; size_of_spoof = bit_size_from_arch(arch)/8;
dmn_process_read(spoof_process->handle.dmn_handle, r1u64(spoof->vaddr, spoof->vaddr+size_of_spoof), &spoof_old_ip_value); dmn_process_read(spoof_process->handle.dmn_handle, r1u64(spoof->vaddr, spoof->vaddr+size_of_spoof), &spoof_old_ip_value);
@@ -4296,7 +4315,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
// simply been sent other debug events first // simply been sent other debug events first
if(spoof != 0) if(spoof != 0)
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, spoof->thread)); CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, spoof->thread));
Arch arch = thread->arch; Arch arch = thread->arch;
void *regs_block = push_array(scratch.arena, U8, regs_block_size_from_arch(arch)); void *regs_block = push_array(scratch.arena, U8, regs_block_size_from_arch(arch));
dmn_thread_read_reg_block(spoof->thread, regs_block); dmn_thread_read_reg_block(spoof->thread, regs_block);
@@ -4388,7 +4407,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
{ {
CTRL_Event *out_evt = ctrl_event_list_push(scratch.arena, &evts); CTRL_Event *out_evt = ctrl_event_list_push(scratch.arena, &evts);
CTRL_Handle module_handle = ctrl_handle_make(CTRL_MachineID_Local, event->module); CTRL_Handle module_handle = ctrl_handle_make(CTRL_MachineID_Local, event->module);
CTRL_Entity *module_ent = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, module_handle); CTRL_Entity *module_ent = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, module_handle);
CTRL_Entity *process_ent = ctrl_process_from_entity(module_ent); CTRL_Entity *process_ent = ctrl_process_from_entity(module_ent);
String8 module_path = event->string; String8 module_path = event->string;
ctrl_thread__module_close(process_ent->handle, module_handle, module_ent->vaddr_range); ctrl_thread__module_close(process_ent->handle, module_handle, module_ent->vaddr_range);
@@ -4489,8 +4508,8 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
//- rjf: unpack event //- rjf: unpack event
CTRL_Handle process_handle = ctrl_handle_make(CTRL_MachineID_Local, event->process); CTRL_Handle process_handle = ctrl_handle_make(CTRL_MachineID_Local, event->process);
CTRL_Handle loaded_module_handle = ctrl_handle_make(CTRL_MachineID_Local, event->module); CTRL_Handle loaded_module_handle = ctrl_handle_make(CTRL_MachineID_Local, event->module);
CTRL_Entity *process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, process_handle); CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, process_handle);
CTRL_Entity *loaded_module = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, loaded_module_handle); CTRL_Entity *loaded_module = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, loaded_module_handle);
//- rjf: for each module, use its full path as the start to a new limited recursive //- rjf: for each module, use its full path as the start to a new limited recursive
// directory search. cache each directory once traversed in the dbg_dir tree. if any // directory search. cache each directory once traversed in the dbg_dir tree. if any
@@ -4708,7 +4727,7 @@ ctrl_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
U64 regs_size = regs_block_size_from_arch(entity->arch); U64 regs_size = regs_block_size_from_arch(entity->arch);
void *regs = ctrl_reg_block_from_thread(scratch.arena, ctrl_state->ctrl_thread_entity_store, entity->handle); void *regs = ctrl_reg_block_from_thread(scratch.arena, &ctrl_state->ctrl_thread_entity_store->ctx, entity->handle);
Rng1U64 legal_range = r1u64(0, regs_size); Rng1U64 legal_range = r1u64(0, regs_size);
Rng1U64 read_range = intersect_1u64(legal_range, range); Rng1U64 read_range = intersect_1u64(legal_range, range);
U64 read_size = dim_1u64(read_range); U64 read_size = dim_1u64(read_range);
@@ -4755,7 +4774,7 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_Entity *thread)
eval_modules_primary->vaddr_range = r1u64(0, max_U64); eval_modules_primary->vaddr_range = r1u64(0, max_U64);
{ {
U64 eval_module_idx = 0; U64 eval_module_idx = 0;
for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->root->first; for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->ctx.root->first;
machine != &ctrl_entity_nil; machine != &ctrl_entity_nil;
machine = machine->next) machine = machine->next)
{ {
@@ -4926,7 +4945,7 @@ ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
for(String8Node *n = msg->entry_points.first; n != 0; n = n->next) for(String8Node *n = msg->entry_points.first; n != 0; n = n->next)
{ {
String8 string = n->string; String8 string = n->string;
CTRL_Entity *entry = ctrl_entity_alloc(ctrl_state->ctrl_thread_entity_store, ctrl_state->ctrl_thread_entity_store->root, CTRL_EntityKind_EntryPoint, Arch_Null, ctrl_handle_zero(), (U64)id); CTRL_Entity *entry = ctrl_entity_alloc(ctrl_state->ctrl_thread_entity_store, ctrl_state->ctrl_thread_entity_store->ctx.root, CTRL_EntityKind_EntryPoint, Arch_Null, ctrl_handle_zero(), (U64)id);
ctrl_entity_equip_string(ctrl_state->ctrl_thread_entity_store, entry, string); ctrl_entity_equip_string(ctrl_state->ctrl_thread_entity_store, entry, string);
} }
} }
@@ -5093,7 +5112,7 @@ ctrl_thread__kill_all(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
default:{}break; default:{}break;
case DMN_EventKind_CreateProcess: case DMN_EventKind_CreateProcess:
{ {
CTRL_Entity *new_process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, event->process)); CTRL_Entity *new_process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process));
Task *t = push_array(scratch.arena, Task, 1); Task *t = push_array(scratch.arena, Task, 1);
t->process = new_process; t->process = new_process;
DLLPushBack(first_task, last_task, t); DLLPushBack(first_task, last_task, t);
@@ -5184,7 +5203,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
CTRL_EventCause stop_cause = CTRL_EventCause_Null; CTRL_EventCause stop_cause = CTRL_EventCause_Null;
CTRL_Handle target_thread = msg->entity; CTRL_Handle target_thread = msg->entity;
CTRL_Handle target_process = msg->parent; CTRL_Handle target_process = msg->parent;
CTRL_Entity *target_process_entity = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, target_process); CTRL_Entity *target_process_entity = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, target_process);
U64 spoof_ip_vaddr = 911; U64 spoof_ip_vaddr = 911;
log_infof("ctrl_thread__run:\n{\n"); log_infof("ctrl_thread__run:\n{\n");
@@ -5193,9 +5212,9 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
// //
DMN_TrapChunkList user_traps = {0}; DMN_TrapChunkList user_traps = {0};
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, target_thread); CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, target_thread);
CTRL_EvalScope *eval_scope = ctrl_thread__eval_scope_begin(scratch.arena, thread); CTRL_EvalScope *eval_scope = ctrl_thread__eval_scope_begin(scratch.arena, thread);
for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->root->first; for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->ctx.root->first;
machine != &ctrl_entity_nil; machine != &ctrl_entity_nil;
machine = machine->next) machine = machine->next)
{ {
@@ -5252,7 +5271,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
{ {
// rjf: gather stuck threads // rjf: gather stuck threads
DMN_HandleList stuck_threads = {0}; DMN_HandleList stuck_threads = {0};
for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->root->first; for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->ctx.root->first;
machine != &ctrl_entity_nil; machine != &ctrl_entity_nil;
machine = machine->next) machine = machine->next)
{ {
@@ -5357,7 +5376,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
//- rjf: gather frozen threads //- rjf: gather frozen threads
// //
CTRL_EntityList frozen_threads = {0}; CTRL_EntityList frozen_threads = {0};
for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->root->first; for(CTRL_Entity *machine = ctrl_state->ctrl_thread_entity_store->ctx.root->first;
machine != &ctrl_entity_nil; machine != &ctrl_entity_nil;
machine = machine->next) machine = machine->next)
{ {
@@ -5508,7 +5527,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
}break; }break;
case DMN_EventKind_LoadModule: case DMN_EventKind_LoadModule:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, event->thread)); CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->thread));
CTRL_EvalScope *eval_scope = ctrl_thread__eval_scope_begin(scratch.arena, thread); CTRL_EvalScope *eval_scope = ctrl_thread__eval_scope_begin(scratch.arena, thread);
{ {
DMN_TrapChunkList new_traps = {0}; DMN_TrapChunkList new_traps = {0};
@@ -5533,7 +5552,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
{ {
CTRL_Entity *bp = &ctrl_entity_nil; CTRL_Entity *bp = &ctrl_entity_nil;
{ {
CTRL_Entity *process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, event->process)); CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process));
for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next) for(CTRL_Entity *child = process->first; child != &ctrl_entity_nil; child = child->next)
{ {
if(child->kind == CTRL_EntityKind_Breakpoint && if(child->kind == CTRL_EntityKind_Breakpoint &&
@@ -5565,7 +5584,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
DI_Scope *di_scope = di_scope_open(); DI_Scope *di_scope = di_scope_open();
//- rjf: unpack process/module info //- rjf: unpack process/module info
CTRL_Entity *process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, event->process)); CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process));
CTRL_Entity *module = ctrl_entity_child_from_kind(process, CTRL_EntityKind_Module); CTRL_Entity *module = ctrl_entity_child_from_kind(process, CTRL_EntityKind_Module);
U64 module_base_vaddr = module->vaddr_range.min; U64 module_base_vaddr = module->vaddr_range.min;
CTRL_Entity *dbg_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath); CTRL_Entity *dbg_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath);
@@ -5641,7 +5660,7 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
//- rjf: add traps for PID-correllated entry points //- rjf: add traps for PID-correllated entry points
if(!entries_found) if(!entries_found)
{ {
for(CTRL_Entity *e = ctrl_state->ctrl_thread_entity_store->root->first; e != &ctrl_entity_nil; e = e->next) for(CTRL_Entity *e = ctrl_state->ctrl_thread_entity_store->ctx.root->first; e != &ctrl_entity_nil; e = e->next)
{ {
if(e->id == process->id) if(e->id == process->id)
{ {
@@ -5789,8 +5808,8 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
////////////////////////// //////////////////////////
//- rjf: unpack info about thread attached to event //- rjf: unpack info about thread attached to event
// //
CTRL_Entity *thread = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, event->thread)); CTRL_Entity *thread = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->thread));
CTRL_Entity *process = ctrl_entity_from_handle(ctrl_state->ctrl_thread_entity_store, ctrl_handle_make(CTRL_MachineID_Local, event->process)); CTRL_Entity *process = ctrl_entity_from_handle(&ctrl_state->ctrl_thread_entity_store->ctx, ctrl_handle_make(CTRL_MachineID_Local, event->process));
Arch arch = thread->arch; Arch arch = thread->arch;
U64 thread_rip_vaddr = dmn_rip_from_thread(event->thread); U64 thread_rip_vaddr = dmn_rip_from_thread(event->thread);
CTRL_Entity *module = &ctrl_entity_nil; CTRL_Entity *module = &ctrl_entity_nil;
@@ -6602,9 +6621,33 @@ ASYNC_WORK_DEF(ctrl_call_stack_build_work)
{ {
CTRL_CallStackCache *cache = &ctrl_state->call_stack_cache; CTRL_CallStackCache *cache = &ctrl_state->call_stack_cache;
//- rjf: get next request //- rjf: get next request & unpack
CTRL_Handle thread_handle = {0}; CTRL_Handle thread_handle = {0};
ctrl_u2csb_dequeue_req(&thread_handle); ctrl_u2csb_dequeue_req(&thread_handle);
U64 hash = ctrl_hash_from_handle(thread_handle);
U64 slot_idx = hash%cache->slots_count;
U64 stripe_idx = hash%cache->stripes_count;
CTRL_CallStackCacheSlot *slot = &cache->slots[slot_idx];
CTRL_CallStackCacheStripe *stripe = &cache->stripes[stripe_idx];
//- rjf: do task
#if 0
OS_MutexScopeR(ctrl_state->call_stack_builder_entity_store_rw_mutex)
{
Temp scratch = scratch_begin(0, 0);
CTRL_EntityStore *store = ctrl_state->call_stack_builder_entity_store;
//- rjf: compute unwind to find list of all concrete frames, then
// call stack, to determine list of all concrete & inline frames
CTRL_Unwind unwind = ctrl_unwind_from_thread(scratch.arena, store, thread_handle, os_now_microseconds()+1000000);
CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena);
//- rjf: use debug info to to list of all (concrete & inline) frames
scratch_end(scratch);
}
#endif
return 0; return 0;
} }
+43 -30
View File
@@ -178,15 +178,21 @@ read_only global U64 ctrl_entity_string_bucket_chunk_sizes[] =
0xffffffffffffffffull, 0xffffffffffffffffull,
}; };
typedef struct CTRL_EntityCtx CTRL_EntityCtx;
struct CTRL_EntityCtx
{
CTRL_Entity *root;
CTRL_EntityHashSlot *hash_slots;
U64 hash_slots_count;
};
typedef struct CTRL_EntityStore CTRL_EntityStore; typedef struct CTRL_EntityStore CTRL_EntityStore;
struct CTRL_EntityStore struct CTRL_EntityStore
{ {
Arena *arena; Arena *arena;
CTRL_Entity *root; CTRL_EntityCtx ctx;
CTRL_Entity *free; CTRL_Entity *free;
CTRL_EntityHashSlot *hash_slots;
CTRL_EntityHashNode *hash_node_free; CTRL_EntityHashNode *hash_node_free;
U64 hash_slots_count;
CTRL_EntityStringChunkNode *free_string_chunks[ArrayCount(ctrl_entity_string_bucket_chunk_sizes)]; CTRL_EntityStringChunkNode *free_string_chunks[ArrayCount(ctrl_entity_string_bucket_chunk_sizes)];
U64 entity_kind_counts[CTRL_EntityKind_COUNT]; U64 entity_kind_counts[CTRL_EntityKind_COUNT];
Arena *entity_kind_arrays_arenas[CTRL_EntityKind_COUNT]; Arena *entity_kind_arrays_arenas[CTRL_EntityKind_COUNT];
@@ -601,7 +607,6 @@ struct CTRL_CallStackCacheNode
CTRL_Handle thread; CTRL_Handle thread;
U64 reg_gen; U64 reg_gen;
U64 mem_gen; U64 mem_gen;
CTRL_Unwind unwind;
CTRL_CallStack call_stack; CTRL_CallStack call_stack;
}; };
@@ -745,6 +750,7 @@ struct CTRL_State
String8 ctrl_thread_log_path; String8 ctrl_thread_log_path;
OS_Handle ctrl_thread; OS_Handle ctrl_thread;
Log *ctrl_thread_log; Log *ctrl_thread_log;
OS_Handle ctrl_thread_entity_ctx_rw_mutex;
CTRL_EntityStore *ctrl_thread_entity_store; CTRL_EntityStore *ctrl_thread_entity_store;
E_Cache *ctrl_thread_eval_cache; E_Cache *ctrl_thread_eval_cache;
Arena *dmn_event_arena; Arena *dmn_event_arena;
@@ -860,13 +866,32 @@ internal CTRL_Event ctrl_event_from_serialized_string(Arena *arena, String8 stri
//- rjf: entity list data structures //- rjf: entity list data structures
internal void ctrl_entity_list_push(Arena *arena, CTRL_EntityList *list, CTRL_Entity *entity); internal void ctrl_entity_list_push(Arena *arena, CTRL_EntityList *list, CTRL_Entity *entity);
internal CTRL_EntityList ctrl_entity_list_from_handle_list(Arena *arena, CTRL_EntityStore *store, CTRL_HandleList *list); internal CTRL_EntityList ctrl_entity_list_from_handle_list(Arena *arena, CTRL_EntityCtx *ctx, CTRL_HandleList *list);
#define ctrl_entity_list_first(list) ((list)->first ? (list)->first->v : &ctrl_entity_nil) #define ctrl_entity_list_first(list) ((list)->first ? (list)->first->v : &ctrl_entity_nil)
//- rjf: entity array data structure //- rjf: entity array data structure
internal CTRL_EntityArray ctrl_entity_array_from_list(Arena *arena, CTRL_EntityList *list); internal CTRL_EntityArray ctrl_entity_array_from_list(Arena *arena, CTRL_EntityList *list);
#define ctrl_entity_array_first(array) ((array)->count != 0 ? (array)->v[0] : &ctrl_entity_nil) #define ctrl_entity_array_first(array) ((array)->count != 0 ? (array)->v[0] : &ctrl_entity_nil)
//- rjf: entity context (entity group read-only) functions
internal CTRL_Entity *ctrl_entity_from_handle(CTRL_EntityCtx *ctx, CTRL_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_process_from_entity(CTRL_Entity *entity);
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_Entity *ctrl_module_from_thread_candidates(CTRL_EntityCtx *ctx, CTRL_Entity *thread, CTRL_EntityList *candidates);
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);
internal B32 ctrl_entity_tree_is_frozen(CTRL_Entity *root);
//- 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: cache creation/destruction //- rjf: cache creation/destruction
internal CTRL_EntityStore *ctrl_entity_store_alloc(void); internal CTRL_EntityStore *ctrl_entity_store_alloc(void);
internal void ctrl_entity_store_release(CTRL_EntityStore *store); internal void ctrl_entity_store_release(CTRL_EntityStore *store);
@@ -884,26 +909,9 @@ internal void ctrl_entity_release(CTRL_EntityStore *store, CTRL_Entity *entity);
internal void ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *entity, String8 string); internal void ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *entity, String8 string);
//- rjf: entity store lookups //- rjf: entity store lookups
internal CTRL_Entity *ctrl_entity_from_handle(CTRL_EntityStore *store, CTRL_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_process_from_entity(CTRL_Entity *entity);
internal CTRL_Entity *ctrl_thread_from_id(CTRL_EntityStore *store, U64 id);
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_EntityArray ctrl_entity_array_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind); internal CTRL_EntityArray ctrl_entity_array_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind);
internal U64 ctrl_vaddr_from_voff(CTRL_Entity *module, U64 voff); internal CTRL_EntityList ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_key);
internal U64 ctrl_voff_from_vaddr(CTRL_Entity *module, U64 vaddr); internal CTRL_Entity *ctrl_thread_from_id(CTRL_EntityStore *store, U64 id);
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);
internal B32 ctrl_entity_tree_is_frozen(CTRL_Entity *root);
//- 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 //- rjf: applying events to entity caches
internal void ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list); internal void ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list);
@@ -940,10 +948,10 @@ internal B32 ctrl_process_write(CTRL_Handle process, Rng1U64 range, void *src);
//~ rjf: Thread Register Functions //~ rjf: Thread Register Functions
//- rjf: thread register cache reading //- rjf: thread register cache reading
internal void *ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle handle); internal void *ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle handle);
internal U64 ctrl_tls_root_vaddr_from_thread(CTRL_EntityStore *store, CTRL_Handle handle); internal U64 ctrl_tls_root_vaddr_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle);
internal U64 ctrl_rip_from_thread(CTRL_EntityStore *store, CTRL_Handle handle); internal U64 ctrl_rip_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle);
internal U64 ctrl_rsp_from_thread(CTRL_EntityStore *store, CTRL_Handle handle); internal U64 ctrl_rsp_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle);
//- rjf: thread register writing //- rjf: thread register writing
internal B32 ctrl_thread_write_reg_block(CTRL_Handle thread, void *block); internal B32 ctrl_thread_write_reg_block(CTRL_Handle thread, void *block);
@@ -972,14 +980,19 @@ internal CTRL_UnwindStepResult ctrl_unwind_step__pe_x64(CTRL_Handle process_hand
internal CTRL_UnwindStepResult ctrl_unwind_step(CTRL_Handle process, CTRL_Handle module, U64 module_base_vaddr, Arch arch, void *reg_block, U64 endt_us); internal CTRL_UnwindStepResult ctrl_unwind_step(CTRL_Handle process, CTRL_Handle module, U64 module_base_vaddr, Arch arch, void *reg_block, U64 endt_us);
//- rjf: abstracted full unwind //- rjf: abstracted full unwind
internal CTRL_Unwind ctrl_unwind_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle thread, U64 endt_us); internal CTRL_Unwind ctrl_unwind_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle thread, U64 endt_us);
//////////////////////////////// ////////////////////////////////
//~ rjf: Call Stack Building Functions //~ rjf: Call Stack Building Functions
internal CTRL_CallStack ctrl_call_stack_from_unwind(Arena *arena, DI_Scope *di_scope, CTRL_Entity *process, CTRL_Unwind *base_unwind); internal CTRL_CallStack ctrl_call_stack_from_unwind(Arena *arena, CTRL_Entity *process, CTRL_Unwind *base_unwind);
internal CTRL_CallStackFrame *ctrl_call_stack_frame_from_unwind_and_inline_depth(CTRL_CallStack *call_stack, U64 unwind_count, U64 inline_depth); internal CTRL_CallStackFrame *ctrl_call_stack_frame_from_unwind_and_inline_depth(CTRL_CallStack *call_stack, U64 unwind_count, U64 inline_depth);
////////////////////////////////
//~ rjf: Call Stack Cache Functions
internal CTRL_CallStack ctrl_call_stack_from_thread(HS_Scope *hs_scope, CTRL_Entity *thread, U64 endt_us);
//////////////////////////////// ////////////////////////////////
//~ rjf: Halting All Attached Processes //~ rjf: Halting All Attached Processes
+18 -18
View File
@@ -300,7 +300,7 @@ d_trap_net_from_thread__step_over_inst(Arena *arena, CTRL_Entity *thread)
// rjf: thread => unpacked info // rjf: thread => unpacked info
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
Arch arch = thread->arch; Arch arch = thread->arch;
U64 ip_vaddr = ctrl_rip_from_thread(d_state->ctrl_entity_store, thread->handle); U64 ip_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle);
// rjf: ip => machine code // rjf: ip => machine code
String8 machine_code = {0}; String8 machine_code = {0};
@@ -337,7 +337,7 @@ d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread)
// rjf: thread => info // rjf: thread => info
Arch arch = thread->arch; Arch arch = thread->arch;
U64 ip_vaddr = ctrl_rip_from_thread(d_state->ctrl_entity_store, thread->handle); U64 ip_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle);
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ip_vaddr); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ip_vaddr);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
@@ -498,7 +498,7 @@ d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread)
// rjf: thread => info // rjf: thread => info
Arch arch = thread->arch; Arch arch = thread->arch;
U64 ip_vaddr = ctrl_rip_from_thread(d_state->ctrl_entity_store, thread->handle); U64 ip_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle);
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ip_vaddr); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ip_vaddr);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
@@ -1240,7 +1240,7 @@ d_query_cached_unwind_from_thread(CTRL_Entity *thread)
} }
if(!d_state->ctrl_is_running && (node->reggen != reg_gen || node->memgen != mem_gen)) if(!d_state->ctrl_is_running && (node->reggen != reg_gen || node->memgen != mem_gen))
{ {
CTRL_Unwind new_unwind = ctrl_unwind_from_thread(scratch.arena, d_state->ctrl_entity_store, thread->handle, os_now_microseconds()+100); CTRL_Unwind new_unwind = ctrl_unwind_from_thread(scratch.arena, &d_state->ctrl_entity_store->ctx, thread->handle, os_now_microseconds()+100);
if(!(new_unwind.flags & (CTRL_UnwindFlag_Error|CTRL_UnwindFlag_Stale)) && new_unwind.frames.count != 0) if(!(new_unwind.flags & (CTRL_UnwindFlag_Error|CTRL_UnwindFlag_Stale)) && new_unwind.frames.count != 0)
{ {
node->unwind = ctrl_unwind_deep_copy(node->arena, thread->arch, &new_unwind); node->unwind = ctrl_unwind_deep_copy(node->arena, thread->arch, &new_unwind);
@@ -1267,7 +1267,7 @@ d_query_cached_rip_from_thread_unwind(CTRL_Entity *thread, U64 unwind_count)
U64 result = 0; U64 result = 0;
if(unwind_count == 0) if(unwind_count == 0)
{ {
result = ctrl_rip_from_thread(d_state->ctrl_entity_store, thread->handle); result = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle);
} }
else else
{ {
@@ -1579,7 +1579,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
// rjf: push stop event to caller, if this is not a soft-halt // rjf: push stop event to caller, if this is not a soft-halt
if(should_snap) if(should_snap)
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, event->entity); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, event->entity);
D_EventCause cause = D_EventCause_Null; D_EventCause cause = D_EventCause_Null;
switch(event->cause) switch(event->cause)
{ {
@@ -1743,7 +1743,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
for(D_UnwindCacheNode *n = slot->first, *next = 0; n != 0; n = next) for(D_UnwindCacheNode *n = slot->first, *next = 0; n != 0; n = next)
{ {
next = n->next; next = n->next;
if(ctrl_entity_from_handle(d_state->ctrl_entity_store, n->thread) == &ctrl_entity_nil) if(ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, n->thread) == &ctrl_entity_nil)
{ {
DLLRemove(slot->first, slot->last, n); DLLRemove(slot->first, slot->last, n);
arena_release(n->arena); arena_release(n->arena);
@@ -1869,7 +1869,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
}break; }break;
case D_CmdKind_Kill: case D_CmdKind_Kill:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(d_state->ctrl_entity_store, params->process); CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->process);
if(process == &ctrl_entity_nil) if(process == &ctrl_entity_nil)
{ {
log_user_error(str8_lit("Cannot kill; no process was specified.")); log_user_error(str8_lit("Cannot kill; no process was specified."));
@@ -1892,7 +1892,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
}break; }break;
case D_CmdKind_Detach: case D_CmdKind_Detach:
{ {
CTRL_Entity *process = ctrl_entity_from_handle(d_state->ctrl_entity_store, params->process); CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->process);
if(process == &ctrl_entity_nil) if(process == &ctrl_entity_nil)
{ {
log_user_error(str8_lit("Cannot detach; no process specified.")); log_user_error(str8_lit("Cannot detach; no process specified."));
@@ -1938,7 +1938,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
case D_CmdKind_StepOverLine: case D_CmdKind_StepOverLine:
case D_CmdKind_StepOut: case D_CmdKind_StepOut:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, params->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->thread);
if(thread == &ctrl_entity_nil) if(thread == &ctrl_entity_nil)
{ {
log_user_error(str8_lit("Must have a selected thread to step.")); log_user_error(str8_lit("Must have a selected thread to step."));
@@ -1968,7 +1968,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
case D_CmdKind_StepOut: case D_CmdKind_StepOut:
{ {
// rjf: thread => full unwind // rjf: thread => full unwind
CTRL_Unwind unwind = ctrl_unwind_from_thread(scratch.arena, d_state->ctrl_entity_store, thread->handle, os_now_microseconds()+10000); CTRL_Unwind unwind = ctrl_unwind_from_thread(scratch.arena, &d_state->ctrl_entity_store->ctx, thread->handle, os_now_microseconds()+10000);
// rjf: use first unwind frame to generate trap // rjf: use first unwind frame to generate trap
if(unwind.flags == 0 && unwind.frames.count > 1) if(unwind.flags == 0 && unwind.frames.count > 1)
@@ -2012,15 +2012,15 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
{ {
need_run = 1; need_run = 1;
run_kind = d_state->ctrl_last_run_kind; run_kind = d_state->ctrl_last_run_kind;
run_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, d_state->ctrl_last_run_thread_handle); 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_flags = d_state->ctrl_last_run_flags;
run_traps = d_state->ctrl_last_run_traps; run_traps = d_state->ctrl_last_run_traps;
}break; }break;
case D_CmdKind_SetThreadIP: case D_CmdKind_SetThreadIP:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, params->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->thread);
U64 vaddr = params->vaddr; U64 vaddr = params->vaddr;
void *block = ctrl_reg_block_from_thread(scratch.arena, d_state->ctrl_entity_store, thread->handle); void *block = ctrl_reg_block_from_thread(scratch.arena, &d_state->ctrl_entity_store->ctx, thread->handle);
regs_arch_block_write_rip(thread->arch, block, vaddr); regs_arch_block_write_rip(thread->arch, block, vaddr);
B32 result = ctrl_thread_write_reg_block(thread->handle, block); B32 result = ctrl_thread_write_reg_block(thread->handle, block);
@@ -2136,7 +2136,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
case D_CmdKind_ThawEntity: case D_CmdKind_ThawEntity:
{ {
B32 should_freeze = (cmd->kind == D_CmdKind_FreezeEntity); B32 should_freeze = (cmd->kind == D_CmdKind_FreezeEntity);
CTRL_Entity *root = ctrl_entity_from_handle(d_state->ctrl_entity_store, params->entity); CTRL_Entity *root = ctrl_entity_from_handle(&d_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) 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) if(e->kind == CTRL_EntityKind_Thread)
@@ -2151,7 +2151,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
{ {
need_run = 1; need_run = 1;
run_kind = d_state->ctrl_last_run_kind; run_kind = d_state->ctrl_last_run_kind;
run_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, d_state->ctrl_last_run_thread_handle); 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_flags = d_state->ctrl_last_run_flags;
run_traps = d_state->ctrl_last_run_traps; run_traps = d_state->ctrl_last_run_traps;
} }
@@ -2160,12 +2160,12 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
//- rjf: entity decoration //- rjf: entity decoration
case D_CmdKind_SetEntityColor: case D_CmdKind_SetEntityColor:
{ {
CTRL_Entity *entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, params->entity); CTRL_Entity *entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, params->entity);
entity->rgba = params->rgba; entity->rgba = params->rgba;
}break; }break;
case D_CmdKind_SetEntityName: case D_CmdKind_SetEntityName:
{ {
CTRL_Entity *entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, params->entity); 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_equip_string(d_state->ctrl_entity_store, entity, params->string);
}break; }break;
+33 -39
View File
@@ -1693,7 +1693,7 @@ rd_ctrl_entity_from_eval_space(E_Space space)
CTRL_Handle handle; CTRL_Handle handle;
handle.machine_id = space.u64s[0]; handle.machine_id = space.u64s[0];
handle.dmn_handle.u64[0] = space.u64s[1]; handle.dmn_handle.u64[0] = space.u64s[1];
entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, handle); entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, handle);
} }
return entity; return entity;
} }
@@ -2021,7 +2021,7 @@ rd_eval_space_write(void *u, E_Space space, void *in, Rng1U64 range)
Rng1U64 legal_range = r1u64(0, regs_size); Rng1U64 legal_range = r1u64(0, regs_size);
Rng1U64 write_range = intersect_1u64(legal_range, range); Rng1U64 write_range = intersect_1u64(legal_range, range);
U64 write_size = dim_1u64(write_range); U64 write_size = dim_1u64(write_range);
void *new_regs = ctrl_reg_block_from_thread(scratch.arena, d_state->ctrl_entity_store, entity->handle); void *new_regs = ctrl_reg_block_from_thread(scratch.arena, &d_state->ctrl_entity_store->ctx, entity->handle);
MemoryCopy((U8 *)new_regs + write_range.min, in, write_size); MemoryCopy((U8 *)new_regs + write_range.min, in, write_size);
result = ctrl_thread_write_reg_block(entity->handle, new_regs); result = ctrl_thread_write_reg_block(entity->handle, new_regs);
scratch_end(scratch); scratch_end(scratch);
@@ -3352,7 +3352,7 @@ rd_view_ui(Rng2F32 rect)
String8 name = {0}; String8 name = {0};
{ {
U64 vaddr = eval.value.u64; U64 vaddr = eval.value.u64;
CTRL_Entity *process = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process); CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process);
CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
U64 voff = ctrl_voff_from_vaddr(module, vaddr); U64 voff = ctrl_voff_from_vaddr(module, vaddr);
@@ -5601,7 +5601,7 @@ rd_arch_from_eval(E_Eval eval)
CTRL_Entity *process = ctrl_process_from_entity(ctrl_entity); CTRL_Entity *process = ctrl_process_from_entity(ctrl_entity);
if(process == &ctrl_entity_nil) if(process == &ctrl_entity_nil)
{ {
process = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process); process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process);
} }
Arch arch = process->arch; Arch arch = process->arch;
if(arch == Arch_Null) if(arch == Arch_Null)
@@ -6337,16 +6337,15 @@ rd_window_frame(void)
//////////////////////// ////////////////////////
//- rjf: control entity tooltips //- rjf: control entity tooltips
// //
case RD_RegSlot_Machine: {ctrl_entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, regs->machine); }goto ctrl_entity_tooltip; case RD_RegSlot_Machine: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->machine); }goto ctrl_entity_tooltip;
case RD_RegSlot_Process: {ctrl_entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, regs->process); }goto ctrl_entity_tooltip; case RD_RegSlot_Process: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->process); }goto ctrl_entity_tooltip;
case RD_RegSlot_Module: {ctrl_entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, regs->module); }goto ctrl_entity_tooltip; case RD_RegSlot_Module: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->module); }goto ctrl_entity_tooltip;
case RD_RegSlot_Thread: {ctrl_entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, regs->thread); }goto ctrl_entity_tooltip; case RD_RegSlot_Thread: {ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->thread); }goto ctrl_entity_tooltip;
case RD_RegSlot_CtrlEntity:{ctrl_entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, regs->ctrl_entity); }goto ctrl_entity_tooltip; case RD_RegSlot_CtrlEntity:{ctrl_entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, regs->ctrl_entity); }goto ctrl_entity_tooltip;
ctrl_entity_tooltip:; ctrl_entity_tooltip:;
UI_Tooltip UI_Tooltip
{ {
// rjf: unpack // rjf: unpack
DI_Scope *di_scope = di_scope_open();
Arch arch = ctrl_entity->arch; Arch arch = ctrl_entity->arch;
String8 arch_str = string_from_arch(arch); String8 arch_str = string_from_arch(arch);
DR_FStrList fstrs = rd_title_fstrs_from_ctrl_entity(scratch.arena, ctrl_entity, 0); DR_FStrList fstrs = rd_title_fstrs_from_ctrl_entity(scratch.arena, ctrl_entity, 0);
@@ -6398,7 +6397,7 @@ rd_window_frame(void)
Vec4F32 symbol_color = ui_color_from_name(str8_lit("code_symbol")); Vec4F32 symbol_color = ui_color_from_name(str8_lit("code_symbol"));
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(ctrl_entity, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(ctrl_entity, CTRL_EntityKind_Process);
CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(ctrl_entity); CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(ctrl_entity);
CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, di_scope, process, &base_unwind); CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, process, &base_unwind);
if(call_stack.count != 0) if(call_stack.count != 0)
{ {
ui_spacer(ui_em(1.5f, 1.f)); ui_spacer(ui_em(1.5f, 1.f));
@@ -6417,7 +6416,6 @@ rd_window_frame(void)
} }
} }
di_scope_close(di_scope);
}break; }break;
//////////////////////// ////////////////////////
@@ -10193,7 +10191,7 @@ rd_code_color_slot_from_txt_token_kind_lookup_string(TXT_TokenKind kind, String8
RD_CodeColorSlot color = RD_CodeColorSlot_CodeDefault; RD_CodeColorSlot color = RD_CodeColorSlot_CodeDefault;
if(kind == TXT_TokenKind_Identifier || kind == TXT_TokenKind_Keyword) if(kind == TXT_TokenKind_Identifier || kind == TXT_TokenKind_Keyword)
{ {
CTRL_Entity *module = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->module); CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->module);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
B32 mapped = 0; B32 mapped = 0;
@@ -10312,7 +10310,7 @@ rd_string_from_exception_code(U32 code)
internal DR_FStrList internal DR_FStrList
rd_stop_explanation_fstrs_from_ctrl_event(Arena *arena, CTRL_Event *event) rd_stop_explanation_fstrs_from_ctrl_event(Arena *arena, CTRL_Event *event)
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, event->entity); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, event->entity);
DR_FStrList thread_fstrs = rd_title_fstrs_from_ctrl_entity(arena, thread, 0); DR_FStrList thread_fstrs = rd_title_fstrs_from_ctrl_entity(arena, thread, 0);
DR_FStrList fstrs = {0}; DR_FStrList fstrs = {0};
DR_FStrParams params = {ui_top_font(), ui_top_text_raster_flags(), ui_color_from_name(str8_lit("text")), ui_top_font_size()}; DR_FStrParams params = {ui_top_font(), ui_top_text_raster_flags(), ui_color_from_name(str8_lit("text")), ui_top_font_size()};
@@ -11610,15 +11608,15 @@ rd_frame(void)
//- rjf: unpack eval-dependent info //- rjf: unpack eval-dependent info
// //
ProfBegin("unpack eval-dependent info"); ProfBegin("unpack eval-dependent info");
CTRL_Entity *process = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process); CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process);
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
Arch arch = thread->arch; Arch arch = thread->arch;
U64 unwind_count = rd_regs()->unwind_count; U64 unwind_count = rd_regs()->unwind_count;
U64 rip_vaddr = d_query_cached_rip_from_thread_unwind(thread, unwind_count); U64 rip_vaddr = d_query_cached_rip_from_thread_unwind(thread, unwind_count);
CTRL_Unwind unwind = d_query_cached_unwind_from_thread(thread); CTRL_Unwind unwind = d_query_cached_unwind_from_thread(thread);
CTRL_Entity *module = ctrl_module_from_process_vaddr(process, rip_vaddr); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, rip_vaddr);
U64 rip_voff = ctrl_voff_from_vaddr(module, rip_vaddr); U64 rip_voff = ctrl_voff_from_vaddr(module, rip_vaddr);
U64 tls_root_vaddr = ctrl_tls_root_vaddr_from_thread(d_state->ctrl_entity_store, thread->handle); U64 tls_root_vaddr = ctrl_tls_root_vaddr_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle);
CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Module); CTRL_EntityArray all_modules = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Module);
U64 eval_modules_count = Max(1, all_modules.count); U64 eval_modules_count = Max(1, all_modules.count);
E_Module *eval_modules = push_array(scratch.arena, E_Module, eval_modules_count); E_Module *eval_modules = push_array(scratch.arena, E_Module, eval_modules_count);
@@ -14006,12 +14004,12 @@ rd_frame(void)
//- rjf: source <-> disasm //- rjf: source <-> disasm
case RD_CmdKind_GoToDisassembly: case RD_CmdKind_GoToDisassembly:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
U64 vaddr = 0; U64 vaddr = 0;
for(D_LineNode *n = rd_regs()->lines.first; n != 0; n = n->next) for(D_LineNode *n = rd_regs()->lines.first; n != 0; n = n->next)
{ {
CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key); CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key);
CTRL_Entity *module = ctrl_module_from_thread_candidates(d_state->ctrl_entity_store, thread, &modules); CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules);
if(module != &ctrl_entity_nil) if(module != &ctrl_entity_nil)
{ {
vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min);
@@ -14294,7 +14292,7 @@ rd_frame(void)
RD_RegsScope(.window = ws->cfg_id) RD_RegsScope(.window = ws->cfg_id)
{ {
DI_Scope *scope = di_scope_open(); DI_Scope *scope = di_scope_open();
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
U64 unwind_index = rd_regs()->unwind_count; U64 unwind_index = rd_regs()->unwind_count;
U64 inline_depth = rd_regs()->inline_depth; U64 inline_depth = rd_regs()->inline_depth;
if(thread->kind == CTRL_EntityKind_Thread) if(thread->kind == CTRL_EntityKind_Thread)
@@ -14366,7 +14364,7 @@ rd_frame(void)
for(RD_WindowState *ws = rd_state->first_window_state; ws != &rd_nil_window_state; ws = ws->order_next) for(RD_WindowState *ws = rd_state->first_window_state; ws != &rd_nil_window_state; ws = ws->order_next)
RD_RegsScope(.window = ws->cfg_id) RD_RegsScope(.window = ws->cfg_id)
{ {
CTRL_Entity *selected_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_base_regs()->thread); CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread);
rd_cmd(RD_CmdKind_FindThread, rd_cmd(RD_CmdKind_FindThread,
.thread = selected_thread->handle, .thread = selected_thread->handle,
.unwind_count = rd_base_regs()->unwind_count, .unwind_count = rd_base_regs()->unwind_count,
@@ -14550,8 +14548,8 @@ rd_frame(void)
{ {
file_path = rd_mapped_from_file_path(scratch.arena, rd_regs()->file_path); file_path = rd_mapped_from_file_path(scratch.arena, rd_regs()->file_path);
point = rd_regs()->cursor; point = rd_regs()->cursor;
thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
process = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process); process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process);
vaddr = rd_regs()->vaddr; vaddr = rd_regs()->vaddr;
if(file_path.size == 0) if(file_path.size == 0)
{ {
@@ -14567,7 +14565,7 @@ rd_frame(void)
for(D_LineNode *n = lines.first; n != 0; n = n->next) for(D_LineNode *n = lines.first; n != 0; n = n->next)
{ {
CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key); CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key);
CTRL_Entity *module = ctrl_module_from_thread_candidates(d_state->ctrl_entity_store, thread, &modules); CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules);
vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min);
break; break;
} }
@@ -15501,7 +15499,7 @@ rd_frame(void)
}break; }break;
case RD_CmdKind_SetNextStatement: case RD_CmdKind_SetNextStatement:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
String8 file_path = rd_regs()->file_path; String8 file_path = rd_regs()->file_path;
U64 new_rip_vaddr = rd_regs()->vaddr_range.min; U64 new_rip_vaddr = rd_regs()->vaddr_range.min;
if(file_path.size != 0) if(file_path.size != 0)
@@ -15510,7 +15508,7 @@ rd_frame(void)
for(D_LineNode *n = lines->first; n != 0; n = n->next) for(D_LineNode *n = lines->first; n != 0; n = n->next)
{ {
CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key); CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key);
CTRL_Entity *module = ctrl_module_from_thread_candidates(d_state->ctrl_entity_store, thread, &modules); CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules);
if(module != &ctrl_entity_nil) if(module != &ctrl_entity_nil)
{ {
new_rip_vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); new_rip_vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min);
@@ -15622,9 +15620,9 @@ rd_frame(void)
}break; }break;
case RD_CmdKind_SelectThread: case RD_CmdKind_SelectThread:
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ctrl_rip_from_thread(d_state->ctrl_entity_store, thread->handle)); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle));
CTRL_Entity *machine = ctrl_entity_ancestor_from_kind(process, CTRL_EntityKind_Machine); CTRL_Entity *machine = ctrl_entity_ancestor_from_kind(process, CTRL_EntityKind_Machine);
rd_state->base_regs.v.unwind_count = 0; rd_state->base_regs.v.unwind_count = 0;
rd_state->base_regs.v.inline_depth = 0; rd_state->base_regs.v.inline_depth = 0;
@@ -15636,11 +15634,10 @@ rd_frame(void)
}break; }break;
case RD_CmdKind_SelectUnwind: case RD_CmdKind_SelectUnwind:
{ {
DI_Scope *di_scope = di_scope_open(); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread);
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_base_regs()->thread);
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(thread); CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(thread);
CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, di_scope, process, &base_unwind); CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, process, &base_unwind);
CTRL_CallStackFrame *frame = ctrl_call_stack_frame_from_unwind_and_inline_depth(&call_stack, rd_regs()->unwind_count, rd_regs()->inline_depth); CTRL_CallStackFrame *frame = ctrl_call_stack_frame_from_unwind_and_inline_depth(&call_stack, rd_regs()->unwind_count, rd_regs()->inline_depth);
if(frame == 0) if(frame == 0)
{ {
@@ -15652,16 +15649,14 @@ rd_frame(void)
rd_state->base_regs.v.inline_depth = rd_regs()->inline_depth; rd_state->base_regs.v.inline_depth = rd_regs()->inline_depth;
} }
rd_cmd(RD_CmdKind_FindThread, .thread = thread->handle, .unwind_count = rd_state->base_regs.v.unwind_count, .inline_depth = rd_state->base_regs.v.inline_depth); rd_cmd(RD_CmdKind_FindThread, .thread = thread->handle, .unwind_count = rd_state->base_regs.v.unwind_count, .inline_depth = rd_state->base_regs.v.inline_depth);
di_scope_close(di_scope);
}break; }break;
case RD_CmdKind_UpOneFrame: case RD_CmdKind_UpOneFrame:
case RD_CmdKind_DownOneFrame: case RD_CmdKind_DownOneFrame:
{ {
DI_Scope *di_scope = di_scope_open(); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread);
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_base_regs()->thread);
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(thread); CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(thread);
CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, di_scope, process, &base_unwind); CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, process, &base_unwind);
CTRL_CallStackFrame *current_frame = ctrl_call_stack_frame_from_unwind_and_inline_depth(&call_stack, rd_regs()->unwind_count, rd_regs()->inline_depth); CTRL_CallStackFrame *current_frame = ctrl_call_stack_frame_from_unwind_and_inline_depth(&call_stack, rd_regs()->unwind_count, rd_regs()->inline_depth);
CTRL_CallStackFrame *next_frame = current_frame; CTRL_CallStackFrame *next_frame = current_frame;
if(current_frame != 0) switch(kind) if(current_frame != 0) switch(kind)
@@ -15685,7 +15680,6 @@ rd_frame(void)
.unwind_count = next_frame->unwind_count, .unwind_count = next_frame->unwind_count,
.inline_depth = next_frame->inline_depth); .inline_depth = next_frame->inline_depth);
} }
di_scope_close(di_scope);
}break; }break;
//- rjf: meta controls //- rjf: meta controls
@@ -16391,13 +16385,13 @@ rd_frame(void)
case D_EventKind_Stop: case D_EventKind_Stop:
{ {
B32 need_refocus = (evt->cause != D_EventCause_SoftHalt); B32 need_refocus = (evt->cause != D_EventCause_SoftHalt);
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, evt->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, evt->thread);
U64 vaddr = evt->vaddr; U64 vaddr = evt->vaddr;
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
U64 voff = ctrl_voff_from_vaddr(module, vaddr); U64 voff = ctrl_voff_from_vaddr(module, vaddr);
U64 test_cached_vaddr = ctrl_rip_from_thread(d_state->ctrl_entity_store, thread->handle); U64 test_cached_vaddr = ctrl_rip_from_thread(&d_state->ctrl_entity_store->ctx, thread->handle);
// rjf: valid stop thread? -> select & snap // rjf: valid stop thread? -> select & snap
if(need_refocus && thread != &ctrl_entity_nil && evt->cause != D_EventCause_Halt) if(need_refocus && thread != &ctrl_entity_nil && evt->cause != D_EventCause_Halt)
@@ -16406,7 +16400,7 @@ rd_frame(void)
} }
// rjf: no stop-causing thread, but have selected thread? -> snap to selected // rjf: no stop-causing thread, but have selected thread? -> snap to selected
CTRL_Entity *selected_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_base_regs()->thread); CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_base_regs()->thread);
if(need_refocus && (evt->cause == D_EventCause_Halt || thread == &ctrl_entity_nil) && selected_thread != &ctrl_entity_nil) if(need_refocus && (evt->cause == D_EventCause_Halt || thread == &ctrl_entity_nil) && selected_thread != &ctrl_entity_nil)
{ {
rd_cmd(RD_CmdKind_SelectThread, .thread = selected_thread->handle); rd_cmd(RD_CmdKind_SelectThread, .thread = selected_thread->handle);
+5 -5
View File
@@ -205,7 +205,7 @@ E_TYPE_EXPAND_RANGE_FUNCTION_DEF(locals)
E_TYPE_EXPAND_INFO_FUNCTION_DEF(registers) E_TYPE_EXPAND_INFO_FUNCTION_DEF(registers)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
Arch arch = thread->arch; Arch arch = thread->arch;
U64 reg_count = regs_reg_code_count_from_arch(arch); U64 reg_count = regs_reg_code_count_from_arch(arch);
U64 alias_count = regs_alias_code_count_from_arch(arch); U64 alias_count = regs_alias_code_count_from_arch(arch);
@@ -658,7 +658,7 @@ E_TYPE_ACCESS_FUNCTION_DEF(control)
str8_match(str8_prefix(rhs->string, 1), str8_lit("$"), 0)) str8_match(str8_prefix(rhs->string, 1), str8_lit("$"), 0))
{ {
CTRL_Handle handle = ctrl_handle_from_string(rhs->string); CTRL_Handle handle = ctrl_handle_from_string(rhs->string);
CTRL_Entity *entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, handle); CTRL_Entity *entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, handle);
E_Space space = rd_eval_space_from_ctrl_entity(entity, RD_EvalSpaceKind_MetaCtrlEntity); E_Space space = rd_eval_space_from_ctrl_entity(entity, RD_EvalSpaceKind_MetaCtrlEntity);
result.root = e_irtree_set_space(arena, space, e_irtree_const_u(arena, 0)); result.root = e_irtree_set_space(arena, space, e_irtree_const_u(arena, 0));
result.type_key = e_string2typekey_map_lookup(rd_state->meta_name2type_map, ctrl_entity_kind_code_name_table[entity->kind]); result.type_key = e_string2typekey_map_lookup(rd_state->meta_name2type_map, ctrl_entity_kind_code_name_table[entity->kind]);
@@ -959,7 +959,7 @@ E_TYPE_IREXT_FUNCTION_DEF(call_stack)
CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(entity); CTRL_Unwind base_unwind = d_query_cached_unwind_from_thread(entity);
accel->arch = entity->arch; accel->arch = entity->arch;
accel->process = process->handle; accel->process = process->handle;
accel->call_stack = ctrl_call_stack_from_unwind(arena, rd_state->frame_di_scope, process, &base_unwind); accel->call_stack = ctrl_call_stack_from_unwind(arena, process, &base_unwind);
} }
scratch_end(scratch); scratch_end(scratch);
} }
@@ -977,7 +977,7 @@ E_TYPE_ACCESS_FUNCTION_DEF(call_stack)
CTRL_CallStack *call_stack = &accel->call_stack; CTRL_CallStack *call_stack = &accel->call_stack;
if(0 <= rhs_value.u64 && rhs_value.u64 < call_stack->count) if(0 <= rhs_value.u64 && rhs_value.u64 < call_stack->count)
{ {
CTRL_Entity *process = ctrl_entity_from_handle(d_state->ctrl_entity_store, accel->process); CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, accel->process);
CTRL_CallStackFrame *f = &call_stack->frames[rhs_value.u64]; CTRL_CallStackFrame *f = &call_stack->frames[rhs_value.u64];
result.root = e_irtree_set_space(arena, rd_eval_space_from_ctrl_entity(process, RD_EvalSpaceKind_CtrlEntity), e_irtree_const_u(arena, regs_rip_from_arch_block(accel->arch, f->regs))); result.root = e_irtree_set_space(arena, rd_eval_space_from_ctrl_entity(process, RD_EvalSpaceKind_CtrlEntity), e_irtree_const_u(arena, regs_rip_from_arch_block(accel->arch, f->regs)));
result.type_key = e_type_key_cons(.arch = process->arch, .kind = E_TypeKind_Ptr, .direct_key = e_type_key_basic(E_TypeKind_Function), .count = 1, .depth = f->inline_depth); result.type_key = e_type_key_cons(.arch = process->arch, .kind = E_TypeKind_Ptr, .direct_key = e_type_key_basic(E_TypeKind_Function), .count = 1, .depth = f->inline_depth);
@@ -1420,7 +1420,7 @@ E_TYPE_ACCESS_FUNCTION_DEF(ctrl_entities)
{ {
String8 rhs_name = expr->first->next->string; String8 rhs_name = expr->first->next->string;
CTRL_Handle handle = ctrl_handle_from_string(rhs_name); CTRL_Handle handle = ctrl_handle_from_string(rhs_name);
entity = ctrl_entity_from_handle(d_state->ctrl_entity_store, handle); entity = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, handle);
}break; }break;
case E_ExprKind_ArrayIndex: case E_ExprKind_ArrayIndex:
{ {
+11 -13
View File
@@ -44,7 +44,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla
F32 scroll_bar_dim = floor_f32(main_font_size*1.5f); F32 scroll_bar_dim = floor_f32(main_font_size*1.5f);
Vec2F32 code_area_dim = v2f32(panel_box_dim.x - scroll_bar_dim, panel_box_dim.y - scroll_bar_dim); Vec2F32 code_area_dim = v2f32(panel_box_dim.x - scroll_bar_dim, panel_box_dim.y - scroll_bar_dim);
S64 num_possible_visible_lines = (S64)(code_area_dim.y/code_line_height)+1; S64 num_possible_visible_lines = (S64)(code_area_dim.y/code_line_height)+1;
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
B32 do_line_numbers = rd_setting_b32_from_name(str8_lit("show_line_numbers")); B32 do_line_numbers = rd_setting_b32_from_name(str8_lit("show_line_numbers"));
@@ -260,7 +260,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla
// rjf: find live threads mapping to source code // rjf: find live threads mapping to source code
if(!dasm_lines) ProfScope("find live threads mapping to this file") if(!dasm_lines) ProfScope("find live threads mapping to this file")
{ {
CTRL_Entity *selected_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
CTRL_EntityArray threads = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Thread); CTRL_EntityArray threads = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Thread);
for EachIndex(idx, threads.count) for EachIndex(idx, threads.count)
{ {
@@ -323,7 +323,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla
if(!dasm_lines) ProfScope("find all src -> dasm info for source code") if(!dasm_lines) ProfScope("find all src -> dasm info for source code")
{ {
String8 file_path = rd_regs()->file_path; String8 file_path = rd_regs()->file_path;
CTRL_Entity *module = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->module); CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->module);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
D_LineListArray lines_array = d_lines_array_from_dbgi_key_file_path_line_range(scratch.arena, dbgi_key, file_path, visible_line_num_range); D_LineListArray lines_array = d_lines_array_from_dbgi_key_file_path_line_range(scratch.arena, dbgi_key, file_path, visible_line_num_range);
if(lines_array.count != 0) if(lines_array.count != 0)
@@ -336,7 +336,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla
// rjf: find live threads mapping to disasm // rjf: find live threads mapping to disasm
if(dasm_lines) ProfScope("find live threads mapping to this disassembly") if(dasm_lines) ProfScope("find live threads mapping to this disassembly")
{ {
CTRL_Entity *selected_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
CTRL_EntityArray threads = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Thread); CTRL_EntityArray threads = ctrl_entity_array_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Thread);
for EachIndex(idx, threads.count) for EachIndex(idx, threads.count)
{ {
@@ -1008,11 +1008,10 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row)
CTRL_Entity *entity = rd_ctrl_entity_from_eval_space(block_eval.space); CTRL_Entity *entity = rd_ctrl_entity_from_eval_space(block_eval.space);
if(entity->kind == CTRL_EntityKind_Thread) if(entity->kind == CTRL_EntityKind_Thread)
{ {
DI_Scope *di_scope = di_scope_open();
info.callstack_thread = entity; info.callstack_thread = entity;
U64 frame_num = ev_block_num_from_id(block, key.child_id); U64 frame_num = ev_block_num_from_id(block, key.child_id);
CTRL_Unwind unwind = d_query_cached_unwind_from_thread(entity); CTRL_Unwind unwind = d_query_cached_unwind_from_thread(entity);
CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, di_scope, ctrl_process_from_entity(entity), &unwind); CTRL_CallStack call_stack = ctrl_call_stack_from_unwind(scratch.arena, ctrl_process_from_entity(entity), &unwind);
if(1 <= frame_num && frame_num <= call_stack.count) if(1 <= frame_num && frame_num <= call_stack.count)
{ {
CTRL_CallStackFrame *f = &call_stack.frames[frame_num-1]; CTRL_CallStackFrame *f = &call_stack.frames[frame_num-1];
@@ -1020,7 +1019,6 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row)
info.callstack_inline_depth = f->inline_depth; info.callstack_inline_depth = f->inline_depth;
info.callstack_vaddr = regs_rip_from_arch_block(entity->arch, f->regs); info.callstack_vaddr = regs_rip_from_arch_block(entity->arch, f->regs);
} }
di_scope_close(di_scope);
} }
} }
@@ -2143,7 +2141,7 @@ RD_VIEW_UI_FUNCTION_DEF(text)
// //
if(rd_regs()->file_path.size != 0) if(rd_regs()->file_path.size != 0)
{ {
CTRL_Entity *module = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->module); CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->module);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
rd_regs()->lines = d_lines_from_dbgi_key_file_path_line_num(rd_frame_arena(), dbgi_key, rd_regs()->file_path, rd_regs()->cursor.line); rd_regs()->lines = d_lines_from_dbgi_key_file_path_line_num(rd_frame_arena(), dbgi_key, rd_regs()->file_path, rd_regs()->cursor.line);
} }
@@ -2284,13 +2282,13 @@ RD_VIEW_UI_FUNCTION_DEF(disasm)
if(dv->temp_look_vaddr != 0 && dv->temp_look_run_gen == ctrl_run_gen()) if(dv->temp_look_vaddr != 0 && dv->temp_look_run_gen == ctrl_run_gen())
{ {
auto_selected = 1; auto_selected = 1;
auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(d_state->ctrl_entity_store, dv->temp_look_process), RD_EvalSpaceKind_CtrlEntity); auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, dv->temp_look_process), RD_EvalSpaceKind_CtrlEntity);
eval = e_eval_from_stringf("(0x%I64x & (~(0x4000 - 1)))", dv->temp_look_vaddr); eval = e_eval_from_stringf("(0x%I64x & (~(0x4000 - 1)))", dv->temp_look_vaddr);
} }
else else
{ {
auto_selected = 1; auto_selected = 1;
auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process), RD_EvalSpaceKind_CtrlEntity); auto_space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process), RD_EvalSpaceKind_CtrlEntity);
eval = e_eval_from_stringf("(rip.u64 & (~(0x4000 - 1)))"); eval = e_eval_from_stringf("(rip.u64 & (~(0x4000 - 1)))");
} }
} }
@@ -2522,7 +2520,7 @@ RD_VIEW_UI_FUNCTION_DEF(memory)
Rng1U64 view_range = r1u64(base_offset, base_offset+size); Rng1U64 view_range = r1u64(base_offset, base_offset+size);
if(eval.space.kind == 0) if(eval.space.kind == 0)
{ {
eval.space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process), RD_EvalSpaceKind_CtrlEntity); eval.space = rd_eval_space_from_ctrl_entity(ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process), RD_EvalSpaceKind_CtrlEntity);
view_range = rd_whole_range_from_eval_space(eval.space); view_range = rd_whole_range_from_eval_space(eval.space);
} }
if(eval.space.kind == RD_EvalSpaceKind_CtrlEntity && dim_1u64(view_range) == KB(16)) if(eval.space.kind == RD_EvalSpaceKind_CtrlEntity && dim_1u64(view_range) == KB(16))
@@ -2839,7 +2837,7 @@ RD_VIEW_UI_FUNCTION_DEF(memory)
}; };
AnnotationList *visible_memory_annotations = push_array(scratch.arena, AnnotationList, visible_memory_size); AnnotationList *visible_memory_annotations = push_array(scratch.arena, AnnotationList, visible_memory_size);
{ {
CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process); CTRL_Entity *process = ctrl_entity_ancestor_from_kind(thread, CTRL_EntityKind_Process);
CTRL_Unwind unwind = d_query_cached_unwind_from_thread(thread); CTRL_Unwind unwind = d_query_cached_unwind_from_thread(thread);
@@ -2863,7 +2861,7 @@ RD_VIEW_UI_FUNCTION_DEF(memory)
String8 symbol_name = {0}; String8 symbol_name = {0};
{ {
U64 vaddr = eval.value.u64; U64 vaddr = eval.value.u64;
CTRL_Entity *process = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->process); CTRL_Entity *process = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->process);
CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr); CTRL_Entity *module = ctrl_module_from_process_vaddr(process, vaddr);
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); DI_Key dbgi_key = ctrl_dbgi_key_from_module(module);
U64 voff = ctrl_voff_from_vaddr(module, vaddr); U64 voff = ctrl_voff_from_vaddr(module, vaddr);
+5 -5
View File
@@ -1210,7 +1210,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
RD_CodeSliceSignal result = {0}; RD_CodeSliceSignal result = {0};
ProfBeginFunction(); ProfBeginFunction();
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
CTRL_Entity *selected_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); CTRL_Entity *selected_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread);
CTRL_Entity *selected_thread_process = ctrl_entity_ancestor_from_kind(selected_thread, CTRL_EntityKind_Process); CTRL_Entity *selected_thread_process = ctrl_entity_ancestor_from_kind(selected_thread, CTRL_EntityKind_Process);
U64 selected_thread_rip_unwind_vaddr = d_query_cached_rip_from_thread_unwind(selected_thread, rd_regs()->unwind_count); U64 selected_thread_rip_unwind_vaddr = d_query_cached_rip_from_thread_unwind(selected_thread, rd_regs()->unwind_count);
CTRL_Entity *selected_thread_module = ctrl_module_from_process_vaddr(selected_thread_process, selected_thread_rip_unwind_vaddr); CTRL_Entity *selected_thread_module = ctrl_module_from_process_vaddr(selected_thread_process, selected_thread_rip_unwind_vaddr);
@@ -1218,7 +1218,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
F32 selected_thread_module_alive_t = ui_anim(ui_key_from_stringf(ui_key_zero(), "###selected_thread_module_alive_t_%p", selected_thread_module), 1.f); F32 selected_thread_module_alive_t = ui_anim(ui_key_from_stringf(ui_key_zero(), "###selected_thread_module_alive_t_%p", selected_thread_module), 1.f);
F32 selected_thread_arch_alive_t = ui_anim(ui_key_from_stringf(ui_key_zero(), "###selected_thread_arch_alive_t_%i", selected_thread->arch), 1.f); F32 selected_thread_arch_alive_t = ui_anim(ui_key_from_stringf(ui_key_zero(), "###selected_thread_arch_alive_t_%i", selected_thread->arch), 1.f);
CTRL_Event stop_event = d_ctrl_last_stop_event(); CTRL_Event stop_event = d_ctrl_last_stop_event();
CTRL_Entity *stopper_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, stop_event.entity); CTRL_Entity *stopper_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, stop_event.entity);
B32 is_focused = ui_is_focus_active(); B32 is_focused = ui_is_focus_active();
B32 ctrlified = (os_get_modifiers() & OS_Modifier_Ctrl); B32 ctrlified = (os_get_modifiers() & OS_Modifier_Ctrl);
Vec4F32 code_line_bgs[] = Vec4F32 code_line_bgs[] =
@@ -1353,7 +1353,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
if(rd_state->drag_drop_regs_slot == RD_RegSlot_Thread) if(rd_state->drag_drop_regs_slot == RD_RegSlot_Thread)
{ {
drop_can_hit_lines = 1; drop_can_hit_lines = 1;
drop_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_state->drag_drop_regs->thread); drop_thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_state->drag_drop_regs->thread);
drop_color = rd_color_from_ctrl_entity(drop_thread); drop_color = rd_color_from_ctrl_entity(drop_thread);
if(drop_color.w == 0) if(drop_color.w == 0)
{ {
@@ -2326,7 +2326,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
for(D_LineNode *n = lines->first; n != 0; n = n->next) for(D_LineNode *n = lines->first; n != 0; n = n->next)
{ {
CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key); CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key);
CTRL_Entity *module = ctrl_module_from_thread_candidates(d_state->ctrl_entity_store, thread, &modules); CTRL_Entity *module = ctrl_module_from_thread_candidates(&d_state->ctrl_entity_store->ctx, thread, &modules);
if(module != &ctrl_entity_nil) if(module != &ctrl_entity_nil)
{ {
new_rip_vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); new_rip_vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min);
@@ -2493,7 +2493,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
Rng1U64 hover_voff_range = hover_regs->voff_range; Rng1U64 hover_voff_range = hover_regs->voff_range;
if(hover_voff_range.min == 0 && hover_voff_range.max == 0) if(hover_voff_range.min == 0 && hover_voff_range.max == 0)
{ {
CTRL_Entity *module = ctrl_entity_from_handle(d_state->ctrl_entity_store, hover_regs->module); CTRL_Entity *module = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, hover_regs->module);
hover_voff_range = ctrl_voff_range_from_vaddr_range(module, hover_regs->vaddr_range); hover_voff_range = ctrl_voff_range_from_vaddr_range(module, hover_regs->vaddr_range);
} }
ui_set_next_pref_height(ui_px(params->line_height_px*(dim_1s64(params->line_num_range)+1), 1.f)); ui_set_next_pref_height(ui_px(params->line_height_px*(dim_1s64(params->line_num_range)+1), 1.f));