mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-12-01 01:53:20 -08:00
source/disassembly inline auto expressions
This commit is contained in:
1 parent
a60502d765
commit
cb8f2749d9
6 files changed
+273
-233
No files matched your search
@@ -9821,6 +9821,182 @@ rd_vocab_info_from_code_name_plural(String8 code_name_plural)
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Auto Watch Computation
|
||||
|
||||
internal String8Array
|
||||
rd_gather_auto_exprs(Arena *arena)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List auto_exprs = {0};
|
||||
ProfScope("compute all autos")
|
||||
{
|
||||
Access *access = access_open();
|
||||
U64 seen_expr_slots_count = 16;
|
||||
String8Node **seen_expr_slots = push_array(scratch.arena, String8Node *, seen_expr_slots_count);
|
||||
D_Handle thread_handle = rd_regs()->thread;
|
||||
D_Entity *thread = d_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, thread_handle);
|
||||
D_CallStack call_stack = d_call_stack_from_thread(access, thread->handle, 0, 0);
|
||||
if(call_stack.frames_count != 0)
|
||||
{
|
||||
//- rjf: unpack thread / module / debug info / lines
|
||||
ARCH_Info *arch_info = arch_info_from_arch(thread->arch);
|
||||
D_Entity *process = d_entity_ancestor_from_kind(thread, D_EntityKind_Process);
|
||||
U64 thread_ip_vaddr = d_rip_from_thread(&d_user_state->ctrl_entity_store->ctx, thread_handle);
|
||||
D_Entity *module = d_module_from_process_vaddr(process, thread_ip_vaddr);
|
||||
DI_Key dbgi_key = d_dbgi_key_from_module(module);
|
||||
RDI_Parsed *rdi = di_rdi_from_key(access, dbgi_key, 0, 0);
|
||||
U64 thread_ip_voff = d_voff_from_vaddr(module, thread_ip_vaddr);
|
||||
D_LineList thread_ip_lines = d_lines_from_dbgi_key_voff(scratch.arena, dbgi_key, thread_ip_voff);
|
||||
|
||||
//- rjf: gather all relevant code vaddr ranges
|
||||
Rng1U64List code_vaddr_ranges = {0};
|
||||
{
|
||||
U64 line_range_limit = 0;
|
||||
for EachNode(n, D_LineNode, thread_ip_lines.first)
|
||||
{
|
||||
Rng1U64 line_voff_range = n->v.voff_range;
|
||||
Rng1U64 line_vaddr_range = d_vaddr_range_from_voff_range(module, line_voff_range);
|
||||
rng1u64_list_push(scratch.arena, &code_vaddr_ranges, line_vaddr_range);
|
||||
line_range_limit += 1;
|
||||
if(line_range_limit >= 16)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
rng1u64_list_push(scratch.arena, &code_vaddr_ranges, rd_state->autos_determining_vaddr_range);
|
||||
}
|
||||
|
||||
//- rjf: for each code vaddr range -> disassemble, look at src/dest of instructions,
|
||||
// map back to location info, & gather expressions for affected symbols
|
||||
for EachNode(n, Rng1U64Node, code_vaddr_ranges.first)
|
||||
{
|
||||
Rng1U64 vaddr_range = n->v;
|
||||
vaddr_range.max = Min(vaddr_range.min+64, vaddr_range.max);
|
||||
D_ProcessMemorySlice slice = d_process_memory_slice_from_vaddr_range(scratch.arena, process->handle, vaddr_range, 0, 0);
|
||||
for(U64 off = 0, next_off = 0; off < slice.data.size; off = next_off)
|
||||
{
|
||||
next_off = slice.data.size;
|
||||
|
||||
// rjf: disassemble next instruction
|
||||
DASM_Inst inst = dasm_inst_from_code(scratch.arena, thread->arch, vaddr_range.min + off, str8_skip(slice.data, off), DASM_Syntax_Intel);
|
||||
next_off = off + inst.size;
|
||||
|
||||
// rjf: gather locations from instruction
|
||||
struct
|
||||
{
|
||||
ARCH_RegCode reg_code;
|
||||
U64 reg_off;
|
||||
}
|
||||
inst_locations[] =
|
||||
{
|
||||
{inst.dst_reg_code, inst.dst_reg_off},
|
||||
{inst.src_reg_code, inst.src_reg_off},
|
||||
};
|
||||
|
||||
// rjf: for each location -> map to symbols, gather
|
||||
for EachElement(location_idx, inst_locations)
|
||||
{
|
||||
if(inst_locations[location_idx].reg_code != 0)
|
||||
{
|
||||
U64 reg_value = 0;
|
||||
void *regs = call_stack.frames[0].regs;
|
||||
Rng1U16 reg_rng = arch_info->reg_code_rng_table[inst_locations[location_idx].reg_code];
|
||||
reg_rng.max = Min(reg_rng.max, reg_rng.min + sizeof(reg_value));
|
||||
if(arch_reg_block_read_range(arch_info, regs, reg_rng, ®_value))
|
||||
{
|
||||
U64 affected_vaddr = reg_value + inst_locations[location_idx].reg_off;
|
||||
|
||||
// rjf: compare against locals
|
||||
{
|
||||
E_String2NumMap *locals_map = e_ir_ctx->locals_map;
|
||||
for(E_String2NumMapNode *n = locals_map->first; n != 0; n = n->order_next)
|
||||
{
|
||||
U64 local_num = n->num;
|
||||
if(local_num != 0)
|
||||
{
|
||||
U64 local_idx = local_num-1;
|
||||
RDI_Symbol *local = rdi_element_from_name_idx(rdi, LocalVariables, local_idx);
|
||||
if(rdi_kind_from_location(local->location) == RDI_LocationKind_AddrBytecodeStream ||
|
||||
rdi_kind_from_location(local->location) == RDI_LocationKind_AddrRegPlusOff ||
|
||||
rdi_kind_from_location(local->location) == RDI_LocationKind_AddrAddrRegPlusOff)
|
||||
{
|
||||
RDI_TypeNode *type_node = rdi_element_from_name_idx(rdi, TypeNodes, local->type_idx);
|
||||
E_OpList local_ops = e_oplist_from_location(scratch.arena, rdi, local->location);
|
||||
String8 local_bytecode = e_bytecode_from_oplist(scratch.arena, &local_ops);
|
||||
E_Interpretation local_addr_interpret = e_interpret(local_bytecode);
|
||||
U64 local_vaddr = local_addr_interpret.value.u64;
|
||||
Rng1U64 local_vaddr_range = r1u64(local_vaddr, local_vaddr+type_node->byte_size);
|
||||
if(contains_1u64(local_vaddr_range, affected_vaddr))
|
||||
{
|
||||
String8 local_name = str8_from_rdi_string_idx(rdi, local->name_string_idx);
|
||||
U64 hash = u64_hash_from_str8(local_name);
|
||||
U64 slot_idx = hash%seen_expr_slots_count;
|
||||
B32 already_seen = 0;
|
||||
for(String8Node *n = seen_expr_slots[slot_idx]; n != 0; n = n->next)
|
||||
{
|
||||
if(str8_match(n->string, local_name, 0))
|
||||
{
|
||||
already_seen = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!already_seen)
|
||||
{
|
||||
str8_list_push(scratch.arena, &auto_exprs, local_name);
|
||||
String8Node *n = push_array(scratch.arena, String8Node, 1);
|
||||
SLLStackPush(seen_expr_slots[slot_idx], n);
|
||||
n->string = local_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: compare against global variables
|
||||
{
|
||||
D_Entity *affected_module = d_module_from_process_vaddr(process, affected_vaddr);
|
||||
U64 affected_voff = d_voff_from_vaddr(affected_module, affected_vaddr);
|
||||
DI_Key affected_dbgi_key = d_dbgi_key_from_module(affected_module);
|
||||
RDI_Parsed *affected_rdi = di_rdi_from_key(access, affected_dbgi_key, 0, 0);
|
||||
RDI_Symbol *affected_gvar = rdi_global_variable_from_voff(affected_rdi, affected_voff);
|
||||
if(affected_gvar->name_string_idx != 0)
|
||||
{
|
||||
String8 gvar_name = fully_qualified_str8_from_rdi_symbol(arena, affected_rdi, affected_gvar);
|
||||
U64 hash = u64_hash_from_str8(gvar_name);
|
||||
U64 slot_idx = hash%seen_expr_slots_count;
|
||||
B32 already_seen = 0;
|
||||
for(String8Node *n = seen_expr_slots[slot_idx]; n != 0; n = n->next)
|
||||
{
|
||||
if(str8_match(n->string, gvar_name, 0))
|
||||
{
|
||||
already_seen = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!already_seen)
|
||||
{
|
||||
str8_list_push(scratch.arena, &auto_exprs, gvar_name);
|
||||
String8Node *n = push_array(scratch.arena, String8Node, 1);
|
||||
SLLStackPush(seen_expr_slots[slot_idx], n);
|
||||
n->string = gvar_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
access_close(access);
|
||||
}
|
||||
String8Array result = str8_array_from_list(arena, &auto_exprs);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Continuous Frame Requests
|
||||
|
||||
|
||||
Reference in new issue
Block a user