From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 58E263858C27 for ; Fri, 28 Jul 2023 17:09:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58E263858C27 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-io1-xd2e.google.com with SMTP id ca18e2360f4ac-783549ef058so99017839f.2 for ; Fri, 28 Jul 2023 10:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1690564159; x=1691168959; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=AhROQ4urWCTVOYBJWmUPq3bWFXrFBcBAMoObU7VRGqc=; b=fl0BaIoXtRFnkpwNv+ptuqmRcxNi53Ki4iAOvq1EvDw/EUfi4xO+/6wSIIZCXgd+yx r5BsO8HGtLAlF8+3nnRtiK/Lbs4z9BjpC8J0KoR6eA11kLeUStYqJ5l4B2tGBWg+AIYS hR34S2xNotvskIb5YmmXNrVo2rkMmtkrN2E93F24KljrHHjnqYJVe0HlAsazrxO02uAN ZTwVWcupeSPz8b/H8ekTmh6qoIjjcZoLQZ6TcHwaoI1yE+lJl5X1XTYxfPPdBARixTPq 2JZutYiZjqGkJ29NItNNfgnbMID5IJUEtR7CqTW0eFGWVGbqafWeABzcXDrIEn1Nastj Qy6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690564159; x=1691168959; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AhROQ4urWCTVOYBJWmUPq3bWFXrFBcBAMoObU7VRGqc=; b=UBObVBd7H4qpYwRuy+EK+s5rl/CHYqDtw4Ogc/0q/6Rgw/xRZaKqHZRuXWHqtuK6la ib6pqbFr2Rfh6RuARof2pL5coB1Fhr7y9tD7y75CirrZfAWN+J4e+ulu3LiHiSkuWMf2 a7Odtuw5Ubw4a9B1znO8UUeqxTQ0QEG6tyKBAHyQFet8XxXlmMHD/0/A7p9jJOOJ2NW0 UkSPo+TyA4w0tlj/bZA/T8RNKIz06U2EAskyoxhRV8rZmyES4ux2cPZ9DHqf9WKDmSZE F0FtF3ja9RVQjAiXcXSLPHmkFslSJNDTrqyPVCQhhwcpxc3VQJp+ZxMxp/JXj5jqi+zK BKAg== X-Gm-Message-State: ABy/qLapBSHste4brb9HCIl2Y8vrUwJZFW49E5iHHTZKjituitHAqywO 6q+axFfJ0MFkOm7Pa/D6aSSdYbA8JWQQT3rUlAOr9Q== X-Google-Smtp-Source: APBJJlEPu+YexuhjYmWzhTP52u0ebwVZEEvMJ1pgW4U/Y5vQV+EzzQzdBB+uq8s26v/TOtfC4Ua0DA== X-Received: by 2002:a6b:780d:0:b0:783:550e:33c0 with SMTP id j13-20020a6b780d000000b00783550e33c0mr168427iom.7.1690564159588; Fri, 28 Jul 2023 10:09:19 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id k17-20020a5e8911000000b0077e3566a801sm1279269ioj.29.2023.07.28.10.09.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 10:09:19 -0700 (PDT) From: Tom Tromey Date: Fri, 28 Jul 2023 11:09:17 -0600 Subject: [PATCH 3/3] Implement DAP "source" request MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230728-dap-source-refs-v1-3-1bcc5cdffd44@adacore.com> References: <20230728-dap-source-refs-v1-0-1bcc5cdffd44@adacore.com> In-Reply-To: <20230728-dap-source-refs-v1-0-1bcc5cdffd44@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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: This implements the DAP "source" request. I renamed the "loadedSources" function from "sources" to "loaded_sources" to avoid any confusion. I also moved the loadedSources test to the new sources.exp. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30691 --- gdb/python/lib/gdb/dap/sources.py | 24 ++++++++++++++++- gdb/testsuite/gdb.dap/basic-dap.exp | 3 --- gdb/testsuite/gdb.dap/sources.c | 22 ++++++++++++++++ gdb/testsuite/gdb.dap/sources.exp | 52 +++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index 806352836db..7fa1ae430c8 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -82,5 +82,27 @@ def _sources(): @request("loadedSources") @capability("supportsLoadedSourcesRequest") -def sources(**extra): +def loaded_sources(**extra): return send_gdb_with_response(_sources) + + +# This helper is needed because we must only access the globals here +# from the gdb thread. +@in_gdb_thread +def _get_source(source): + filename = decode_source(source) + with open(filename) as f: + content = f.read() + return { + "content": content, + } + + +@request("source") +def source(*, source=None, sourceReference: int, **extra): + # The 'sourceReference' parameter is required by the spec, but is + # for backward compatibility, which I take to mean that the + # 'source' is preferred. + if source is None: + source = {"sourceReference": sourceReference} + return send_gdb_with_response(lambda: _get_source(source)) diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index ef3c535f6a2..b0f8e624610 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -206,7 +206,4 @@ set obj [dap_check_request_and_response "command repl" \ set response [lindex $obj 0] gdb_assert {[dict get $response body result] == 23} -set obj [dap_check_request_and_response sources loadedSources] -gdb_assert {[string first basic-dap.c $obj] != -1} - dap_shutdown diff --git a/gdb/testsuite/gdb.dap/sources.c b/gdb/testsuite/gdb.dap/sources.c new file mode 100644 index 00000000000..599d1bd9f77 --- /dev/null +++ b/gdb/testsuite/gdb.dap/sources.c @@ -0,0 +1,22 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + /* Distinguishing comment. */ +} diff --git a/gdb/testsuite/gdb.dap/sources.exp b/gdb/testsuite/gdb.dap/sources.exp new file mode 100644 index 00000000000..8983b4d94e6 --- /dev/null +++ b/gdb/testsuite/gdb.dap/sources.exp @@ -0,0 +1,52 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test 'sources' and 'loadedSources'. + +require allow_dap_tests + +load_lib dap-support.exp + +standard_testfile + +if {[build_executable ${testfile}.exp $testfile] == -1} { + return +} + +if {[dap_launch $testfile {} {} 1] == ""} { + return +} + +set obj [dap_check_request_and_response loadedSources loadedSources] +set ref 0 +foreach src [dict get [lindex $obj 0] body sources] { + if {[file tail [dict get $src name]] == "sources.c"} { + set ref [dict get $src sourceReference] + } +} + +if {$ref == 0} { + 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]] + set text [dict get [lindex $obj 0] body content] + gdb_assert {[string first "Distinguishing comment" $text] != -1} +} + + +dap_shutdown -- 2.40.1