From e1fe877ddd61dbaa4e1fac73cce9e296e1e70a35 Mon Sep 17 00:00:00 2001 From: aolo2 Date: Sun, 25 Jul 2021 15:00:37 +0300 Subject: [PATCH] Do not iterate instructions when we only need to know the length (just add the length, duh!) --- command.c | 1 - dwarf.c | 3 +-- eh_frame.c | 6 ++---- util.c | 28 ---------------------------- 4 files changed, 3 insertions(+), 35 deletions(-) diff --git a/command.c b/command.c index e7d6078..4c97f55 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,6 @@ command_step(struct mi_process proc) ptrace(PTRACE_SINGLESTEP, proc.pid, 0, 0); waitpid(proc.pid, 0, 0); regs = get_process_registers(proc); - long instruction = ptrace(PTRACE_PEEKDATA, proc.pid, regs.rip, NULL); next_sp = pc_to_sourcepoint(proc, regs.rip - proc.base_address, &comp_unit); if (!next_sp) break; } while (next_sp->line == sp->line); diff --git a/dwarf.c b/dwarf.c index 69487dd..04c3a5e 100644 --- a/dwarf.c +++ b/dwarf.c @@ -8,7 +8,6 @@ get_section_entry(u8 *file, char *name) struct elf_header_table_entry_x64 header_entry = { 0 }; u64 offset = header.header_table_offset + header.header_table_entry_size * i; memcpy(&header_entry, file + offset, sizeof(header_entry)); - int a = 1; } struct elf_section_table_entry_x64 shstrtab_header = { 0 }; @@ -119,7 +118,7 @@ abbrev_entry_offset(u8 *file, u64 abbrev_offset, u32 requested_code) offset += decode_leb128(file + abbrev_offset + offset, &tag); u32 has_children = file[abbrev_offset + offset++]; - + (void) has_children; if (code == requested_code) { return(abbrev_offset); } diff --git a/eh_frame.c b/eh_frame.c index d485998..0212b76 100644 --- a/eh_frame.c +++ b/eh_frame.c @@ -240,8 +240,6 @@ read_one_cie(struct dwarf_cie *header, u64 length, u8 *data, u8 *original_data) header->length = length; header->version = *data++; - char *augmenation_string = (char *) data; - // NOTE: null-terminated string int has_z = 0; int has_L = 0; @@ -274,7 +272,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); + data += header->instructions_length; if (has_R) { // NOTE(aolo2): this shit is undocumented. Best sources I could find: @@ -441,7 +439,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); + data += header->instructions_length; return(data - original_data); } diff --git a/util.c b/util.c index 3a065d9..41472dc 100644 --- a/util.c +++ b/util.c @@ -127,15 +127,6 @@ pc_to_sourcepoint(struct mi_process proc, u64 pc, int *comp_unit) return(0); } -static void -print_word_at_address(int child, u64 address) -{ - long word = ptrace(PTRACE_PEEKDATA, child, address, NULL); - u8 nb[4]; - memcpy(nb, &word, 4); - printf("word at %#018lx: {%x %x %x %x}\n", address, nb[0], nb[1], nb[2], nb[3]); -} - static struct mi_buffer read_file_mmap(char *path) { @@ -254,25 +245,6 @@ process_create(char *path) return(result); } -static void -print_current_instruction(struct mi_process proc) -{ - struct mi_registers regs = get_process_registers(proc); - - long wordb = ptrace(PTRACE_PEEKDATA, proc.pid, regs.rip - 4, NULL); - long word = ptrace(PTRACE_PEEKDATA, proc.pid, regs.rip, NULL); - long worda = ptrace(PTRACE_PEEKDATA, proc.pid, regs.rip + 4, NULL); - - u8 nb[12]; - memcpy(nb, &wordb, 4); - memcpy(nb + 4, &word, 4); - memcpy(nb + 8, &worda, 4); - - printf("PC = %#018lx: %x %x %x %x [%x] %x %x %x %x %x %x %x\n", regs.rip, - nb[0], nb[1], nb[2], nb[3], nb[4], nb[5], nb[6], nb[7], - nb[8], nb[9], nb[10], nb[11]); -} - static struct mi_function * get_function_around_pc(struct mi_process proc, u64 pc) {