From e47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Thu, 26 Jan 2017 14:29:19 +0000 Subject: Refactor disassembly code This patch addes class gdb_disassembler, and refactor code to use it. The gdb_disassembler object is saved in disassember_info.application_data. However, disassember_info.application_data is already used by gdb for arm, mips spu, and scm-disasm. In arm and mips, .application_data is gdbarch, but we can still get gdbarch from gdb_disassember. The use of application_data in spu is a little bit complicated. It creates its own disassemble_info, and save spu_dis_asm_data in .application_data. This will overwrite the pointer to gdb_disassembler, so we need to find another place to save spu_dis_asm_data. I extend disassemble_info, and put "id" there. gdb: 2017-01-26 Pedro Alves Yao Qi * arm-tdep.c: Include "disasm.h". (gdb_print_insn_arm): Update code to get gdbarch. * disasm.c (dis_asm_read_memory): Change it to gdb_disassembler::dis_asm_read_memory. (dis_asm_memory_error): Likewise. (dis_asm_print_address): Likewise. (gdb_pretty_print_insn): Change it to gdb_disassembler::pretty_print_insn. (dump_insns): Add one argument gdb_disassemlber. All callers updated. (do_mixed_source_and_assembly_deprecated): Likewise. (do_mixed_source_and_assembly): Likewise. (do_assembly_only): Likewise. (gdb_disassembler::gdb_disassembler): New. (gdb_disassembler::print_insn): New. * disasm.h (class gdb_disassembler): New. (gdb_pretty_print_insn): Remove declaration. (gdb_disassemble_info): Likewise. * guile/scm-disasm.c (class gdbscm_disassembler): New. (gdbscm_disasm_read_memory_worker): Update. (gdbscm_disasm_read_memory): Update. (gdbscm_disasm_memory_error): Remove. (gdbscm_disasm_print_address): Remove. (gdbscm_disassembler::gdbscm_disassembler): New. (gdbscm_print_insn_from_port): Update. * mips-tdep.c: Include disasm.h. (gdb_print_insn_mips): Update code to get gdbarch. * record-btrace.c (btrace_insn_history): Update. * spu-tdep.c: Include disasm.h. (struct spu_dis_asm_data): Remove. (struct spu_dis_asm_info): New. (spu_dis_asm_print_address): Use spu_dis_asm_info to get SPU id. (gdb_print_insn_spu): Cast disassemble_info to spu_dis_asm_info. --- gdb/spu-tdep.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'gdb/spu-tdep.c') diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c index 8756256..70d7f6f 100644 --- a/gdb/spu-tdep.c +++ b/gdb/spu-tdep.c @@ -33,6 +33,7 @@ #include "value.h" #include "inferior.h" #include "dis-asm.h" +#include "disasm.h" #include "objfiles.h" #include "language.h" #include "regcache.h" @@ -1693,18 +1694,19 @@ spu_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) /* Disassembler. */ -struct spu_dis_asm_data +struct spu_dis_asm_info : disassemble_info { - struct gdbarch *gdbarch; int id; }; static void spu_dis_asm_print_address (bfd_vma addr, struct disassemble_info *info) { - struct spu_dis_asm_data *data - = (struct spu_dis_asm_data *) info->application_data; - print_address (data->gdbarch, SPUADDR (data->id, addr), + struct spu_dis_asm_info *data = (struct spu_dis_asm_info *) info; + gdb_disassembler *di + = static_cast(info->application_data); + + print_address (di->arch (), SPUADDR (data->id, addr), (struct ui_file *) info->stream); } @@ -1714,12 +1716,10 @@ gdb_print_insn_spu (bfd_vma memaddr, struct disassemble_info *info) /* The opcodes disassembler does 18-bit address arithmetic. Make sure the SPU ID encoded in the high bits is added back when we call print_address. */ - struct disassemble_info spu_info = *info; - struct spu_dis_asm_data data; - data.gdbarch = (struct gdbarch *) info->application_data; - data.id = SPUADDR_SPU (memaddr); + struct spu_dis_asm_info spu_info; - spu_info.application_data = &data; + memcpy (&spu_info, info, sizeof (*info)); + spu_info.id = SPUADDR_SPU (memaddr); spu_info.print_address_func = spu_dis_asm_print_address; return print_insn_spu (memaddr, &spu_info); } -- cgit v1.1