From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out-237.mta0.migadu.com (out-237.mta0.migadu.com [IPv6:2001:41d0:1004:224b::ed]) by sourceware.org (Postfix) with ESMTPS id 9CD393858C2D for ; Fri, 1 Sep 2023 21:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CD393858C2D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gpanders.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gpanders.com X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpanders.com; s=key1; t=1693602274; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oPySVUkbsITwMXVJJi/pnzknB2+OBGVEqCcdr2nerXw=; b=Fczl5+7mzbGS3QVWSBga3sXqFXdBRyutWThlDjUkACNT3WujLuzFCNTtsYqOBLdkS+IHsQ xnR4HwgDQBGnJ+zvNIqOAdbou4nDkmaQohwtYZhydmep60tSxgNf9I++LjMCa7Y0IGuY/b IaHc8jekT2iqI695uDmswv7htfL6S5UEF2Mp6tFfnqh3eIxVj4rrUXMi8+RZHXpbs+SpIr BTdvsoTTPCgKxJJZXBJFieAnP1DGd7esZ7WiHpOKms25i9b42X3YihfdBnk3ar+Lh3m742 Ye/LVmS0MMNY6AKMnVVG1bJwKSb1IbeIrGotP8E0N1JhdCL7ZSCQgvaTxKzJqg== From: Gregory Anders To: gdb-patches@sourceware.org Cc: Gregory Anders Subject: [PATCH v2 4/4] gdb/dap: only include sourceReference if file path does not exist Date: Fri, 1 Sep 2023 16:02:20 -0500 Message-ID: <20230901210422.58003-5-greg@gpanders.com> In-Reply-To: <20230901210422.58003-1-greg@gpanders.com> References: <20230901210422.58003-1-greg@gpanders.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP 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: According to the DAP specification if the "sourceReference" field is included in a Source object, then the DAP client _must_ make a "source" request to the debugger to retrieve file contents, even if the Source object also includes path information. If the Source's path field is a valid path that the DAP client is able to read from the filesystem, having to make another request to the debugger to get the file contents is wasteful and leads to incorrect results (DAP clients will try to get the contents from the server and display those contents as a file with the name in "source.path", but this will conflict with the _acutal_ existing file at "source.path"). Instead, only set "sourceReference" if the source file path does not exist. --- gdb/python/lib/gdb/dap/sources.py | 16 +++++++++++----- gdb/testsuite/gdb.dap/sources.exp | 9 +++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index 7fa1ae43..00a70701 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os + import gdb from .server import request, capability @@ -41,16 +43,20 @@ def make_source(fullname, filename): if fullname in _source_map: result = _source_map[fullname] else: - global _next_source result = { "name": filename, "path": fullname, - "sourceReference": _next_source, } + + if not os.path.exists(fullname): + global _next_source + result["sourceReference"] = _next_source + + global _id_map + _id_map[_next_source] = result + _next_source += 1 + _source_map[fullname] = result - global _id_map - _id_map[_next_source] = result - _next_source += 1 return result diff --git a/gdb/testsuite/gdb.dap/sources.exp b/gdb/testsuite/gdb.dap/sources.exp index a12c2089..f1b19acc 100644 --- a/gdb/testsuite/gdb.dap/sources.exp +++ b/gdb/testsuite/gdb.dap/sources.exp @@ -30,20 +30,21 @@ if {[dap_launch $testfile stop_at_main 1] == ""} { } set obj [dap_check_request_and_response loadedSources loadedSources] -set ref 0 +set path "" foreach src [dict get [lindex $obj 0] body sources] { if {[file tail [dict get $src name]] == "sources.c"} { - set ref [dict get $src sourceReference] + set path [dict get $src path] } } -if {$ref == 0} { +if {$path == ""} { fail "sources.c in loadedSources" } else { pass "sources.c in loadedSources" set obj [dap_check_request_and_response "get source" source \ - [format {o sourceReference [i %d]} $ref]] + [format {o source [o path [s %s]] \ + sourceReference [i 0]} $path]] set text [dict get [lindex $obj 0] body content] gdb_assert {[string first "Distinguishing comment" $text] != -1} } -- 2.42.0