minidump thread names

This commit is contained in:
Ryan Fleury committed 2026-08-27 09:59:34 -07:00
1 parent 99ea44c4cc
commit 3e704eabb0
5 files changed
+165 -27

No files matched your search

+88 -6
View File
@@ -3951,6 +3951,9 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
D_Handle process = {0};
Arch process_arch = Arch_Null;
OperatingSystem process_os = OperatingSystem_Null;
U64 exception_vaddr = 0;
U32 exception_thread_id = 0;
U32 exception_code = 0;
{
////////////////////////////
//- rjf: try minidump parse -> construct events for entity creation
@@ -3987,6 +3990,8 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
MDMP_MemoryDescriptor64 *memories64 = 0;
U64 memories64_count = 0;
U64 memories64_base_foff = 0;
MDMP_ThreadName *thread_names = 0;
U64 thread_names_count = 0;
{
for EachIndex(idx, directories_count)
{
@@ -4008,6 +4013,15 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
threads = (MDMP_Thread *)(data.str + off);
threads_count = Min(threads_count_32, threads_count_max);
}break;
case MDMP_StreamKind_ThreadNames:
{
U32 thread_names_count_32 = 0;
U64 off = dir->location.foff;
off += str8_deserial_read_struct(data, off, &thread_names_count_32);
U64 thread_names_count_max = (data.size - off) / sizeof(MDMP_ThreadName);
thread_names = (MDMP_ThreadName *)(data.str + off);
thread_names_count = Min(thread_names_count_32, thread_names_count_max);
}break;
case MDMP_StreamKind_ModuleList:
{
U32 modules_count_32 = 0;
@@ -4035,6 +4049,14 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
memories64 = (MDMP_MemoryDescriptor64 *)(data.str + off);
memories64_count = Min(memories64_count, memories64_count_max);
}break;
case MDMP_StreamKind_Exception:
{
MDMP_ExceptionStream stream = {0};
str8_deserial_read_struct(data, dir->location.foff, &stream);
exception_vaddr = stream.exception.exception_addr;
exception_thread_id = stream.thread_id;
exception_code = stream.exception.exception_code;
}break;
}
}
}
@@ -4084,6 +4106,14 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
// rjf: gather threads
dump_threads_count = threads_count;
dump_threads = push_array(arena, D_DumpThread, dump_threads_count);
typedef struct DumpThreadNode DumpThreadNode;
struct DumpThreadNode
{
DumpThreadNode *next;
D_DumpThread *v;
};
U64 dump_thread_from_id_slots_count = threads_count;
DumpThreadNode **dump_thread_from_id_slots = push_array(scratch.arena, DumpThreadNode *, dump_thread_from_id_slots_count);
for EachIndex(idx, threads_count)
{
d_ctrl_state->ctrl_thread_dump_handle_id_gen += 1;
@@ -4092,6 +4122,38 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
dump_threads[idx].thread_handle = thread_handle;
dump_threads[idx].id = thread->id;
dump_threads[idx].context_foff = thread->thread_context.foff;
U64 slot_idx = u64_hash_from_str8(str8_struct(&thread->id))%dump_thread_from_id_slots_count;
DumpThreadNode *n = push_array(scratch.arena, DumpThreadNode, 1);
n->v = &dump_threads[idx];
SLLStackPush(dump_thread_from_id_slots[slot_idx], n);
}
// rjf: equip thread names
for EachIndex(idx, thread_names_count)
{
MDMP_ThreadName *thread_name = &thread_names[idx];
U64 slot_idx = u64_hash_from_str8(str8_struct(&thread_name->thread_id))%dump_thread_from_id_slots_count;
D_DumpThread *thread = 0;
for(DumpThreadNode *n = dump_thread_from_id_slots[slot_idx]; n != 0; n = n->next)
{
if(n->v->id == thread_name->thread_id)
{
thread = n->v;
break;
}
}
if(thread != 0)
{
U64 name_foff = thread_name->thread_name_foff;
U32 name_size_supposedly = 0;
U64 off = name_foff;
off += str8_deserial_read_struct(data, off, &name_size_supposedly);
U64 name_size_max = (data.size - off);
U64 name_size = Min(name_size_max, name_size_supposedly);
String16 name16 = str16((U16 *)(data.str + off), name_size/sizeof(U16));
String8 name8 = str8_from_16(arena, name16);
thread->name = name8;
}
}
// rjf: gather modules
@@ -4218,6 +4280,16 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
evt->entity_id = dump_threads[idx].id;
// TODO(rjf): evt->stack_base = ; (use thread->stack)
// TODO(rjf): evt->tls_root = ; (use thread->thread_context)
if(dump_threads[idx].name.size != 0)
{
D_Event *evt2 = d_event_list_push(scratch.arena, &evts);
evt2->kind = D_EventKind_ThreadName;
evt2->msg_id = msg->msg_id;
evt2->entity = thread_handle;
evt2->parent = process;
evt2->string = dump_threads[idx].name;
evt2->entity_id = dump_threads[idx].id;
}
}
//////////////////////////////
@@ -4229,12 +4301,6 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
D_Handle module_handle = dump_modules[idx].module_handle;
Rng1U64 vaddr_range = dump_modules[idx].vaddr_range;
#if 0
//- TODO(rjf): I don't think we can use this demon module info path here
DMN_ModuleInfo module_info = {0};
d_ctrl_thread__module_open(process, module_handle, vaddr_range.min, dump_modules[idx].path, r1u64(0, 0), 0);
#endif
//- rjf: analyze module file, produce module info
Arena *module_info_arena = arena_alloc();
D_ModuleInfo module_info = {0};
@@ -4329,6 +4395,22 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
event->kind = D_EventKind_Stopped;
event->cause = D_EventCause_Finished;
event->msg_id = msg->msg_id;
if(exception_thread_id != 0)
{
D_Handle thread = {0};
for EachIndex(idx, dump_threads_count)
{
if(dump_threads[idx].id == exception_thread_id)
{
thread = dump_threads[idx].thread_handle;
break;
}
}
event->cause = D_EventCause_InterruptedByException;
event->exception_code = exception_code;
event->entity = thread;
event->parent = process;
}
}
//- rjf: push all events from the parse
+1
View File
@@ -218,6 +218,7 @@ struct D_DumpThread
D_Handle thread_handle;
U32 id;
U64 context_foff;
String8 name;
};
typedef struct D_DumpModule D_DumpModule;
+35 -15
View File
@@ -1835,7 +1835,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
// rjf: no targets -> error
if(targets_to_launch->count == 0)
{
log_user_error(str8_lit("No active targets exist; cannot launch. You must select a target first."));
log_user_error(s("No active targets exist; cannot launch. You must select a target first."));
}
}break;
case D_CmdKind_Kill:
@@ -1843,7 +1843,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
D_Entity *process = d_entity_from_handle(params->process);
if(process == &d_entity_nil)
{
log_user_error(str8_lit("Cannot kill; no process was specified."));
log_user_error(s("Cannot kill; no process was specified."));
}
else
{
@@ -1868,7 +1868,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
D_Entity *process = d_entity_from_handle(params->process);
if(process == &d_entity_nil)
{
log_user_error(str8_lit("Cannot detach; no process specified."));
log_user_error(s("Cannot detach; no process specified."));
}
else
{
@@ -1882,19 +1882,28 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
case D_CmdKind_Continue:
{
B32 good_to_run = 0;
B32 any_non_dump_threads = 0;
D_EntityArray threads = d_entity_array_from_kind(D_EntityKind_Thread);
if(threads.count > 0)
{
for EachIndex(idx, threads.count)
{
D_Entity *thread = threads.v[idx];
if(threads.v[idx]->handle.controller_kind != D_ControllerKind_Dump)
{
any_non_dump_threads = 1;
}
if(!thread->is_frozen)
{
good_to_run = 1;
break;
}
}
if(good_to_run)
if(!any_non_dump_threads)
{
log_user_error(s("Cannot run with only dump file threads."));
}
else if(good_to_run)
{
need_run = 1;
run_kind = D_RunKind_Run;
@@ -1902,7 +1911,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
}
else
{
log_user_error(str8_lit("Cannot run with all threads frozen."));
log_user_error(s("Cannot run with all threads frozen."));
}
}
}break;
@@ -1916,18 +1925,22 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
D_Entity *thread = d_entity_from_handle(params->thread);
if(thread == &d_entity_nil)
{
log_user_error(str8_lit("Must have a selected thread to step."));
log_user_error(s("Must have a selected thread to step."));
}
else if(thread->handle.controller_kind == D_ControllerKind_Dump)
{
log_user_error(s("Cannot step a thread from a dump file."));
}
else if(d_ctrl_targets_running())
{
if(d_ctrl_last_run_kind() == D_RunKind_Run)
{
log_user_error(str8_lit("Must halt before stepping."));
log_user_error(s("Must halt before stepping."));
}
}
else if(thread->is_frozen)
{
log_user_error(str8_lit("Must thaw selected thread before stepping."));
log_user_error(s("Must thaw selected thread before stepping."));
}
else
{
@@ -1967,7 +1980,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
}
else if(!good_trap_net)
{
log_user_error(str8_lit("Could not successfully step."));
log_user_error(s("Could not successfully step."));
}
}
}break;
@@ -1988,12 +2001,19 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
case D_CmdKind_SetThreadIP:
{
D_Entity *thread = d_entity_from_handle(params->thread);
ARCH_Info *arch_info = arch_info_from_arch(thread->arch);
U64 vaddr = params->vaddr;
void *block = d_cached_reg_block_from_thread(scratch.arena, thread->handle);
arch_reg_block_write_ip(arch_info, block, vaddr);
B32 result = d_thread_write_reg_block(thread->handle, block);
(void)result;
if(thread->handle.controller_kind == D_ControllerKind_Dump)
{
log_user_error(s("Cannot write register values to dump file threads."));
}
else
{
ARCH_Info *arch_info = arch_info_from_arch(thread->arch);
U64 vaddr = params->vaddr;
void *block = d_cached_reg_block_from_thread(scratch.arena, thread->handle);
arch_reg_block_write_ip(arch_info, block, vaddr);
B32 result = d_thread_write_reg_block(thread->handle, block);
(void)result;
}
}break;
//- rjf: high-level composite target control operations
+7
View File
@@ -199,6 +199,13 @@ struct MDMP_ExceptionStream
MDMP_LocationDescriptor32 thread_context;
};
typedef struct MDMP_ThreadName MDMP_ThreadName;
struct MDMP_ThreadName
{
U32 thread_id;
U64 thread_name_foff;
};
typedef U16 MDMP_Arch;
typedef enum MDMP_ArchEnum
{
+34 -6
View File
@@ -1783,10 +1783,10 @@ rd_view_ui(Rng2F32 rect)
{
Temp scratch = scratch_begin(0, 0);
ui_set_next_flags(UI_BoxFlag_DefaultFocusNav);
UI_Focus(UI_FocusKind_On) UI_WidthFill UI_HeightFill UI_NamedColumn(str8_lit("empty_view"))
UI_Focus(UI_FocusKind_On) UI_WidthFill UI_HeightFill UI_NamedColumn(s("empty_view"))
UI_Padding(ui_pct(1, 0)) UI_Focus(UI_FocusKind_Null)
{
CFG_NodePtrList targets = cfg_node_top_level_list_from_string(scratch.arena, str8_lit("target"));
CFG_NodePtrList targets = cfg_node_top_level_list_from_string(scratch.arena, s("target"));
D_EntityArray processes = d_entity_array_from_kind(D_EntityKind_Process);
Rng2F32 view_rect = ui_top_parent()->rect;
@@ -1796,6 +1796,7 @@ rd_view_ui(Rng2F32 rect)
//- rjf: icon
{
F32 icon_dim = ui_top_font_size()*10.f;
ui_set_next_flags(UI_BoxFlag_AnimatePosY);
UI_PrefHeight(ui_px(icon_dim, 1.f))
UI_Row
UI_Padding(ui_pct(1, 0))
@@ -11386,6 +11387,7 @@ rd_init(CmdLine *cmdln)
//- rjf: setup initial target from command line args
String8 implicit_user_arg = {0};
String8 implicit_project_arg = {0};
String8 implicit_dmp_arg = {0};
{
Temp scratch2 = scratch_begin(&scratch.arena, 1);
String8List target_args = {0};
@@ -11398,12 +11400,15 @@ rd_init(CmdLine *cmdln)
str8_match(str8_prefix(arg, 1), str8_lit("--"), 0) ||
str8_match(str8_prefix(arg, 1), str8_lit("/"), 0));
B32 is_cfg = 0;
B32 is_dmp = 0;
if(!is_flag && !after_first_non_flag)
{
File file = file_open(AccessFlag_Read|AccessFlag_ShareRead, arg);
U8 raddbg_cfg_magic[] = "// raddbg ";
U8 file_magic_maybe[ArrayCount(raddbg_cfg_magic)] = {0};
file_read(file, r1u64(0, 10), file_magic_maybe);
MDMP_Header mdmp_header_maybe = {0};
file_read_struct(file, 0, &mdmp_header_maybe);
if(MemoryMatchArray(raddbg_cfg_magic, file_magic_maybe))
{
is_cfg = 1;
@@ -11421,13 +11426,18 @@ rd_init(CmdLine *cmdln)
implicit_project_arg = path_absolute_dst_from_relative_dst_src(scratch.arena, arg, get_process_info()->initial_path);
}
}
else if(mdmp_header_maybe.magic == MDMP_MAGIC)
{
is_dmp = 1;
implicit_dmp_arg = arg;
}
file_close(file);
}
if(!is_flag)
{
after_first_non_flag = 1;
}
if(after_first_non_flag && !is_cfg)
if(after_first_non_flag && !is_cfg && !is_dmp)
{
str8_list_push(scratch2.arena, &target_args, arg);
}
@@ -11490,6 +11500,12 @@ rd_init(CmdLine *cmdln)
scratch_end(scratch2);
}
//- rjf: load dump arguments
if(implicit_dmp_arg.size != 0)
{
rd_cmd(RD_CmdKind_OpenCrashDump, .file_path = implicit_dmp_arg);
}
// rjf: set up user / project paths
{
Temp scratch2 = scratch_begin(&scratch.arena, 1);
@@ -13929,11 +13945,23 @@ rd_frame(void)
//- rjf: exiting
case RD_CmdKind_Exit:
{
D_EntityArray processes = d_entity_array_from_kind(D_EntityKind_Process);
// rjf: determine if we're attached to live processes
B32 attached_to_live_processes = 0;
for EachIndex(idx, processes.count)
{
if(processes.v[idx]->handle.controller_kind != D_ControllerKind_Dump)
{
attached_to_live_processes = 1;
break;
}
}
// rjf: if control processes are live, but this is not force-confirmed, then
// get confirmation from user
D_EntityArray processes = d_entity_array_from_kind(D_EntityKind_Process);
UI_Key key = ui_key_from_string(ui_key_zero(), str8_lit("lossy_exit_confirmation"));
if(processes.count != 0 && !rd_regs()->force_confirm && !ui_key_match(rd_state->popup_key, key))
UI_Key key = ui_key_from_string(ui_key_zero(), s("lossy_exit_confirmation"));
if(attached_to_live_processes && !rd_regs()->force_confirm && !ui_key_match(rd_state->popup_key, key))
{
rd_state->popup_key = key;
rd_state->popup_active = 1;