From 10e8a10d9bdbfa4a21898c795f031c54617ceea4 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Wed, 24 Sep 2025 16:06:46 -0700 Subject: [PATCH] adjust new call stack artifact cache hooks to work gracefully with terminated threads/processes --- src/ctrl/ctrl_core.c | 22 ++++++++++++---------- src/file_stream/file_stream.c | 4 +--- src/file_stream/file_stream.h | 1 - src/raddbg/raddbg_core.c | 6 +++--- src/raddbg/raddbg_eval.c | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 5ed8b14d..c9d04747 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -7727,11 +7727,15 @@ ctrl_call_stack_artifact_create(String8 key, B32 *retry_out) } //- rjf: compute call stack - B32 good = 0; - Arena *arena = arena_alloc(); - CTRL_CallStack *call_stack = push_array(arena, CTRL_CallStack, 1); + CTRL_Entity *thread = ctrl_entity_from_handle(entity_ctx, thread_handle); + B32 good = 1; + Arena *arena = 0; + CTRL_CallStack *call_stack = 0; + if(thread != &ctrl_entity_nil) { - CTRL_Entity *thread = ctrl_entity_from_handle(entity_ctx, thread_handle); + good = 0; + arena = arena_alloc(); + call_stack = push_array(arena, CTRL_CallStack, 1); CTRL_Entity *process = ctrl_process_from_entity(thread); U64 pre_reg_gen = 0; U64 post_reg_gen = 0; @@ -7754,6 +7758,10 @@ ctrl_call_stack_artifact_create(String8 key, B32 *retry_out) { good = 0; } + if(!good) + { + arena_release(arena); + } } //- rjf: broadcast update @@ -7769,12 +7777,6 @@ ctrl_call_stack_artifact_create(String8 key, B32 *retry_out) artifact.u64[1] = (U64)call_stack; } - //- rjf: release results on bad - if(!good) - { - arena_release(arena); - } - //- rjf: retry on bad if(!good) { diff --git a/src/file_stream/file_stream.c b/src/file_stream/file_stream.c index c2b77e59..eb2fc240 100644 --- a/src/file_stream/file_stream.c +++ b/src/file_stream/file_stream.c @@ -184,7 +184,7 @@ fs_artifact_create(String8 key, B32 *retry_out) } MemoryZeroStruct(node); node->path = str8_copy(stripe->arena, path); - DLLPushBack(slot->first, slot->last, node); + SLLQueuePush(slot->first, slot->last, node); } node->last_modified_timestamp = pre_props.modified; node->size = pre_props.size; @@ -207,7 +207,6 @@ fs_artifact_destroy(AC_Artifact artifact) { C_Key key = {0}; MemoryCopyStruct(&key, &artifact); - key._padding_ = 0; c_close_key(key); } @@ -247,7 +246,6 @@ fs_key_from_path_range(String8 path, Rng1U64 range, U64 endt_us) //- rjf: map to artifact AC_Artifact artifact = ac_artifact_from_key(access, key, fs_artifact_create, fs_artifact_destroy, endt_us, .gen = gen); MemoryCopyStruct(&result, &artifact); - result._padding_ = 0; } access_close(access); scratch_end(scratch); diff --git a/src/file_stream/file_stream.h b/src/file_stream/file_stream.h index 8b9306b2..9bc219ca 100644 --- a/src/file_stream/file_stream.h +++ b/src/file_stream/file_stream.h @@ -11,7 +11,6 @@ typedef struct FS_Node FS_Node; struct FS_Node { FS_Node *next; - FS_Node *prev; String8 path; U64 gen; U64 last_modified_timestamp; diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index f95783b3..a0caab90 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -12493,10 +12493,10 @@ rd_frame(void) }; for EachElement(idx, table) { - C_Scope *c_scope = c_scope_open(); + Access *access = access_open(); C_Key key = table[idx].key; U128 hash = c_hash_from_key(key, 0); - String8 data = c_data_from_hash(c_scope, hash); + String8 data = c_data_from_hash(access, hash); E_Space space = e_space_make(E_SpaceKind_HashStoreKey); E_Expr *expr = e_push_expr(scratch.arena, E_ExprKind_LeafOffset, r1u64(0, 0)); space.u64_0 = key.root.u64[0]; @@ -12505,7 +12505,7 @@ rd_frame(void) expr->mode = E_Mode_Offset; expr->type_key = e_type_key_cons_array(e_type_key_basic(E_TypeKind_U8), data.size, 0); e_string2expr_map_insert(scratch.arena, macro_map, table[idx].name, expr); - c_scope_close(c_scope); + access_close(access); } } #endif diff --git a/src/raddbg/raddbg_eval.c b/src/raddbg/raddbg_eval.c index c1795d34..d6b98a8b 100644 --- a/src/raddbg/raddbg_eval.c +++ b/src/raddbg/raddbg_eval.c @@ -968,7 +968,7 @@ E_TYPE_IREXT_FUNCTION_DEF(call_stack) B32 call_stack_high_priority = ctrl_handle_match(entity->handle, rd_base_regs()->thread); accel->arch = entity->arch; accel->process = ctrl_process_from_entity(entity)->handle; - accel->call_stack = ctrl_call_stack_from_thread(rd_state->frame_ctrl_scope, entity->handle, call_stack_high_priority, call_stack_high_priority ? rd_state->frame_eval_memread_endt_us : 0); + accel->call_stack = ctrl_call_stack_from_thread_new(rd_state->frame_access, entity->handle, call_stack_high_priority, call_stack_high_priority ? rd_state->frame_eval_memread_endt_us : 0); } scratch_end(scratch); }