markup: thread id based APIs for names/colors; handle names/colors-before-thread, or id-based application, in ctrl layer

This commit is contained in:
Ryan Fleury
2025-05-03 16:45:45 -07:00
parent 5086d1b3db
commit 8b7e7471f5
9 changed files with 118 additions and 67 deletions
+3 -2
View File
@@ -14,8 +14,9 @@ CTRL_EntityKindTable:
{Module module "Module" }
{EntryPoint entry_point "Entry Point" }
{DebugInfoPath debug_info_path "Debug Info Path" }
{PendingThreadName pending_thread_name "Pending Thread Name" }
{Breakpoint breakpoint "Breakpoint" }
{PendingThreadName pending_thread_name "Pending Thread Name" }
{PendingThreadColor pending_thread_color "Pending Thread Color" }
{Breakpoint breakpoint "Breakpoint" }
}
@enum CTRL_EntityKind:
+61 -9
View File
@@ -1023,6 +1023,21 @@ ctrl_process_from_entity(CTRL_Entity *entity)
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)
{
@@ -1239,6 +1254,17 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
break;
}
}
CTRL_EntityArray pending_thread_colors = ctrl_entity_array_from_kind(store, CTRL_EntityKind_PendingThreadColor);
for EachIndex(idx, pending_thread_colors.count)
{
CTRL_Entity *entity = pending_thread_colors.v[idx];
if(entity->id == event->entity_id)
{
thread->rgba = entity->rgba;
ctrl_entity_release(store, entity);
break;
}
}
thread->stack_base = event->stack_base;
ctrl_query_cached_rip_from_thread(store, event->entity);
}break;
@@ -1250,21 +1276,46 @@ ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list)
case CTRL_EventKind_ThreadName:
{
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent);
CTRL_Entity *thread = ctrl_entity_from_handle(store, event->entity);
if(event->entity_id != 0)
CTRL_Entity *thread = &ctrl_entity_nil;
if(event->entity_id == 0)
{
thread = ctrl_entity_from_handle(store, event->entity);
}
else
{
thread = ctrl_thread_from_id(store, event->entity_id);
}
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);
}
else if(thread != &ctrl_entity_nil)
{
ctrl_entity_equip_string(store, thread, event->string);
}
}break;
case CTRL_EventKind_ThreadColor:
{
CTRL_Entity *thread = ctrl_entity_from_handle(store, event->entity);
thread->rgba = event->rgba;
CTRL_Entity *process = ctrl_entity_from_handle(store, event->parent);
CTRL_Entity *thread = &ctrl_entity_nil;
if(event->entity_id == 0)
{
thread = ctrl_entity_from_handle(store, event->entity);
}
else
{
thread = ctrl_thread_from_id(store, event->entity_id);
}
if(thread != &ctrl_entity_nil)
{
thread->rgba = event->rgba;
}
else
{
CTRL_Entity *pending = ctrl_entity_alloc(store, process, CTRL_EntityKind_PendingThreadColor, Arch_Null, ctrl_handle_zero(), event->entity_id);
pending->rgba = event->rgba;
}
}break;
case CTRL_EventKind_ThreadFrozen:
{
@@ -4399,7 +4450,8 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
out_evt->msg_id = msg->msg_id;
out_evt->entity = ctrl_handle_make(CTRL_MachineID_Local, event->thread);
out_evt->parent = ctrl_handle_make(CTRL_MachineID_Local, event->process);
out_evt->rgba = event->code;
out_evt->entity_id = event->code;
out_evt->rgba = event->user_data;
}break;
case DMN_EventKind_SetBreakpoint:
{
+1
View File
@@ -843,6 +843,7 @@ internal CTRL_Entity *ctrl_entity_from_handle(CTRL_EntityStore *store, CTRL_Hand
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);
+4 -2
View File
@@ -4,7 +4,7 @@
//- GENERATED CODE
C_LINKAGE_BEGIN
String8 ctrl_entity_kind_code_name_table[10] =
String8 ctrl_entity_kind_code_name_table[11] =
{
{0},
str8_lit_comp("root"),
@@ -15,10 +15,11 @@ str8_lit_comp("module"),
str8_lit_comp("entry_point"),
str8_lit_comp("debug_info_path"),
str8_lit_comp("pending_thread_name"),
str8_lit_comp("pending_thread_color"),
str8_lit_comp("breakpoint"),
};
String8 ctrl_entity_kind_display_string_table[10] =
String8 ctrl_entity_kind_display_string_table[11] =
{
{0},
str8_lit_comp("Root"),
@@ -29,6 +30,7 @@ str8_lit_comp("Module"),
str8_lit_comp("EntryPoint"),
str8_lit_comp("DebugInfoPath"),
str8_lit_comp("PendingThreadName"),
str8_lit_comp("PendingThreadColor"),
str8_lit_comp("Breakpoint"),
};
+3 -2
View File
@@ -17,6 +17,7 @@ CTRL_EntityKind_Module,
CTRL_EntityKind_EntryPoint,
CTRL_EntityKind_DebugInfoPath,
CTRL_EntityKind_PendingThreadName,
CTRL_EntityKind_PendingThreadColor,
CTRL_EntityKind_Breakpoint,
CTRL_EntityKind_COUNT,
} CTRL_EntityKind;
@@ -65,8 +66,8 @@ CTRL_ExceptionCodeKind_COUNT,
} CTRL_ExceptionCodeKind;
C_LINKAGE_BEGIN
extern String8 ctrl_entity_kind_code_name_table[10];
extern String8 ctrl_entity_kind_display_string_table[10];
extern String8 ctrl_entity_kind_code_name_table[11];
extern String8 ctrl_entity_kind_display_string_table[11];
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];