Browse Source

Do not iterate instructions when we only need to know the length (just add the length, duh!)

master
aolo2 3 years ago
parent
commit
e1fe877ddd
  1. 1
      command.c
  2. 3
      dwarf.c
  3. 6
      eh_frame.c
  4. 28
      util.c

1
command.c

@ -26,7 +26,6 @@ command_step(struct mi_process proc)
ptrace(PTRACE_SINGLESTEP, proc.pid, 0, 0); ptrace(PTRACE_SINGLESTEP, proc.pid, 0, 0);
waitpid(proc.pid, 0, 0); waitpid(proc.pid, 0, 0);
regs = get_process_registers(proc); 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); next_sp = pc_to_sourcepoint(proc, regs.rip - proc.base_address, &comp_unit);
if (!next_sp) break; if (!next_sp) break;
} while (next_sp->line == sp->line); } while (next_sp->line == sp->line);

3
dwarf.c

@ -8,7 +8,6 @@ get_section_entry(u8 *file, char *name)
struct elf_header_table_entry_x64 header_entry = { 0 }; struct elf_header_table_entry_x64 header_entry = { 0 };
u64 offset = header.header_table_offset + header.header_table_entry_size * i; u64 offset = header.header_table_offset + header.header_table_entry_size * i;
memcpy(&header_entry, file + offset, sizeof(header_entry)); memcpy(&header_entry, file + offset, sizeof(header_entry));
int a = 1;
} }
struct elf_section_table_entry_x64 shstrtab_header = { 0 }; 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); offset += decode_leb128(file + abbrev_offset + offset, &tag);
u32 has_children = file[abbrev_offset + offset++]; u32 has_children = file[abbrev_offset + offset++];
(void) has_children;
if (code == requested_code) { if (code == requested_code) {
return(abbrev_offset); return(abbrev_offset);
} }

6
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->length = length;
header->version = *data++; header->version = *data++;
char *augmenation_string = (char *) data;
// NOTE: null-terminated string // NOTE: null-terminated string
int has_z = 0; int has_z = 0;
int has_L = 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 = data;
header->instructions_length = header->length - (data - original_data - 4); 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) { if (has_R) {
// NOTE(aolo2): this shit is undocumented. Best sources I could find: // 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 = data;
header->instructions_length = header->length - (data - original_data - 4); 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); return(data - original_data);
} }

28
util.c

@ -127,15 +127,6 @@ pc_to_sourcepoint(struct mi_process proc, u64 pc, int *comp_unit)
return(0); 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 static struct mi_buffer
read_file_mmap(char *path) read_file_mmap(char *path)
{ {
@ -254,25 +245,6 @@ process_create(char *path)
return(result); 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 * static struct mi_function *
get_function_around_pc(struct mi_process proc, u64 pc) get_function_around_pc(struct mi_process proc, u64 pc)
{ {

Loading…
Cancel
Save