aboutsummaryrefslogtreecommitdiff
path: root/gdb/disasm.h
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-02-02 11:11:47 +0000
committerPedro Alves <palves@redhat.com>2017-02-02 11:11:47 +0000
commit8b172ce7c9435095d14e0bd98cd431bb9584e95e (patch)
treec590f1e822be6f4130bbffe8497eb55acea113d9 /gdb/disasm.h
parentd7e747318f4d04af033f16325f9b6d74f67079ec (diff)
downloadbinutils-8b172ce7c9435095d14e0bd98cd431bb9584e95e.zip
binutils-8b172ce7c9435095d14e0bd98cd431bb9584e95e.tar.gz
binutils-8b172ce7c9435095d14e0bd98cd431bb9584e95e.tar.bz2
Reuse buffers across gdb_pretty_print_insn calls
gdb_pretty_print_insn allocates and destroys a couple local buffers each time it is called, which can be many times when disassembling a region of memory. Avoid that overhead by adding a new class that holds the buffers and making gdb_pretty_print_insn a method of that class, so that the buffers can be reused across calls. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * disasm.c (gdb_pretty_print_insn): Rename to ... (gdb_pretty_print_disassembler::pretty_print_insn): ... this. Remove gdbarch parameter. Adapt to clear the object's buffers instead of allocating new buffers, and to print using the object's gdb_disassembler instead of calling gdb_print_insn. (dump_insns): Use gdb_pretty_print_disassembler. * disasm.h (gdb_pretty_print_insn): Delete declaration. (gdb_pretty_print_disassembler): New class. * record-btrace.c (btrace_insn_history): Use gdb_pretty_print_disassembler.
Diffstat (limited to 'gdb/disasm.h')
-rw-r--r--gdb/disasm.h31
1 files changed, 27 insertions, 4 deletions
diff --git a/gdb/disasm.h b/gdb/disasm.h
index dcc01e1..385cae6 100644
--- a/gdb/disasm.h
+++ b/gdb/disasm.h
@@ -97,11 +97,34 @@ extern void gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
extern int gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
struct ui_file *stream, int *branch_delay_insns);
-/* Prints the instruction INSN into UIOUT and returns the length of
- the printed instruction in bytes. */
+/* Class used to pretty-print an instruction. */
-extern int gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
- const struct disasm_insn *insn, int flags);
+class gdb_pretty_print_disassembler
+{
+public:
+ explicit gdb_pretty_print_disassembler (struct gdbarch *gdbarch)
+ : m_di (gdbarch, &m_insn_stb)
+ {}
+
+ /* 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);
+
+private:
+ /* Returns the architecture used for disassembling. */
+ struct gdbarch *arch () { return m_di.arch (); }
+
+ /* The disassembler used for instruction printing. */
+ gdb_disassembler m_di;
+
+ /* The buffer used to build the instruction string. The
+ disassembler is initialized with this stream. */
+ string_file m_insn_stb;
+
+ /* The buffer used to build the raw opcodes string. */
+ string_file m_opcode_stb;
+};
/* Return the length in bytes of the instruction at address MEMADDR in
debugged memory. */