diff options
author | Yao Qi <yao.qi@linaro.org> | 2017-01-26 14:29:19 +0000 |
---|---|---|
committer | Yao Qi <yao.qi@linaro.org> | 2017-01-26 14:29:19 +0000 |
commit | e47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed (patch) | |
tree | 4b8aaa68f2fe8da7c061d4d5b46c2e2b0bb74142 /gdb/guile | |
parent | 80d758749a7a679288e6e72b2e849b814413b719 (diff) | |
download | gdb-e47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed.zip gdb-e47ad6c0bd7aa388b1bd488f6ef522c20c0b94ed.tar.gz 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/guile')
-rw-r--r-- | gdb/guile/scm-disasm.c | 77 |
1 files changed, 20 insertions, 57 deletions
diff --git a/gdb/guile/scm-disasm.c b/gdb/guile/scm-disasm.c index d06c481..25cae5a 100644 --- a/gdb/guile/scm-disasm.c +++ b/gdb/guile/scm-disasm.c @@ -37,11 +37,13 @@ static SCM address_symbol; static SCM asm_symbol; static SCM length_symbol; -/* Struct used to pass "application data" in disassemble_info. */ - -struct gdbscm_disasm_data +class gdbscm_disassembler : public gdb_disassembler { - struct gdbarch *gdbarch; +public: + gdbscm_disassembler (struct gdbarch *gdbarch, + struct ui_file *stream, + SCM port, ULONGEST offset); + SCM port; /* The offset of the address of the first instruction in PORT. */ ULONGEST offset; @@ -55,7 +57,7 @@ struct gdbscm_disasm_read_data bfd_vma memaddr; bfd_byte *myaddr; unsigned int length; - struct disassemble_info *dinfo; + gdbscm_disassembler *dinfo; }; /* Subroutine of gdbscm_arch_disassemble to simplify it. @@ -81,13 +83,11 @@ gdbscm_disasm_read_memory_worker (void *datap) { struct gdbscm_disasm_read_data *data = (struct gdbscm_disasm_read_data *) datap; - struct disassemble_info *dinfo = data->dinfo; - struct gdbscm_disasm_data *disasm_data - = (struct gdbscm_disasm_data *) dinfo->application_data; - SCM seekto, newpos, port = disasm_data->port; + gdbscm_disassembler *dinfo = data->dinfo; + SCM seekto, newpos, port = dinfo->port; size_t bytes_read; - seekto = gdbscm_scm_from_ulongest (data->memaddr - disasm_data->offset); + seekto = gdbscm_scm_from_ulongest (data->memaddr - dinfo->offset); newpos = scm_seek (port, seekto, scm_from_int (SEEK_SET)); if (!scm_is_eq (seekto, newpos)) return "seek error"; @@ -108,13 +108,15 @@ gdbscm_disasm_read_memory (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *dinfo) { + gdbscm_disassembler *self + = static_cast<gdbscm_disassembler *> (dinfo->application_data); struct gdbscm_disasm_read_data data; const char *status; data.memaddr = memaddr; data.myaddr = myaddr; data.length = length; - data.dinfo = dinfo; + data.dinfo = self; status = gdbscm_with_guile (gdbscm_disasm_read_memory_worker, &data); @@ -123,30 +125,12 @@ gdbscm_disasm_read_memory (bfd_vma memaddr, bfd_byte *myaddr, return status != NULL ? -1 : 0; } -/* disassemble_info.memory_error_func for gdbscm_print_insn_from_port. - Technically speaking, we don't need our own memory_error_func, - but to not provide one would leave a subtle dependency in the code. - This function exists to keep a clear boundary. */ - -static void -gdbscm_disasm_memory_error (int status, bfd_vma memaddr, - struct disassemble_info *info) -{ - memory_error (TARGET_XFER_E_IO, memaddr); -} - -/* disassemble_info.print_address_func for gdbscm_print_insn_from_port. - Since we need to use our own application_data value, we need to supply - this routine as well. */ - -static void -gdbscm_disasm_print_address (bfd_vma addr, struct disassemble_info *info) +gdbscm_disassembler::gdbscm_disassembler (struct gdbarch *gdbarch, + struct ui_file *stream, + SCM port_, ULONGEST offset_) + : gdb_disassembler (gdbarch, stream, gdbscm_disasm_read_memory), + port (port_), offset (offset_) { - struct gdbscm_disasm_data *data - = (struct gdbscm_disasm_data *) info->application_data; - struct gdbarch *gdbarch = data->gdbarch; - - print_address (gdbarch, addr, (struct ui_file *) info->stream); } /* Subroutine of gdbscm_arch_disassemble to simplify it. @@ -164,30 +148,9 @@ gdbscm_print_insn_from_port (struct gdbarch *gdbarch, SCM port, ULONGEST offset, CORE_ADDR memaddr, struct ui_file *stream, int *branch_delay_insns) { - struct disassemble_info di; - int length; - struct gdbscm_disasm_data data; - - di = gdb_disassemble_info (gdbarch, stream); - data.gdbarch = gdbarch; - data.port = port; - data.offset = offset; - di.application_data = &data; - di.read_memory_func = gdbscm_disasm_read_memory; - di.memory_error_func = gdbscm_disasm_memory_error; - di.print_address_func = gdbscm_disasm_print_address; - - length = gdbarch_print_insn (gdbarch, memaddr, &di); - - if (branch_delay_insns) - { - if (di.insn_info_valid) - *branch_delay_insns = di.branch_delay_insns; - else - *branch_delay_insns = 0; - } + gdbscm_disassembler di (gdbarch, stream, port, offset); - return length; + return di.print_insn (memaddr, branch_delay_insns); } /* (arch-disassemble <gdb:arch> address |