From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E2E283858025 for ; Thu, 23 Jun 2022 16:05:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2E283858025 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-h6upH0aTOB-m40HWlrbkrw-1; Thu, 23 Jun 2022 12:05:30 -0400 X-MC-Unique: h6upH0aTOB-m40HWlrbkrw-1 Received: by mail-wm1-f72.google.com with SMTP id r65-20020a1c4444000000b003a02a3f0beeso47248wma.3 for ; Thu, 23 Jun 2022 09:05:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QMXAYDcXiIulFND3jVBP5aG1b/nvIiS7hPcnx5Mi8yY=; b=uGzGgnTM6vDb+BO7n5/Y8NDcpFVKe1cBMwf4v3pOzLPGaqC90XtThteBqSIzDoldzp bgiWMV2Ai+fHB387pp3olISvNwbaxq8RdUj9XKLg3bMMA2hdouNY9SADRaoJ5RokdyAm IlFVooPCzs8dcgKm6UjskFKaBlYeEQ2zJRtUUyV+0ckQY9e2HJyMnS/eejyhJL3Jj7As xuwZG8sklKqs5sUXAAHMQ85xapok35zq9rGJuHauiCAulzuuBEl+gm1T5tmUG5QjpUOw fAExuO444VOni3kiJWWSNW20tJ+OkPWcgK3nr0hH+jgL+pA2MmQwWIVAbbnKMOFwjzAo bh6Q== X-Gm-Message-State: AJIora87J5ULHNXHoOoRWclg1W/AtuQuKbRQZ498ZGapJKhGW/Ke5T6+ c8U3yFcQqNA0LTyFlSyvkRKgps3/bckSYyfwCEUyUILD/rCoe5+VATq9RSM3JSgstMKOlPnG7kV Ei+qmW92utJuC2ItDoRVIAiYoFKse0LL/aT3RJqazvCtS464+F8ZzhxANpaVqUHA3j3ER/Mho0Q == X-Received: by 2002:adf:ec02:0:b0:21b:931c:cf78 with SMTP id x2-20020adfec02000000b0021b931ccf78mr8695410wrn.188.1656000328060; Thu, 23 Jun 2022 09:05:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uan5emKZ/mUBxgkcEemBpdiYwuNVfPP6kqJmaAEINuiSf9Wd52TMZXZe+pTfExpAbV/CZMqg== X-Received: by 2002:adf:ec02:0:b0:21b:931c:cf78 with SMTP id x2-20020adfec02000000b0021b931ccf78mr8695370wrn.188.1656000327726; Thu, 23 Jun 2022 09:05:27 -0700 (PDT) Received: from localhost ([195.213.152.79]) by smtp.gmail.com with ESMTPSA id p13-20020a05600c1d8d00b0039c5645c60fsm10202311wms.3.2022.06.23.09.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 09:05:27 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/9] gdb/disasm: read opcodes bytes with a single read_code call Date: Thu, 23 Jun 2022 17:05:10 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2022 16:05:33 -0000 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. --- 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 c6edc92930d..42351c735d3 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -323,21 +323,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 da03e130526..13403042709 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -311,6 +311,9 @@ class gdb_pretty_print_disassembler /* 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 -- 2.25.4