aboutsummaryrefslogtreecommitdiff
path: root/gdb/disasm.h
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-01-26 14:29:19 +0000
committerYao Qi <yao.qi@linaro.org>2017-01-26 14:29:19 +0000
commite47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed (patch)
tree4b8aaa68f2fe8da7c061d4d5b46c2e2b0bb74142 /gdb/disasm.h
parent80d758749a7a679288e6e72b2e849b814413b719 (diff)
downloadfsf-binutils-gdb-e47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed.zip
fsf-binutils-gdb-e47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed.tar.gz
fsf-binutils-gdb-e47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed.tar.bz2
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 <palves@redhat.com> Yao Qi <yao.qi@linaro.org> * 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.
Diffstat (limited to 'gdb/disasm.h')
-rw-r--r--gdb/disasm.h56
1 files changed, 43 insertions, 13 deletions
diff --git a/gdb/disasm.h b/gdb/disasm.h
index 4c6fd54..c6cb13b 100644
--- a/gdb/disasm.h
+++ b/gdb/disasm.h
@@ -33,6 +33,49 @@ struct gdbarch;
struct ui_out;
struct ui_file;
+class gdb_disassembler
+{
+ using di_read_memory_ftype = decltype (disassemble_info::read_memory_func);
+
+public:
+ gdb_disassembler (struct gdbarch *gdbarch, struct ui_file *file)
+ : gdb_disassembler (gdbarch, file, dis_asm_read_memory)
+ {}
+
+ int print_insn (CORE_ADDR memaddr, int *branch_delay_insns = NULL);
+
+ /* Prints the instruction INSN into UIOUT and returns the length of
+ the printed instruction in bytes. */
+ int pretty_print_insn (struct ui_out *uiout,
+ const struct disasm_insn *insn, int flags);
+
+ /* Return the gdbarch of gdb_disassembler. */
+ struct gdbarch *arch ()
+ { return m_gdbarch; }
+
+protected:
+ gdb_disassembler (struct gdbarch *gdbarch, struct ui_file *file,
+ di_read_memory_ftype func);
+
+ struct ui_file *stream ()
+ { return (struct ui_file *) m_di.stream; }
+
+private:
+ struct gdbarch *m_gdbarch;
+
+ /* Stores data required for disassembling instructions in
+ opcodes. */
+ struct disassemble_info m_di;
+
+ static int dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr,
+ unsigned int len,
+ struct disassemble_info *info);
+ static void dis_asm_memory_error (int err, bfd_vma memaddr,
+ struct disassemble_info *info);
+ static void dis_asm_print_address (bfd_vma addr,
+ struct disassemble_info *info);
+};
+
/* An instruction to be disassembled. */
struct disasm_insn
@@ -47,19 +90,6 @@ struct disasm_insn
unsigned int is_speculative:1;
};
-/* Prints the instruction INSN into UIOUT and returns the length of the
- printed instruction in bytes. */
-
-extern int gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
- struct disassemble_info * di,
- const struct disasm_insn *insn, int flags,
- struct ui_file *stb);
-
-/* Return a filled in disassemble_info object for use by gdb. */
-
-extern struct disassemble_info gdb_disassemble_info (struct gdbarch *gdbarch,
- struct ui_file *file);
-
extern void gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
char *file_string, int flags, int how_many,
CORE_ADDR low, CORE_ADDR high);