Skip to content

Commit

Permalink
fix moduleless unwinding and find-threads without debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfleury committed May 23, 2024
1 parent 35b97d9 commit 489ae56
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/ctrl/ctrl_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ ctrl_unwind_reg_from_pe_gpr_reg__pe_x64(REGS_RegBlockX64 *regs, PE_UnwindGprRegX
}

internal CTRL_UnwindStepResult
ctrl_unwind_step__pe_x64(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle module_handle, REGS_RegBlockX64 *regs, U64 endt_us)
ctrl_unwind_step__pe_x64(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle process_handle, DMN_Handle module_handle, REGS_RegBlockX64 *regs, U64 endt_us)
{
B32 is_stale = 0;
B32 is_good = 1;
Expand All @@ -1710,7 +1710,7 @@ ctrl_unwind_step__pe_x64(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN
//- rjf: unpack parameters
//
CTRL_Entity *module = ctrl_entity_from_machine_id_handle(store, machine_id, module_handle);
CTRL_Entity *process = module->parent;
CTRL_Entity *process = ctrl_entity_from_machine_id_handle(store, machine_id, process_handle);
U64 rip_voff = regs->rip.u64 - module->vaddr_range.min;

//////////////////////////////
Expand Down Expand Up @@ -2519,15 +2519,15 @@ ctrl_unwind_step__pe_x64(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN
//- rjf: abstracted unwind step

internal CTRL_UnwindStepResult
ctrl_unwind_step(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle module, Architecture arch, void *reg_block, U64 endt_us)
ctrl_unwind_step(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle process, DMN_Handle module, Architecture arch, void *reg_block, U64 endt_us)
{
CTRL_UnwindStepResult result = {0};
switch(arch)
{
default:{}break;
case Architecture_x64:
{
result = ctrl_unwind_step__pe_x64(store, machine_id, module, (REGS_RegBlockX64 *)reg_block, endt_us);
result = ctrl_unwind_step__pe_x64(store, machine_id, process, module, (REGS_RegBlockX64 *)reg_block, endt_us);
}break;
}
return result;
Expand Down Expand Up @@ -2589,7 +2589,7 @@ ctrl_unwind_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_MachineID ma
frame_node_count += 1;

// rjf: unwind one step
CTRL_UnwindStepResult step = ctrl_unwind_step(store, machine_id, module, arch, regs_block, endt_us);
CTRL_UnwindStepResult step = ctrl_unwind_step(store, machine_id, process_entity->handle, module, arch, regs_block, endt_us);
unwind.flags |= step.flags;
if(step.flags & CTRL_UnwindFlag_Error ||
regs_rsp_from_arch_block(arch, regs_block) == 0 ||
Expand Down
4 changes: 2 additions & 2 deletions src/ctrl/ctrl_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,10 @@ internal CTRL_Unwind ctrl_unwind_deep_copy(Arena *arena, Architecture arch, CTRL

//- rjf: [x64]
internal REGS_Reg64 *ctrl_unwind_reg_from_pe_gpr_reg__pe_x64(REGS_RegBlockX64 *regs, PE_UnwindGprRegX64 gpr_reg);
internal CTRL_UnwindStepResult ctrl_unwind_step__pe_x64(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle module, REGS_RegBlockX64 *regs, U64 endt_us);
internal CTRL_UnwindStepResult ctrl_unwind_step__pe_x64(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle process_handle, DMN_Handle module, REGS_RegBlockX64 *regs, U64 endt_us);

//- rjf: abstracted unwind step
internal CTRL_UnwindStepResult ctrl_unwind_step(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle module, Architecture arch, void *reg_block, U64 endt_us);
internal CTRL_UnwindStepResult ctrl_unwind_step(CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle process_handle, DMN_Handle module, Architecture arch, void *reg_block, U64 endt_us);

//- rjf: abstracted full unwind
internal CTRL_Unwind ctrl_unwind_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_MachineID machine_id, DMN_Handle thread, U64 endt_us);
Expand Down
15 changes: 15 additions & 0 deletions src/df/gfx/df_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,21 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
df_cmd_list_push(arena, cmds, &params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_FindCodeLocation));
}

// rjf: snap to resolved address w/o line info
if(!missing_rip && !dbgi_pending && !has_line_info && !has_module)
{
DF_CmdParams params = df_cmd_params_from_window(ws);
params.entity = df_handle_from_entity(thread);
params.voff = rip_voff;
params.vaddr = rip_vaddr;
params.index = unwind_count;
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_Entity);
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_VirtualOff);
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_VirtualAddr);
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_Index);
df_cmd_list_push(arena, cmds, &params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_FindCodeLocation));
}

// rjf: retry on stopped, pending debug info
if(!df_ctrl_targets_running() && (dbgi_pending || missing_rip))
{
Expand Down

0 comments on commit 489ae56

Please sign in to comment.