diff --git a/command.c b/command.c index 85df614..e7d6078 100644 --- a/command.c +++ b/command.c @@ -150,12 +150,12 @@ command_print(struct mi_process proc, char *name, int name_length) u64 cfa = get_cfa_at_pc(proc, pc); struct mi_variable *variable = get_variable(proc, name, name_length, pc); - if (variable) { + if (cfa && variable) { u64 address = cfa + variable->location; long value = ptrace(PTRACE_PEEKDATA, proc.pid, address, NULL); int val4 = value & 0x00000000FFFFFFFF; printf("%.*s = %d\n", name_length, name, val4); } else { - printf("variable %.*s not found\n", name_length, name); + printf("Variable %.*s not found\n", name_length, name); } } \ No newline at end of file diff --git a/eh_frame.c b/eh_frame.c index c031209..d485998 100644 --- a/eh_frame.c +++ b/eh_frame.c @@ -1,6 +1,6 @@ static u64 iterate_call_frame_instructions(struct dwarf_cie *cie, u8 *data, u64 to_read, - struct mi_registers *regs, struct dwarf_regset *regset, u64 location) + struct dwarf_regset *regset, u64 location) { u64 read = 0; @@ -274,7 +274,7 @@ read_one_cie(struct dwarf_cie *header, u64 length, u8 *data, u8 *original_data) header->instructions = data; header->instructions_length = header->length - (data - original_data - 4); - data += iterate_call_frame_instructions(header, data, header->instructions_length, 0, 0, 0); + data += iterate_call_frame_instructions(header, data, header->instructions_length, 0, 0); if (has_R) { // NOTE(aolo2): this shit is undocumented. Best sources I could find: @@ -441,7 +441,7 @@ read_one_fde(struct mi_process proc, struct dwarf_cie *cie, u64 length, u8 *data header->instructions = data; header->instructions_length = header->length - (data - original_data - 4); - data += iterate_call_frame_instructions(cie, data, header->instructions_length, 0, 0, 0); + data += iterate_call_frame_instructions(cie, data, header->instructions_length, 0, 0); return(data - original_data); } @@ -515,7 +515,7 @@ eh_frame_find_fde(struct mi_process proc, u64 pc) } static struct dwarf_regset -eh_frame_init_registers(struct mi_process proc, struct mi_registers regs, struct dwarf_cie cie) +eh_frame_init_registers(struct mi_registers regs, struct dwarf_cie cie) { struct dwarf_regset regset = { 0 }; @@ -536,15 +536,15 @@ eh_frame_init_registers(struct mi_process proc, struct mi_registers regs, struct regset.system[14] = regs._sys.r14; regset.system[15] = regs._sys.r15; - iterate_call_frame_instructions(&cie, cie.instructions, cie.instructions_length, ®s, ®set, 0); + iterate_call_frame_instructions(&cie, cie.instructions, cie.instructions_length, ®set, 0); return(regset); } static struct dwarf_regset -eh_frame_find_pc(struct mi_process proc, struct dwarf_fde fde, struct mi_registers regs, struct dwarf_regset regset, u64 pc) +eh_frame_find_pc(struct dwarf_fde fde, struct dwarf_regset regset, u64 pc) { regset.loc = fde.low_pc; - iterate_call_frame_instructions(&fde.cie, fde.instructions, fde.instructions_length, ®s, ®set, pc); + iterate_call_frame_instructions(&fde.cie, fde.instructions, fde.instructions_length, ®set, pc); return(regset); } \ No newline at end of file diff --git a/util.c b/util.c index b7f148a..3a065d9 100644 --- a/util.c +++ b/util.c @@ -338,13 +338,14 @@ get_cfa_at_pc(struct mi_process proc, u64 pc) { struct dwarf_fde fde = eh_frame_find_fde(proc, pc); if (!fde.length) { - DIE("could not find FDE for pc!\n"); + printf("Could not find FDE for pc %#lx\n", pc); + return(0); } struct mi_registers regs = get_process_registers(proc); - struct dwarf_regset regset = eh_frame_init_registers(proc, regs, fde.cie); + struct dwarf_regset regset = eh_frame_init_registers(regs, fde.cie); - regset = eh_frame_find_pc(proc, fde, regs, regset, pc); + regset = eh_frame_find_pc(fde, regset, pc); return(regset.cfa); } \ No newline at end of file