From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 94AB83858CD1 for ; Mon, 31 Jul 2023 17:48:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94AB83858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3a425ef874dso3638648b6e.0 for ; Mon, 31 Jul 2023 10:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1690825718; x=1691430518; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Xo3Dumfho9mntkccG4eNlbyMVmjvmBEz6UEqZSokHxw=; b=Zu0uUEJ/JmAod+nbBlWVCchtZLFEPHgCGoEpaTCOAOq0jq9x181OqscHKXcSdxFIXw Zu60Fm0nBITOPbdZyVf1V/f6+71OKimyw/RXsEMwaJA1+CHruIPps0RAonNuqFIFNhCX rBPvdXY5NEz9tJDPKlIDHpwRjO3b5mz8a0oGb4sdZU0qjxdip1GwenuF3ssCSZwp+/Xw CY8nbQZ2w0UBYjG07CTf/cCFyvJshasw5j1BfgZEcGGZDhIPya8gVnQO4CzO6lclcMhz rf89VNyCRVtlno4rvOIcdiaMKY6k0KXzpN/ifyRfQ0Jm7dZw7aAWice+Yq4B2XTuCfyN jegw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690825718; x=1691430518; 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=Xo3Dumfho9mntkccG4eNlbyMVmjvmBEz6UEqZSokHxw=; b=gINAe682e3h579GhKvAQy+pAzgX20ZNWvC6mnAZVP2ALWsyxEDMAWkYKneycIAjnt4 mQks3FDTmCMWiOGerADclam2Nyj0yOWfGKRE+alxD9vKO1LtO2d0qoug86+KI5VL3nPz akVlyB5lgWx/YLg/GZtrQUBzR2fkL7lDdAeH79hm7fhwo0U53Hhj57J791ABtAGwpiBp GfbtybJp8wMzEqlM6XUST68+4dtjsyFLajmOHhEsd8NaI1AAT5BNXCxKAPd22mGyAMdk rB4+vAxN1UsqMuuMZ/qqUbwe7wzP/AV/HqAH8uWQmGZSlQ1vRKV6N/o9aY3v0Zs60Ybj Fdyg== X-Gm-Message-State: ABy/qLbB16E0tyzyaDbRM7Imq6WvhxOKTN3GNeMH545LHns6ygk1mQmk gz1rpCRMXzY8h08/7yCG7nMKY0w4xOTcKUwMTbMuaQ== X-Google-Smtp-Source: APBJJlH2cHVdZ+3M/cvKf04zoDP/b7pPcUFgmOaCg4MGE6XEpJ/gmIxrc7R9U+MJz0hi67Pkwdx1kQ== X-Received: by 2002:a05:6358:52ce:b0:130:afe8:43de with SMTP id z14-20020a05635852ce00b00130afe843demr559508rwz.30.1690825716948; Mon, 31 Jul 2023 10:48:36 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id f5-20020a02b785000000b004302760aa6bsm3208829jam.4.2023.07.31.10.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 10:48:36 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2] Respect supportsMemoryReferences in DAP Date: Mon, 31 Jul 2023 11:48:26 -0600 Message-Id: <20230731174826.2733368-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: I noticed that the support for memoryReference in the "variables" output is gated on the client "supportsMemoryReferences" capability. This patch implements this and makes some other changes to the DAP memory reference code: * Remove the memoryReference special case from _SetResult. Upstream DAP fixed this oversight in response to https://github.com/microsoft/debug-adapter-protocol/issues/414 * Don't use the address of a variable as its memoryReference -- only emit this for pointer types. There's no spec support for the previous approach. * Use strip_typedefs to handle typedefs of pointers. --- gdb/python/lib/gdb/dap/evaluate.py | 7 ------- gdb/python/lib/gdb/dap/varref.py | 11 +++++++---- gdb/testsuite/gdb.dap/memory.c | 2 ++ gdb/testsuite/gdb.dap/memory.exp | 2 ++ gdb/testsuite/lib/dap-support.exp | 3 ++- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 63e80331b24..9fa94e08121 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -55,13 +55,6 @@ class _SetResult(VariableReference): def __init__(self, value): super().__init__(None, value, "value") - def to_object(self): - result = super().to_object() - # This is not specified in the setExpression result. - if "memoryReference" in result: - del result["memoryReference"] - return result - # Helper function to perform an assignment. @in_gdb_thread diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py index 213151fd3d3..0e0d92a8832 100644 --- a/gdb/python/lib/gdb/dap/varref.py +++ b/gdb/python/lib/gdb/dap/varref.py @@ -162,10 +162,13 @@ class VariableReference(BaseReference): result["indexedVariables"] = num_children else: result["namedVariables"] = num_children - if self.value.type.code == gdb.TYPE_CODE_PTR: - result["memoryReference"] = hex(int(self.value)) - elif self.value.address is not None: - result["memoryReference"] = hex(int(self.value.address)) + if client_bool_capability("supportsMemoryReferences"): + # https://github.com/microsoft/debug-adapter-protocol/issues/414 + # changed DAP to allow memory references for any of the + # variable response requests, and to lift the restriction + # to pointer-to-function from Variable. + if self.value.type.strip_typedefs().code == gdb.TYPE_CODE_PTR: + result["memoryReference"] = hex(int(self.value)) if client_bool_capability("supportsVariableType"): result["type"] = str(self.value.type) return result diff --git a/gdb/testsuite/gdb.dap/memory.c b/gdb/testsuite/gdb.dap/memory.c index 3b9f6138abe..630e23dcf01 100644 --- a/gdb/testsuite/gdb.dap/memory.c +++ b/gdb/testsuite/gdb.dap/memory.c @@ -19,6 +19,8 @@ uint32_t thirty_two = 7; +uint32_t *thirty_two_p = &thirty_two; + int main () { return 0; /* BREAK */ diff --git a/gdb/testsuite/gdb.dap/memory.exp b/gdb/testsuite/gdb.dap/memory.exp index ab0516d6b3d..d702d5b5dee 100644 --- a/gdb/testsuite/gdb.dap/memory.exp +++ b/gdb/testsuite/gdb.dap/memory.exp @@ -47,6 +47,8 @@ set obj [dap_check_request_and_response "evaluate global" \ evaluate {o expression [s thirty_two]}] dap_match_values "global value" [lindex $obj 0] "body result" 7 +set obj [dap_check_request_and_response "evaluate global pointer" \ + evaluate {o expression [s thirty_two_p]}] set addr [dict get [lindex $obj 0] body memoryReference] set obj [dap_check_request_and_response "read memory" \ diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index e3750e1d016..4183526a320 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -233,7 +233,8 @@ proc _dap_initialize {name} { return [dap_check_request_and_response $name initialize \ {o clientID [s "gdb testsuite"] \ supportsVariableType [l true] \ - supportsVariablePaging [l true]}] + supportsVariablePaging [l true] \ + supportsMemoryReferences [l true]}] } # Start gdb, send a DAP initialize request, and then a launch request -- 2.40.1