Skip to content

Commit

Permalink
pending thread names in ctrl entity system, for cases where a thread …
Browse files Browse the repository at this point in the history
…name is established before the thread is reported as being created, and the id is used to correllate
  • Loading branch information
ryanfleury committed Dec 6, 2024
1 parent 59e2d7d commit 7516264
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 94 deletions.
1 change: 1 addition & 0 deletions src/ctrl/ctrl.mdesk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CTRL_EntityKindTable:
{Module "Module" }
{EntryPoint "Entry Point" }
{DebugInfoPath "Debug Info Path" }
{PendingThreadName "Pending Thread Name" }
}

@enum CTRL_EntityKind:
Expand Down
21 changes: 20 additions & 1 deletion src/ctrl/ctrl_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
{
Expand Down
3 changes: 2 additions & 1 deletion src/ctrl/generated/ctrl.meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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] =
Expand Down
3 changes: 2 additions & 1 deletion src/ctrl/generated/ctrl.meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CTRL_EntityKind_Thread,
CTRL_EntityKind_Module,
CTRL_EntityKind_EntryPoint,
CTRL_EntityKind_DebugInfoPath,
CTRL_EntityKind_PendingThreadName,
CTRL_EntityKind_COUNT,
} CTRL_EntityKind;

Expand Down Expand Up @@ -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];
Expand Down
84 changes: 0 additions & 84 deletions src/raddbg/raddbg_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/raddbg/raddbg_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7516264

Please sign in to comment.