From patchwork Mon Jul 3 13:59:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72012 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FF8B3858D28 for ; Mon, 3 Jul 2023 13:59:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FF8B3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688392774; bh=678D7uJF8pPqBaEa+XPf6snAHkuwPIVmkGRTkfXgNng=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=pv/fFd73jJqHLGk0YXZYpgr5+f72Ar0vZ2gn/Na1n+PJBIW+ZAREjtlyNWO+BuT3I DqPYBxrGpjdMslJI8IIzllEYluzrN753No0i6IF6/7qPho0gZgFvwqJCjQ4kYTzNE/ vKBFM/a+tT2lM5SPXJ5TVKuvuLsZdO3ittWuShZ0= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by sourceware.org (Postfix) with ESMTPS id 138593858D28 for ; Mon, 3 Jul 2023 13:59:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 138593858D28 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-77a62a84855so181398839f.1 for ; Mon, 03 Jul 2023 06:59:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688392750; x=1690984750; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=678D7uJF8pPqBaEa+XPf6snAHkuwPIVmkGRTkfXgNng=; b=jd+NrCZtkAQQ3A1frAhcpCIcWZY8muWEumu2YZBeE8ZnY8YM+/lYrAo2NF+UCNMsF6 yvc+713MM2e7ICfK1Gg6QAVRIvjyMcLHqGNJaJFfmeMJ2bOsF96VVAEdl+yl9ewnhkmb Cve2grwHDtRBBStb6hERjzrq6X+ck/+lfi1oy4qlbtJFP1PDp+v1Za5x8AOcFNvJd80v nMYrQmt3wJqle/Fujh0OBsWtVxWIWxeGplIHp7UIVjZFMF7xwO8+QEtMmS1ptSgDD3YZ A7o708p91kCep6qK05B4fjjeuUe9Cf4unXUHgLtOC5Ygg/QaHPRHgfbSvLZNBceJTpLk uU/g== X-Gm-Message-State: AC+VfDw/cidvkbz+InIAXNQdF96NNlTZBABoRF3yKyxTVlVDqBvSG9Rk 95eAIT8aXVZBBWaR29HKKcRB9LccqFisruQb5+BJQg== X-Google-Smtp-Source: ACHHUZ6E6786tStzLBSsZNjF61kMx39EE5OidtIJURVKPnEQLG5LdFv+9TM7tbLpTOipdg2z44ajRA== X-Received: by 2002:a5d:83c6:0:b0:783:47cd:27b5 with SMTP id u6-20020a5d83c6000000b0078347cd27b5mr10833521ior.3.1688392749898; Mon, 03 Jul 2023 06:59:09 -0700 (PDT) Received: from localhost.localdomain (71-211-136-248.hlrn.qwest.net. [71.211.136.248]) by smtp.gmail.com with ESMTPSA id t9-20020a028789000000b0041f4ce6e9cdsm6403698jai.65.2023.07.03.06.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 06:59:09 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add instruction bytes to DAP disassembly response Date: Mon, 3 Jul 2023 07:59:02 -0600 Message-Id: <20230703135902.2770290-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The DAP disassemble command lets the client return the underlying bytes of the instruction in an implementation-defined format. This patch updates gdb to return this, and simply uses a hex string of the bytes as the format. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 5 +++++ gdb/python/lib/gdb/dap/disassemble.py | 5 ++++- gdb/testsuite/gdb.dap/basic-dap.exp | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index b10c06ae91f..714f4bc1672 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -39087,6 +39087,11 @@ The target to which @value{GDBN} should connect. This is a string and is passed to the @code{target remote} command. @xref{Connecting}. @end table +In response to the @code{disassemble} request, DAP allows the client +to return the bytes of each instruction in an implementation-defined +format. @value{GDBN} implements this by sending a string with the +bytes encoded in hex, like @code{"55a2b900"}. + @node JIT Interface @chapter JIT Compilation Interface @cindex just-in-time compilation diff --git a/gdb/python/lib/gdb/dap/disassemble.py b/gdb/python/lib/gdb/dap/disassemble.py index bc091eb2c89..dda2f43b5a3 100644 --- a/gdb/python/lib/gdb/dap/disassemble.py +++ b/gdb/python/lib/gdb/dap/disassemble.py @@ -21,18 +21,21 @@ from .startup import send_gdb_with_response, in_gdb_thread @in_gdb_thread def _disassemble(pc, skip_insns, count): + inf = gdb.selected_inferior() try: arch = gdb.selected_frame().architecture() except gdb.error: # Maybe there was no frame. - arch = gdb.selected_inferior().architecture() + arch = inf.architecture() result = [] total_count = skip_insns + count for elt in arch.disassemble(pc, count=total_count)[skip_insns:]: + mem = inf.read_memory(elt["addr"], elt["length"]) result.append( { "address": hex(elt["addr"]), "instruction": elt["asm"], + "instructionBytes": mem.hex(), } ) return { diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index df9afcfcdfc..81c63a4ac09 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -191,6 +191,15 @@ set obj [dap_check_request_and_response "disassemble one instruction" \ $insn_pc]] set response [lindex $obj 0] gdb_assert { [dict exists $response body instructions] } "instructions in disassemble output" +foreach insn [dict get $response body instructions] { + gdb_assert {[dict exists $insn instructionBytes]} \ + "instruction bytes in disassemble output" + set bytes [dict get $insn instructionBytes] + gdb_assert {[string length $bytes] % 2 == 0} \ + "even number of digits" + gdb_assert {[regexp "^\[0-9A-Fa-f\]+\$" $bytes]} \ + "instructionBytes is hex" +} set obj [dap_check_request_and_response "command repl" \ evaluate {o expression [s {output 23}] context [s repl]}]