From 751626446ae0ea15e75def9251fb133033f69f8b Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 6 Dec 2024 12:29:06 -0800 Subject: [PATCH] pending thread names in ctrl entity system, for cases where a thread name is established before the thread is reported as being created, and the id is used to correllate --- src/ctrl/ctrl.mdesk | 1 + src/ctrl/ctrl_core.c | 21 ++++++++- src/ctrl/generated/ctrl.meta.c | 3 +- src/ctrl/generated/ctrl.meta.h | 3 +- src/raddbg/raddbg_core.c | 84 ---------------------------------- src/raddbg/raddbg_core.h | 7 --- 6 files changed, 25 insertions(+), 94 deletions(-) diff --git a/src/ctrl/ctrl.mdesk b/src/ctrl/ctrl.mdesk index cf9f33ec..abc3401d 100644 --- a/src/ctrl/ctrl.mdesk +++ b/src/ctrl/ctrl.mdesk @@ -14,6 +14,7 @@ CTRL_EntityKindTable: {Module "Module" } {EntryPoint "Entry Point" } {DebugInfoPath "Debug Info Path" } + {PendingThreadName "Pending Thread Name" } } @enum CTRL_EntityKind: diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 9f72aaf6..85025cb0 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -1146,6 +1146,16 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) { ctrl_entity_equip_string(store, thread, str8_lit("main_thread")); } + CTRL_EntityList pending_thread_names = ctrl_entity_list_from_kind(store, CTRL_EntityKind_PendingThreadName); + for(CTRL_EntityNode *n = pending_thread_names.first; n != 0; n = n->next) + { + if(n->v->id == event->entity_id) + { + ctrl_entity_equip_string(store, thread, n->v->string); + ctrl_entity_release(store, n->v); + break; + } + } thread->stack_base = event->stack_base; ctrl_query_cached_rip_from_thread(store, event->entity); }break; @@ -1156,8 +1166,17 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list) }break; case CTRL_EventKind_ThreadName: { + CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent); CTRL_Entity *thread = ctrl_entity_from_handle(store, event->entity); - ctrl_entity_equip_string(store, thread, event->string); + if(thread != &ctrl_entity_nil) + { + ctrl_entity_equip_string(store, thread, event->string); + } + else + { + CTRL_Entity *pending_name = ctrl_entity_alloc(store, process, CTRL_EntityKind_PendingThreadName, Arch_Null, ctrl_handle_zero(), event->entity_id); + ctrl_entity_equip_string(store, pending_name, event->string); + } }break; case CTRL_EventKind_ThreadColor: { diff --git a/src/ctrl/generated/ctrl.meta.c b/src/ctrl/generated/ctrl.meta.c index 26bc0c99..019fde09 100644 --- a/src/ctrl/generated/ctrl.meta.c +++ b/src/ctrl/generated/ctrl.meta.c @@ -4,7 +4,7 @@ //- GENERATED CODE C_LINKAGE_BEGIN -String8 ctrl_entity_kind_display_string_table[8] = +String8 ctrl_entity_kind_display_string_table[9] = { {0}, str8_lit_comp("Root"), @@ -14,6 +14,7 @@ str8_lit_comp("Thread"), str8_lit_comp("Module"), str8_lit_comp("EntryPoint"), str8_lit_comp("DebugInfoPath"), +str8_lit_comp("PendingThreadName"), }; U32 ctrl_exception_code_kind_code_table[38] = diff --git a/src/ctrl/generated/ctrl.meta.h b/src/ctrl/generated/ctrl.meta.h index b5f03424..9192b4de 100644 --- a/src/ctrl/generated/ctrl.meta.h +++ b/src/ctrl/generated/ctrl.meta.h @@ -16,6 +16,7 @@ CTRL_EntityKind_Thread, CTRL_EntityKind_Module, CTRL_EntityKind_EntryPoint, CTRL_EntityKind_DebugInfoPath, +CTRL_EntityKind_PendingThreadName, CTRL_EntityKind_COUNT, } CTRL_EntityKind; @@ -63,7 +64,7 @@ CTRL_ExceptionCodeKind_COUNT, } CTRL_ExceptionCodeKind; C_LINKAGE_BEGIN -extern String8 ctrl_entity_kind_display_string_table[8]; +extern String8 ctrl_entity_kind_display_string_table[9]; extern U32 ctrl_exception_code_kind_code_table[38]; extern String8 ctrl_exception_code_kind_display_string_table[38]; extern String8 ctrl_exception_code_kind_lowercase_code_string_table[38]; diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index b81c4e66..a8982b70 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -327,56 +327,6 @@ rd_entity_array_from_list(Arena *arena, RD_EntityList *list) return result; } -//- rjf: entity fuzzy list building - -internal RD_EntityFuzzyItemArray -rd_entity_fuzzy_item_array_from_entity_list_needle(Arena *arena, RD_EntityList *list, String8 needle) -{ - Temp scratch = scratch_begin(&arena, 1); - RD_EntityArray array = rd_entity_array_from_list(scratch.arena, list); - RD_EntityFuzzyItemArray result = rd_entity_fuzzy_item_array_from_entity_array_needle(arena, &array, needle); - return result; -} - -internal RD_EntityFuzzyItemArray -rd_entity_fuzzy_item_array_from_entity_array_needle(Arena *arena, RD_EntityArray *array, String8 needle) -{ - Temp scratch = scratch_begin(&arena, 1); - RD_EntityFuzzyItemArray result = {0}; - result.count = array->count; - result.v = push_array(arena, RD_EntityFuzzyItem, result.count); - U64 result_idx = 0; - for(U64 src_idx = 0; src_idx < array->count; src_idx += 1) - { - RD_Entity *entity = array->v[src_idx]; - String8 display_string = rd_display_string_from_entity(scratch.arena, entity); - FuzzyMatchRangeList matches = fuzzy_match_find(arena, needle, display_string); - if(matches.count >= matches.needle_part_count) - { - result.v[result_idx].entity = entity; - result.v[result_idx].matches = matches; - result_idx += 1; - } - else - { - String8 search_tags = rd_search_tags_from_entity(scratch.arena, entity); - if(search_tags.size != 0) - { - FuzzyMatchRangeList tag_matches = fuzzy_match_find(scratch.arena, needle, search_tags); - if(tag_matches.count >= tag_matches.needle_part_count) - { - result.v[result_idx].entity = entity; - result.v[result_idx].matches = matches; - result_idx += 1; - } - } - } - } - result.count = result_idx; - scratch_end(scratch); - return result; -} - //- rjf: full path building, from file/folder entities internal String8 @@ -467,40 +417,6 @@ rd_display_string_from_entity(Arena *arena, RD_Entity *entity) return result; } -//- rjf: extra search tag strings for fuzzy filtering entities - -internal String8 -rd_search_tags_from_entity(Arena *arena, RD_Entity *entity) -{ - String8 result = {0}; - if(entity->kind == RD_EntityKind_Thread) - { - Temp scratch = scratch_begin(&arena, 1); - CTRL_Entity *entity_ctrl = ctrl_entity_from_handle(d_state->ctrl_entity_store, entity->ctrl_handle); - CTRL_Entity *process = ctrl_entity_ancestor_from_kind(entity_ctrl, CTRL_EntityKind_Process); - CTRL_Unwind unwind = d_query_cached_unwind_from_thread(entity_ctrl); - String8List strings = {0}; - for(U64 frame_num = unwind.frames.count; frame_num > 0; frame_num -= 1) - { - CTRL_UnwindFrame *f = &unwind.frames.v[frame_num-1]; - U64 rip_vaddr = regs_rip_from_arch_block(entity->arch, f->regs); - CTRL_Entity *module = ctrl_module_from_process_vaddr(process, rip_vaddr); - U64 rip_voff = ctrl_voff_from_vaddr(module, rip_vaddr); - DI_Key dbgi_key = ctrl_dbgi_key_from_module(module); - String8 procedure_name = d_symbol_name_from_dbgi_key_voff(scratch.arena, &dbgi_key, rip_voff, 0); - if(procedure_name.size != 0) - { - str8_list_push(scratch.arena, &strings, procedure_name); - } - } - StringJoin join = {0}; - join.sep = str8_lit(","); - result = str8_list_join(arena, &strings, &join); - scratch_end(scratch); - } - return result; -} - //- rjf: entity -> color operations internal Vec4F32 diff --git a/src/raddbg/raddbg_core.h b/src/raddbg/raddbg_core.h index 196c106b..f83977b8 100644 --- a/src/raddbg/raddbg_core.h +++ b/src/raddbg/raddbg_core.h @@ -1071,19 +1071,12 @@ internal void rd_entity_list_push(Arena *arena, RD_EntityList *list, RD_Entity * internal RD_EntityArray rd_entity_array_from_list(Arena *arena, RD_EntityList *list); #define rd_first_entity_from_list(list) ((list)->first != 0 ? (list)->first->entity : &d_nil_entity) -//- rjf: entity fuzzy list building -internal RD_EntityFuzzyItemArray rd_entity_fuzzy_item_array_from_entity_list_needle(Arena *arena, RD_EntityList *list, String8 needle); -internal RD_EntityFuzzyItemArray rd_entity_fuzzy_item_array_from_entity_array_needle(Arena *arena, RD_EntityArray *array, String8 needle); - //- rjf: full path building, from file/folder entities internal String8 rd_full_path_from_entity(Arena *arena, RD_Entity *entity); //- rjf: display string entities, for referencing entities in ui internal String8 rd_display_string_from_entity(Arena *arena, RD_Entity *entity); -//- rjf: extra search tag strings for fuzzy filtering entities -internal String8 rd_search_tags_from_entity(Arena *arena, RD_Entity *entity); - //- rjf: entity -> color operations internal Vec4F32 rd_hsva_from_entity(RD_Entity *entity); internal Vec4F32 rd_rgba_from_entity(RD_Entity *entity);