public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/disasm: read opcodes bytes with a single read_code call Date: Sun, 2 Oct 2022 13:15:03 +0000 (GMT) [thread overview] Message-ID: <20221002131503.050493858D32@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d309a8f9b34d8fd570dc8c7189eb6790b9afd4e3 commit d309a8f9b34d8fd570dc8c7189eb6790b9afd4e3 Author: Andrew Burgess <aburgess@redhat.com> Date: Thu Jun 23 11:49:08 2022 +0100 gdb/disasm: read opcodes bytes with a single read_code call This commit reduces the number of times we call read_code when printing the instruction opcode bytes during disassembly. I've added a new gdb::byte_vector within the gdb_pretty_print_disassembler class, in line with all the other buffers that gdb_pretty_print_disassembler needs. This byte_vector is then resized as needed, and filled with a single read_code call for each instruction. There should be no user visible changes after this commit. Diff: --- gdb/disasm.c | 16 +++++++--------- gdb/disasm.h | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gdb/disasm.c b/gdb/disasm.c index 989120e05b1..ba6ac2d4827 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -459,21 +459,19 @@ gdb_pretty_print_disassembler::pretty_print_insn (const struct disasm_insn *insn if (flags & DISASSEMBLY_RAW_INSN) { - CORE_ADDR end_pc; - bfd_byte data; - const char *spacer = ""; - /* Build the opcodes using a temporary stream so we can write them out in a single go for the MI. */ m_opcode_stb.clear (); - end_pc = pc + size; + /* Read the instruction opcode data. */ + m_opcode_data.resize (size); + read_code (pc, m_opcode_data.data (), size); - for (;pc < end_pc; ++pc) + for (int i = 0; i < size; ++i) { - read_code (pc, &data, 1); - m_opcode_stb.printf ("%s%02x", spacer, (unsigned) data); - spacer = " "; + if (i > 0) + m_opcode_stb.puts (" "); + m_opcode_stb.printf ("%02x", (unsigned) m_opcode_data[i]); } m_uiout->field_stream ("opcodes", m_opcode_stb); diff --git a/gdb/disasm.h b/gdb/disasm.h index 09cb3921767..dab6116cd00 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -344,6 +344,9 @@ private: /* The buffer used to build the raw opcodes string. */ string_file m_opcode_stb; + + /* The buffer used to hold the opcode bytes (if required). */ + gdb::byte_vector m_opcode_data; }; /* Return the length in bytes of the instruction at address MEMADDR in
reply other threads:[~2022-10-02 13:15 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221002131503.050493858D32@sourceware.org \ --to=aburgess@sourceware.org \ --cc=gdb-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).