diff options
author | Pedro Alves <palves@redhat.com> | 2010-05-06 00:21:53 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2010-05-06 00:21:53 +0000 |
commit | eda5a4d72028db748b14d3995f49d6c8b609e9b1 (patch) | |
tree | 636dc0361832fa3fb27e1fb53680caa8012d15e1 /gdb/disasm.c | |
parent | 02357a4aafd655e14222cdfa5e1c316bd1bbb092 (diff) | |
download | gdb-eda5a4d72028db748b14d3995f49d6c8b609e9b1.zip gdb-eda5a4d72028db748b14d3995f49d6c8b609e9b1.tar.gz gdb-eda5a4d72028db748b14d3995f49d6c8b609e9b1.tar.bz2 |
* amd64-tdep.c: Include disasm.h.
(amd64_insn_length_fprintf, amd64_insn_length_init_dis)
(amd64_insn_length): Moved to disasm.c and renamed.
(fixup_riprel): Adjust.
* disasm.c (do_ui_file_delete): New.
(gdb_insn_length): New.
(gdb_buffered_insn_length_fprintf)
(gdb_buffered_insn_length_init_dis)
(gdb_buffered_insn_length): New, moved from amd64-tdep.c, and
renamed.
* disasm.h (gdb_insn_length): Declare.
(gdb_buffered_insn_length): Declare.
Diffstat (limited to 'gdb/disasm.c')
-rw-r--r-- | gdb/disasm.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/gdb/disasm.c b/gdb/disasm.c index 0e43b0f..a3fe89a 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -429,3 +429,76 @@ gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr, } return length; } + +static void +do_ui_file_delete (void *arg) +{ + ui_file_delete (arg); +} + +/* Return the length in bytes of the instruction at address MEMADDR in + debugged memory. */ + +int +gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr) +{ + static struct ui_file *null_stream = NULL; + + /* Dummy file descriptor for the disassembler. */ + if (!null_stream) + { + null_stream = ui_file_new (); + make_final_cleanup (do_ui_file_delete, null_stream); + } + + return gdb_print_insn (gdbarch, addr, null_stream, NULL); +} + +/* fprintf-function for gdb_buffered_insn_length. This function is a + nop, we don't want to print anything, we just want to compute the + length of the insn. */ + +static int ATTRIBUTE_PRINTF (2, 3) +gdb_buffered_insn_length_fprintf (void *stream, const char *format, ...) +{ + return 0; +} + +/* Initialize a struct disassemble_info for gdb_buffered_insn_length. */ + +static void +gdb_buffered_insn_length_init_dis (struct gdbarch *gdbarch, + struct disassemble_info *di, + const gdb_byte *insn, int max_len, + CORE_ADDR addr) +{ + init_disassemble_info (di, NULL, gdb_buffered_insn_length_fprintf); + + /* init_disassemble_info installs buffer_read_memory, etc. + so we don't need to do that here. + The cast is necessary until disassemble_info is const-ified. */ + di->buffer = (gdb_byte *) insn; + di->buffer_length = max_len; + di->buffer_vma = addr; + + di->arch = gdbarch_bfd_arch_info (gdbarch)->arch; + di->mach = gdbarch_bfd_arch_info (gdbarch)->mach; + di->endian = gdbarch_byte_order (gdbarch); + di->endian_code = gdbarch_byte_order_for_code (gdbarch); + + disassemble_init_for_target (di); +} + +/* Return the length in bytes of INSN. MAX_LEN is the size of the + buffer containing INSN. */ + +int +gdb_buffered_insn_length (struct gdbarch *gdbarch, + const gdb_byte *insn, int max_len, CORE_ADDR addr) +{ + struct disassemble_info di; + + gdb_buffered_insn_length_init_dis (gdbarch, &di, insn, max_len, addr); + + return gdbarch_print_insn (gdbarch, addr, &di); +} |