From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 050493858D32; Sun, 2 Oct 2022 13:15:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 050493858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664716503; bh=NiTNtTNn2Q1Hblb6NQGaDxM2BQzMLh9L2u5MhSZpJHg=; h=From:To:Subject:Date:From; b=mfBYiu9ku1qHlp2/1uTf9ZiJq46pRu8wKaKN+BugZhax6/6Zf3X+tdteeXecsMt2p DLkZ5nF7mdAvoayE/rMG1DuBhQeWwsEvhLiqaCqRZc+w9pVlSDcwvs4QE01Fg7DMcc jf3/S6aLNw4FBd7YIAnx8kxGiR+ajAq48637W/E0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/disasm: read opcodes bytes with a single read_code call X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 21a52f7d827dab6bf14f81f478e1f9c7bdc7f218 X-Git-Newrev: d309a8f9b34d8fd570dc8c7189eb6790b9afd4e3 Message-Id: <20221002131503.050493858D32@sourceware.org> Date: Sun, 2 Oct 2022 13:15:03 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd309a8f9b34d= 8fd570dc8c7189eb6790b9afd4e3 commit d309a8f9b34d8fd570dc8c7189eb6790b9afd4e3 Author: Andrew Burgess Date: Thu Jun 23 11:49:08 2022 +0100 gdb/disasm: read opcodes bytes with a single read_code call =20 This commit reduces the number of times we call read_code when printing the instruction opcode bytes during disassembly. =20 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. =20 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 (con= st struct disasm_insn *insn =20 if (flags & DISASSEMBLY_RAW_INSN) { - CORE_ADDR end_pc; - bfd_byte data; - const char *spacer =3D ""; - /* Build the opcodes using a temporary stream so we can write them out in a single go for the MI. */ m_opcode_stb.clear (); =20 - end_pc =3D pc + size; + /* Read the instruction opcode data. */ + m_opcode_data.resize (size); + read_code (pc, m_opcode_data.data (), size); =20 - for (;pc < end_pc; ++pc) + for (int i =3D 0; i < size; ++i) { - read_code (pc, &data, 1); - m_opcode_stb.printf ("%s%02x", spacer, (unsigned) data); - spacer =3D " "; + if (i > 0) + m_opcode_stb.puts (" "); + m_opcode_stb.printf ("%02x", (unsigned) m_opcode_data[i]); } =20 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: =20 /* 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; }; =20 /* Return the length in bytes of the instruction at address MEMADDR in