Skip to content

Commit c8c25c0

Browse files
committed
processless debug info loading/unloading; separate modules from dbg infos in eval; keep dbg infos around after debugging via config, correllate to new modules, evict when necessary, when generating new versions
1 parent f9d1ffa commit c8c25c0

File tree

21 files changed

+1274
-884
lines changed

21 files changed

+1274
-884
lines changed

src/ctrl/ctrl_core.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,7 @@ ctrl_thread__entry_point(void *p)
31893189
CTRL_Entity *module = ctrl_entity_from_handle(entity_ctx, msg->entity);
31903190
CTRL_Entity *debug_info_path = ctrl_entity_child_from_kind(module, CTRL_EntityKind_DebugInfoPath);
31913191
DI_Key old_dbgi_key = di_key_from_path_timestamp(debug_info_path->string, debug_info_path->timestamp);
3192-
di_close(old_dbgi_key);
3192+
di_close(old_dbgi_key, 0);
31933193
MutexScopeW(ctrl_state->ctrl_thread_entity_ctx_rw_mutex)
31943194
{
31953195
ctrl_entity_equip_string(ctrl_state->ctrl_thread_entity_store, debug_info_path, path_normalized_from_string(scratch.arena, path));
@@ -4112,7 +4112,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
41124112
out_evt->entity = module_handle;
41134113
out_evt->string = module_path;
41144114
DI_Key dbgi_key = ctrl_dbgi_key_from_module(module_ent);
4115-
di_close(dbgi_key);
4115+
di_close(dbgi_key, 0);
41164116
}break;
41174117
case DMN_EventKind_DebugString:
41184118
{
@@ -4274,15 +4274,19 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C
42744274
U64 thread_rip_voff = ctrl_voff_from_vaddr(module, thread_rip_vaddr);
42754275

42764276
//////////////////////////////
4277-
//- rjf: gather evaluation modules
4277+
//- rjf: gather evaluation debug infos & modules
42784278
//
42794279
U64 eval_modules_count = Max(1, entity_ctx->entity_kind_counts[CTRL_EntityKind_Module]);
42804280
E_Module *eval_modules = push_array(arena, E_Module, eval_modules_count);
42814281
E_Module *eval_modules_primary = &eval_modules[0];
4282-
eval_modules_primary->rdi = &rdi_parsed_nil;
42834282
eval_modules_primary->vaddr_range = r1u64(0, max_U64);
4283+
U64 eval_dbg_infos_count = Max(1, entity_ctx->entity_kind_counts[CTRL_EntityKind_Module]);
4284+
E_DbgInfo *eval_dbg_infos = push_array(arena, E_DbgInfo, eval_dbg_infos_count);
4285+
E_DbgInfo *eval_dbg_infos_primary = &eval_dbg_infos[0];
4286+
MemoryCopyStruct(eval_dbg_infos_primary, &e_dbg_info_nil);
42844287
{
42854288
U64 eval_module_idx = 0;
4289+
U64 eval_dbg_info_idx = 0;
42864290
for(CTRL_Entity *machine = entity_ctx->root->first;
42874291
machine != &ctrl_entity_nil;
42884292
machine = machine->next)
@@ -4392,10 +4396,18 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C
43924396
rdi = di_rdi_from_key(scope->access, dbgi_key, 1, max_U64);
43934397
}
43944398

4399+
//- rjf: fill debug info
4400+
eval_dbg_infos[eval_dbg_info_idx].dbgi_key = dbgi_key;
4401+
eval_dbg_infos[eval_dbg_info_idx].rdi = rdi;
4402+
if(mod == module)
4403+
{
4404+
eval_dbg_infos_primary = &eval_dbg_infos[eval_dbg_info_idx];
4405+
}
4406+
eval_dbg_info_idx += 1;
4407+
43954408
//- rjf: fill evaluation module info
43964409
eval_modules[eval_module_idx].arch = arch;
4397-
eval_modules[eval_module_idx].dbgi_key = dbgi_key;
4398-
eval_modules[eval_module_idx].rdi = rdi;
4410+
eval_modules[eval_module_idx].dbg_info_num= (U32)eval_dbg_info_idx;
43994411
eval_modules[eval_module_idx].vaddr_range = mod->vaddr_range;
44004412
eval_modules[eval_module_idx].space = e_space_make(CTRL_EvalSpaceKind_Entity);
44014413
eval_modules[eval_module_idx].space.u64_0 = (U64)process;
@@ -4427,6 +4439,11 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C
44274439
ctx->thread_reg_space = e_space_make(CTRL_EvalSpaceKind_Entity);
44284440
ctx->thread_reg_space.u64_0 = (U64)thread;
44294441

4442+
//- rjf: fill debug infos
4443+
ctx->dbg_infos = eval_dbg_infos;
4444+
ctx->dbg_infos_count = eval_dbg_infos_count;
4445+
ctx->primary_dbg_info = eval_dbg_infos_primary;
4446+
44304447
//- rjf: fill modules
44314448
ctx->modules = eval_modules;
44324449
ctx->modules_count = eval_modules_count;
@@ -4445,8 +4462,8 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C
44454462
E_IRCtx *ctx = &scope->ir_ctx;
44464463
ctx->regs_map = ctrl_string2reg_from_arch(arch);
44474464
ctx->reg_alias_map = ctrl_string2alias_from_arch(arch);
4448-
ctx->locals_map = e_push_locals_map_from_rdi_voff(arena, eval_modules_primary->rdi, thread_rip_voff);
4449-
ctx->member_map = e_push_member_map_from_rdi_voff(arena, eval_modules_primary->rdi, thread_rip_voff);
4465+
ctx->locals_map = e_push_locals_map_from_rdi_voff(arena, eval_dbg_infos_primary->rdi, thread_rip_voff);
4466+
ctx->member_map = e_push_member_map_from_rdi_voff(arena, eval_dbg_infos_primary->rdi, thread_rip_voff);
44504467
ctx->macro_map = push_array(arena, E_String2ExprMap, 1);
44514468
ctx->macro_map[0] = e_string2expr_map_make(arena, 512);
44524469
ctx->auto_hook_map = push_array(arena, E_AutoHookMap, 1);
@@ -4469,7 +4486,7 @@ ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, C
44694486
// TODO(rjf): need to compute this out here somehow... ctx->frame_base[0] = ;
44704487
ctx->tls_base = push_array(arena, U64, 1);
44714488
}
4472-
e_select_interpret_ctx(&scope->interpret_ctx, eval_modules_primary->rdi, thread_rip_voff);
4489+
e_select_interpret_ctx(&scope->interpret_ctx, eval_dbg_infos_primary->rdi, thread_rip_voff);
44734490

44744491
ProfEnd();
44754492
return scope;

src/dbg_engine/dbg_engine_core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,16 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
15001500
evt->code = event->u64_code;
15011501
}break;
15021502

1503+
case CTRL_EventKind_NewModule:
1504+
{
1505+
D_EventNode *n = push_array(arena, D_EventNode, 1);
1506+
SLLQueuePush(result.first, result.last, n);
1507+
result.count += 1;
1508+
D_Event *evt = &n->v;
1509+
evt->kind = D_EventKind_ModuleLoad;
1510+
evt->module = event->entity;
1511+
}break;
1512+
15031513
//- rjf: debug strings
15041514

15051515
case CTRL_EventKind_DebugString:

src/dbg_engine/dbg_engine_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct D_TrapNet
8686
typedef enum D_EventKind
8787
{
8888
D_EventKind_Null,
89+
D_EventKind_ModuleLoad,
8990
D_EventKind_ProcessEnd,
9091
D_EventKind_Stop,
9192
D_EventKind_COUNT
@@ -107,6 +108,7 @@ struct D_Event
107108
{
108109
D_EventKind kind;
109110
D_EventCause cause;
111+
CTRL_Handle module;
110112
CTRL_Handle thread;
111113
U64 vaddr;
112114
U64 code;

src/dbg_info/dbg_info.c

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ di_open(DI_Key key)
313313
}
314314

315315
internal void
316-
di_close(DI_Key key)
317-
{
316+
di_close(DI_Key key, B32 force_closed)
317+
{
318318
//- rjf: unpack key
319319
U64 hash = u64_hash_from_str8(str8_struct(&key));
320320
U64 slot_idx = hash%di_shared->slots_count;
@@ -340,8 +340,15 @@ di_close(DI_Key key)
340340
}
341341
}
342342
if(node)
343-
{
344-
node->refcount -= 1;
343+
{
344+
if(force_closed)
345+
{
346+
node->refcount = 0;
347+
}
348+
else
349+
{
350+
node->refcount -= 1;
351+
}
345352
if(node->refcount == 0)
346353
{
347354
for(;;)
@@ -377,7 +384,7 @@ di_close(DI_Key key)
377384
{
378385
arena_release(arena);
379386
}
380-
}
387+
}
381388
}
382389

383390
////////////////////////////////
@@ -754,8 +761,31 @@ di_async_tick(void)
754761
threads_available = (max_threads >= needed_threads);
755762
}
756763

764+
//- rjf: if this conversion will overwrite an RDI we already have in cache,
765+
// then we need to evict the old one from the cache.
766+
B32 ready_to_launch_conversion = (threads_available && !og_is_rdi && rdi_is_stale && t->thread_count != 0 && t->status != DI_LoadTaskStatus_Active);
767+
if(ready_to_launch_conversion)
768+
{
769+
U64 path2key_hash = u64_hash_from_str8(og_path);
770+
U64 path2key_slot_idx = path2key_hash%di_shared->path2key_slots_count;
771+
DI_KeySlot *path2key_slot = &di_shared->path2key_slots[path2key_slot_idx];
772+
Stripe *path2key_stripe = stripe_from_slot_idx(&di_shared->path2key_stripes, path2key_slot_idx);
773+
RWMutexScope(path2key_stripe->rw_mutex, 0)
774+
{
775+
// NOTE(rjf): we need to iterate from last -> first, since we want to evict the
776+
// most recent key.
777+
for(DI_KeyPathNode *n = path2key_slot->last; n != 0; n = n->prev)
778+
{
779+
if(str8_match(n->path, og_path, 0) && !di_key_match(key, n->key))
780+
{
781+
di_close(n->key, 1);
782+
}
783+
}
784+
}
785+
}
786+
757787
//- rjf: launch conversion processes
758-
if(threads_available && !og_is_rdi && rdi_is_stale && t->thread_count != 0 && t->status != DI_LoadTaskStatus_Active)
788+
if(ready_to_launch_conversion)
759789
{
760790
B32 should_compress = 0;
761791
OS_ProcessLaunchParams params = {0};
@@ -960,8 +990,11 @@ di_async_tick(void)
960990
node->arena = rdi_parsed_arena;
961991
MemoryCopyStruct(&node->rdi, &rdi_parsed);
962992
node->completion_count += 1;
963-
node->working_count -= 1;
964-
ins_atomic_u64_inc_eval(&di_shared->load_gen);
993+
node->working_count -= 1;
994+
if(node->rdi.raw_data_size != 0)
995+
{
996+
ins_atomic_u64_inc_eval(&di_shared->load_gen);
997+
}
965998
ins_atomic_u64_inc_eval(&di_shared->load_count);
966999
}
9671000
else

src/dbg_info/dbg_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ internal DI_Key di_key_from_path_timestamp(String8 path, U64 min_timestamp);
323323
//~ rjf: Debug Info Opening / Closing
324324

325325
internal void di_open(DI_Key key);
326-
internal void di_close(DI_Key key);
326+
internal void di_close(DI_Key key, B32 force_closed);
327327

328328
////////////////////////////////
329329
//~ rjf: Debug Info Lookups

src/eval/eval_core.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,10 @@ internal void
676676
e_select_base_ctx(E_BaseCtx *ctx)
677677
{
678678
//- rjf: select base context
679-
if(ctx->modules == 0) { ctx->modules = &e_module_nil; }
680-
if(ctx->primary_module == 0) { ctx->primary_module = &e_module_nil; }
679+
if(ctx->modules == 0) { ctx->modules = &e_module_nil; }
680+
if(ctx->primary_module == 0) { ctx->primary_module = &e_module_nil; }
681+
if(ctx->dbg_infos == 0) { ctx->dbg_infos = &e_dbg_info_nil; }
682+
if(ctx->primary_dbg_info == 0) { ctx->primary_dbg_info = &e_dbg_info_nil; }
681683
e_base_ctx = ctx;
682684

683685
//- rjf: reset the evaluation cache
@@ -718,7 +720,7 @@ e_select_base_ctx(E_BaseCtx *ctx)
718720
.id_from_num = E_TYPE_EXPAND_ID_FROM_NUM_FUNCTION_NAME(folder),
719721
.num_from_id = E_TYPE_EXPAND_NUM_FROM_ID_FUNCTION_NAME(folder),
720722
});
721-
e_cache->thread_ip_procedure = rdi_procedure_from_voff(e_base_ctx->primary_module->rdi, e_base_ctx->thread_ip_voff);
723+
e_cache->thread_ip_procedure = rdi_procedure_from_voff(e_base_ctx->primary_dbg_info->rdi, e_base_ctx->thread_ip_voff);
722724
e_cache->used_expr_map = push_array(e_cache->arena, E_UsedExprMap, 1);
723725
e_cache->used_expr_map->slots_count = 64;
724726
e_cache->used_expr_map->slots = push_array(e_cache->arena, E_UsedExprSlot, e_cache->used_expr_map->slots_count);
@@ -744,6 +746,20 @@ e_select_ir_ctx(E_IRCtx *ctx)
744746
e_ir_ctx = ctx;
745747
}
746748

749+
////////////////////////////////
750+
//~ rjf: Context Accessors
751+
752+
internal E_DbgInfo *
753+
e_dbg_info_from_module(E_Module *module)
754+
{
755+
E_DbgInfo *result = &e_dbg_info_nil;
756+
if(0 < module->dbg_info_num && module->dbg_info_num <= e_base_ctx->dbg_infos_count)
757+
{
758+
result = &e_base_ctx->dbg_infos[module->dbg_info_num-1];
759+
}
760+
return result;
761+
}
762+
747763
////////////////////////////////
748764
//~ rjf: Cache Accessing Functions
749765

src/eval/eval_core.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,15 +564,24 @@ struct E_ConsTypeSlot
564564
E_ConsTypeNode *last;
565565
};
566566

567+
////////////////////////////////
568+
//~ rjf: Debug Info
569+
570+
typedef struct E_DbgInfo E_DbgInfo;
571+
struct E_DbgInfo
572+
{
573+
DI_Key dbgi_key;
574+
RDI_Parsed *rdi;
575+
};
576+
567577
////////////////////////////////
568578
//~ rjf: Modules
569579

570580
typedef struct E_Module E_Module;
571581
struct E_Module
572582
{
573-
DI_Key dbgi_key;
574-
RDI_Parsed *rdi;
575583
Rng1U64 vaddr_range;
584+
U32 dbg_info_num;
576585
Arch arch;
577586
E_Space space;
578587
};
@@ -760,6 +769,11 @@ struct E_BaseCtx
760769
Arch thread_arch;
761770
U64 thread_unwind_count;
762771

772+
// rjf: debug infos
773+
E_DbgInfo *dbg_infos;
774+
U64 dbg_infos_count;
775+
E_DbgInfo *primary_dbg_info;
776+
763777
// rjf: modules
764778
E_Module *modules;
765779
U64 modules_count;
@@ -1111,7 +1125,8 @@ read_only global E_String2ExprMap e_string2expr_map_nil = {0};
11111125
read_only global E_Expr e_expr_nil = {&e_expr_nil, &e_expr_nil, &e_expr_nil, &e_expr_nil, &e_expr_nil};
11121126
read_only global E_IRNode e_irnode_nil = {&e_irnode_nil, &e_irnode_nil, &e_irnode_nil};
11131127
read_only global E_Eval e_eval_nil = {{0}, {0}, {0}, &e_expr_nil, {&e_irnode_nil}};
1114-
read_only global E_Module e_module_nil = {{0}, &rdi_parsed_nil};
1128+
read_only global E_DbgInfo e_dbg_info_nil = {{0}, &rdi_parsed_nil};
1129+
read_only global E_Module e_module_nil = {0};
11151130
read_only global E_CacheBundle e_cache_bundle_nil = {0, {0}, {0}, {0}, {{0}, 0, &e_expr_nil, &e_expr_nil}, {&e_irnode_nil}};
11161131
thread_static E_BaseCtx *e_base_ctx = 0;
11171132
thread_static E_IRCtx *e_ir_ctx = 0;
@@ -1203,6 +1218,11 @@ internal void e_select_cache(E_Cache *cache);
12031218
internal void e_select_base_ctx(E_BaseCtx *ctx);
12041219
internal void e_select_ir_ctx(E_IRCtx *ctx);
12051220

1221+
////////////////////////////////
1222+
//~ rjf: Context Accessors
1223+
1224+
internal E_DbgInfo *e_dbg_info_from_module(E_Module *module);
1225+
12061226
////////////////////////////////
12071227
//~ rjf: Base Cache Accessing Functions
12081228
//

0 commit comments

Comments
 (0)