From patchwork Thu Nov 21 20:35:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 101697 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 5B7103857346 for ; Thu, 21 Nov 2024 20:37:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B7103857346 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=aJjdhhoH X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 229C93857C6E for ; Thu, 21 Nov 2024 20:35:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 229C93857C6E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 229C93857C6E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221321; cv=none; b=cLpQz9w7QFXMHgGuhxF2Fp0st6j0eZ5MnCBnIbiLIMSs4BkGkQcXTpUXG/7K42Z/osBFyNO8YWojpiS/zmTZllZUs68gyVu/qWT0Sk+M8xo0CFrWTwlA0NyFC2re/5NjP/cW5i9rthmNYftaTbyxDsKT4R83c0bj+MarwcPPRpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221321; c=relaxed/simple; bh=7eR8ZUtkb7H0rlz/aMC+CdaEmpXkcKLnY2WDggwegNo=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=a/HYRHn3rl8V29waqkddAX3kbQ1Cl9hoMnId/A3Mznv1xdhJgR8IqJ0OQVjId1voinjNVaUrFdAJq9Uf7LYG6hRIf3MwtZ6IBW5O6dbxqz4vIdsZyRlYlClJ/x9zmSQh3EhYNM9OS39ak4McuxkH5QMKF5sWJQrnXqYtNT9g/5Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 229C93857C6E Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3a75f77d859so5166905ab.3 for ; Thu, 21 Nov 2024 12:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1732221320; x=1732826120; darn=sourceware.org; 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=zV7KrBN36bsLGEUwJqcy3v8tD5bfPb6IRtof8wBLdxQ=; b=aJjdhhoHWf5WFZUBr5+YSX632B1UDFlPsc/3ukgSzxcV/dKsopqNs04kYVBpBhvrks o1DpY7KyQlsobVNXF8nSSya5TTE5V0smAqdozltNa8HRCsVnHo/7LE90MCTQtF4VXiwW b8H/QVFcRFK8PdkV17+Qxm8oYeVUH6AAblJ3wzc4kIlqBR9ejqasC39auMAVwwVONs3S tHn8e2tWfCLwpkY0RHEvKnWRXySJu/YJtoxouzypt0nlYFrukBAznf4ZO3G8ABt2Bqyf u8psqYMv4fT2VpztLPcPsICdK8sLlvkdjatiWgwHEa6dr/n2OM8Jup2MY4tH4LzVmbIH 3AJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732221320; x=1732826120; 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=zV7KrBN36bsLGEUwJqcy3v8tD5bfPb6IRtof8wBLdxQ=; b=or6UJgINjB93SxqDcoDilvorP5LeVKXI/lQC8GyFerLQT1cFoDe1xAPtV42F793kkw ohCH3nPacqGNygNM+V3bAQBKb/5gWdezdtoa4bdNX5blfP+CrEhDVWQCSPhhVPrSbvYe tnCapcIrWITl67C8GMZ/1PXqbz4GPpf9KevaEblCvK0cxZyHb0sW2FbMaER3oRy4eW6D PtpTFVl+e2ANRI4yxyQLC1eTrKd4ZClCkS9XtQypYD01ZZqNqWWdSL38Xe0OAq8ovISU ilAr94Fd8aVy2dTgctui+r7M9ao8stQRUiavLC/8pHh/grwPpliKcQmqHAp+ShbnlabI e+7g== X-Gm-Message-State: AOJu0YwTJQvN26gmpNCjCEK8zHSHN8BzxIiLa6o1SxNSsRIJspRTwkAJ 3zhHUMM275v6T64zQLB9kuytn03NMapIo9E71PQ1eroUsAaIly6t82D78a53T6yAeBrq0gNYLXI = X-Gm-Gg: ASbGnct4sETrqM0UaCOLwLMebTl2J98gt8Y/ZAoLndvuTH08Gp+ASdL1oVDbh37ibRv yDjkIeg0h2zNqpHMfeqEEDrLM9IZCMBDxjsmh9pEqEeGJVuq3RPWYqNThGScxgzX3x/+s0e8JG7 pgNY7Z/W/lLyUb23+9ygK+WDVHKo3lu/zJK3DMwuixDUuGo0Ldnjx9yWqZ60FIVHRwv4yOsU6Hv 55BXauUEdvSgzXOqZl1GtBVo2GcYgxyFFT/O5iqkbRxs1o7z2TJTP+Zp9dvdfGUP2IctczINMUr aiYTLxaJ6lCBeFpt X-Google-Smtp-Source: AGHT+IEenWP8l6lWdrFSggcRkmbzlE+HtB/cSBzndqnQKUR6/l7xGwuB8IAVjexs5Lz0vsErUZn8mQ== X-Received: by 2002:a05:6602:164c:b0:83a:a9cc:69ff with SMTP id ca18e2360f4ac-83ecdd2ff2cmr29732139f.13.1732221320433; Thu, 21 Nov 2024 12:35:20 -0800 (PST) Received: from localhost.localdomain (97-122-113-155.hlrn.qwest.net. [97.122.113.155]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ecd43fb95sm9263139f.51.2024.11.21.12.35.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 12:35:19 -0800 (PST) From: Tom Tromey Date: Thu, 21 Nov 2024 13:35:16 -0700 Subject: [PATCH 1/7] Reimplement DAP's stopAtBeginningOfMainSubprogram MIME-Version: 1.0 Message-Id: <20241121-dap-launch-v3-v1-1-c1fa046b3285@adacore.com> References: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> In-Reply-To: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.3 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 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org Right now, stopAtBeginningOfMainSubprogram is implemented "by hand", but then later the launch function uses "starti" to implement stopOnEntry. This patch unifies this code and rewrites it to use "start" when appropriate. --- gdb/python/lib/gdb/dap/launch.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 65444bf976a03ffe6d8ff0d927dd66adf63256d1..6444c8b7b6741c4847a6c12df78685afca37847a 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -53,17 +53,19 @@ def launch( if program is not None: file_command(program) inf = gdb.selected_inferior() - if stopAtBeginningOfMainSubprogram: - main = inf.main_name - if main is not None: - exec_and_log("tbreak " + main) inf.arguments = args if env is not None: inf.clear_env() for name, value in env.items(): inf.set_env(name, value) expect_process("process") - exec_and_expect_stop("starti" if stopOnEntry else "run") + if stopAtBeginningOfMainSubprogram: + cmd = "start" + elif stopOnEntry: + cmd = "starti" + else: + cmd = "run" + exec_and_expect_stop(cmd) @request("attach") From patchwork Thu Nov 21 20:35:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 101698 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 2E5523857350 for ; Thu, 21 Nov 2024 20:37:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E5523857350 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=j2itqXnq X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 6B64B3857B91 for ; Thu, 21 Nov 2024 20:35:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B64B3857B91 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6B64B3857B91 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221322; cv=none; b=kYYTHaQmN8zXIoDqVGPl4/tLEUWQvpLL+JCVZu+s5pcN9rhouAFTaYKGa4xukXkinQLcXhbTh1vLhmYATXt5d/i2FiCG/UZN0HaquvwizDpBbmqDStCTOvf2Hf3QWGg7xQPqEE/82eYqmu55Ac6f7JwJxJAsNLtNTZnZ3GlqcGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221322; c=relaxed/simple; bh=FoXNF1r3frxxoc7RZOMULgtERrwtxduH+Ijyi3Ml5Rs=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=KaHURvIKek+m+Z3bhuQIoO/f6ZLictty93AT7FR5bhlHDg9nHUXOMViOFryA2v/Pa6odxa+F4mhqS1OK5gZt2JRSgKy1pnHdLO5yd1dk07HpeTJQ3E6wd030TQH23buAS6yCkJREzlfEvff6vSmEQzHwwjFvbIzpMHfzlFMu/nk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B64B3857B91 Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-3a761a622dcso5014335ab.0 for ; Thu, 21 Nov 2024 12:35:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1732221321; x=1732826121; darn=sourceware.org; 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=19D3gk+bGadrY/ih7UgCQAhGrk8eQPRxWDbTFFu059U=; b=j2itqXnqn4Pbcix7xVV3/tlvbUfo874DKnRkwB7w5I8BiLv9bQjslQrv80++xiv2Kx r42tvT17hvDX/V6sx3bOiZIX907qXJEetYBB4IFzbH/lOshouH2A7F9izfWTpTApiJYj cppnYvvTOwsEHUuIb+qY0kY7rc1uhag7XKAHkn4vIjb0PFYlZ46ubVUIyhFl9u24vKIc gjKVCGEi/SlH+2jdkDVIS6BH0HidpGkKFTIKQcxNQUPsfnsTSqsWyfYqDJQ4hFm1swQ/ lW39dfzKh7Ahe+ngKkcTrTDA8SnXtI7vM/ZI5mhlhCM1Rw67u34b7MSgqKMXvw0EZWVy z3Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732221321; x=1732826121; 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=19D3gk+bGadrY/ih7UgCQAhGrk8eQPRxWDbTFFu059U=; b=L1MRReIGHs/twJL8CIlKGvv3va+RMMz4tYyHsyaSvDvY7ihFqU076wH8aXDyieSVzw FzzXnlTS9n+DAMDQe1yemKWBtONRbDsLWV8HipMENgcs/JREXt6P0R4J1ecA+fFSj7of SHYlutdHDNWTTNYuL16jQjxzG3BXTujZIT6dPobyTHdPKysdsRojSW/QoM34pEolmSNd EpmACkynf6/GuJ6scejkNjepgrNQGSajoJne/e0yigtdz0q0HRFDFwlTl3dHyGM4jbAW /jxpCe/MS6ZdAiwudQEj4tm6zwYaJrCYqZAawusipBnLN7+kqjvddLSIe+PK2sNl7fih 5fVg== X-Gm-Message-State: AOJu0Yy4ySbSHLc91xogOtDLM7Ns0gYNz+4T/3o0WRa+nd+FQB1RE3kA lYUl9mlycn4XNR7A/JlcC9ZRvacHILYiTaBqj4SIdb0Ryp+1XPMW8c7w0JpLsEczTH6go5eAFhg = X-Gm-Gg: ASbGncvBa3cV4RJT0nbEQa+OHlqQ1CMBNMEHq9wX7HhPzcvC/7TqsPugUQBETJCJ1ac 3RFIxRqc47UbB7ElogqvAhgHUe3L8A8qqXIHodlsrarXZKqd72g0QyjQM4DupSonrYZQfYRDXJE 7TBw9/PQtvPaXW8udNZnDszn7ikIp29hyIQA8hyBekyceyMc+jsfmDYiYGanLlSBJkhs3nTdhtv /Uyy3a5/RyyyBijUUPiBlTyLrA3PSVwNSmC+WhC0/FrjKjIzyXahj9rcsP1U8sGMiFkbNLScgDN UC5I47JXbnyf2mS/ X-Google-Smtp-Source: AGHT+IEiI/6wTXcABcLN7DKFWTT63eHpFMxCgyFupLKFavQuDOl35wOvQ+wUe3cOkC99kaHG659reg== X-Received: by 2002:a05:6602:1691:b0:837:7f69:eac2 with SMTP id ca18e2360f4ac-83ecdc5607dmr31218139f.1.1732221321672; Thu, 21 Nov 2024 12:35:21 -0800 (PST) Received: from localhost.localdomain (97-122-113-155.hlrn.qwest.net. [97.122.113.155]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ecd43fb95sm9263139f.51.2024.11.21.12.35.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 12:35:21 -0800 (PST) From: Tom Tromey Date: Thu, 21 Nov 2024 13:35:17 -0700 Subject: [PATCH 2/7] Reimplement DAP delayed events MIME-Version: 1.0 Message-Id: <20241121-dap-launch-v3-v1-2-c1fa046b3285@adacore.com> References: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> In-Reply-To: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.3 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 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This patch changes how delayed events are implemented in DAP. The new implementation makes it simpler to add a delayed function call, which will be needed by the final patch in this series. --- gdb/python/lib/gdb/dap/server.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 8c6d90822f301e9948a413592d75be65988af222..ceffefc81dc1c42d695008a0fe67454deab71ee5 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -124,9 +124,9 @@ class Server: self.in_stream = in_stream self.out_stream = out_stream self.child_stream = child_stream - self.delayed_events_lock = threading.Lock() + self.delayed_fns_lock = threading.Lock() self.defer_stop_events = False - self.delayed_events = [] + self.delayed_fns = [] # This queue accepts JSON objects that are then sent to the # DAP client. Writing is done in a separate thread to avoid # blocking the read loop. @@ -246,13 +246,13 @@ class Server: result = self._handle_command(cmd) self._send_json(result) self._handle_command_finish(cmd) - events = None - with self.delayed_events_lock: - events = self.delayed_events - self.delayed_events = [] + fns = None + with self.delayed_fns_lock: + fns = self.delayed_fns + self.delayed_fns = [] self.defer_stop_events = False - for event, body in events: - self.send_event(event, body) + for fn in fns: + fn() # Got the terminate request. This is handled by the # JSON-writing thread, so that we can ensure that all # responses are flushed to the client before exiting. @@ -264,8 +264,8 @@ class Server: def send_event_later(self, event, body=None): """Send a DAP event back to the client, but only after the current request has completed.""" - with self.delayed_events_lock: - self.delayed_events.append((event, body)) + with self.delayed_fns_lock: + self.delayed_fns.append(lambda: self.send_event(event, body)) @in_gdb_thread def send_event_maybe_later(self, event, body=None): @@ -275,9 +275,9 @@ class Server: the client.""" with self.canceller.lock: if self.canceller.in_flight_dap_thread: - with self.delayed_events_lock: + with self.delayed_fns_lock: if self.defer_stop_events: - self.delayed_events.append((event, body)) + self.delayed_fns.append(lambda: self.send_event(event, body)) return self.send_event(event, body) From patchwork Thu Nov 21 20:35:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 101699 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 717453857B91 for ; Thu, 21 Nov 2024 20:38:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 717453857B91 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=OJOpHsU/ X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id 6CF853857B96 for ; Thu, 21 Nov 2024 20:35:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CF853857B96 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6CF853857B96 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221323; cv=none; b=a7wjgKyWxBZAo8O23FGYjW7pNfKjNbq5xhqN/SJ9cz/d6dqSnDAfN2Ic5NZNTbnuD1bFIIcm2EXEReThm8WEVE4XPfu5HI9DOLMKIyV6pOo+BfYPdWtRat1eGlooQsyHKGjH40m0eXmuW1vutVRbfN8ueRvX/9PjQ5yudybz3aY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221323; c=relaxed/simple; bh=90D47SCgU4N+ungB2iV3lrdox0beQ30Vd0mjp2Ymmv4=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=LmbqSvlpPL/mlykTLmJ1Zb+rrWlSJeLrIBgxIESt46BwNRpOiytM11Ln3wetmAnCp8+eSruxdRa6c7fQYnaTmEcwzZPwjxD384uZprJVVU7LMxCzBn84w4SjwHiar+gKHDDHLdy2mACKOZAYySIVXQ9lgYIrg+ewg4J3/Yp5XeU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CF853857B96 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-83aba237c03so47068239f.3 for ; Thu, 21 Nov 2024 12:35:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1732221322; x=1732826122; darn=sourceware.org; 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=tPfAnyA8YFfM8rorXZvc2g+3I7sDU/RusamWT0DCVTA=; b=OJOpHsU/TEe3T3ZWmmKX/GDNqguS9VQPDXCx0Y8Hh5vBvVUi/m/CBRBHT+JhdnQc5c TcrP76YhtnTFxK4rPjGVFgJgG4v1pVtYmLBJgW1lBgAaiwy7VTiCGp7qYd74w9S/RyZk 5n0Zd7r0jP/hNSWMzJfX+Y/wlaB3G6RTm3eiF8a2OnM2ZCiktuxCpryWQz7zHCBWEuC/ L0md0qCSn7bQKdJSkcQ3gvOWNSYQfPK35IxnOyk8Lp28jY6Z7aIKpfhdBQ+5JSnZfcA1 XDLHN1A/quXv5SIE+q/zv98WJHGSimReJMryd5xK1L5rQ5Ss36m7KfiRRb9QiP++JnIs ZCXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732221322; x=1732826122; 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=tPfAnyA8YFfM8rorXZvc2g+3I7sDU/RusamWT0DCVTA=; b=JpoNO7Sd9aAeJjg9yXRqd1+txND/hZnQ4tr1/lZrN9hh6PEWW/Hxmf5qDXE9NQmewj 6StLj9LXkos7Mqq0vnE0ZETos2OJupni4lqdfnNXOIDI2EkA+mwpKQ1Mrngj9fZf7kSF SsF4Rwwg7aGYk4eTVA7X401vhHzDZmv9/dxSlnP2gJdafy9C740k0spCtGFE6l0tJIMg of9ElnPaB1anGChjPo9fyBz66R62QZTIg/awKJwz+QUlueTL/FFIVPSECaGaGOQAqjtv nhEa2kB/k5qiKZmiA8Tmeh7SY9NU9ilf8cuhbxjpJg3qYXSQRFqO4V1H+I8TTC8MsSPR 7Oqw== X-Gm-Message-State: AOJu0Yy+ks94JdiJ6YxI9UwTFiwh1K5N7xdsttKHAu/mqWccLVFjV9S1 AMNMjs2XrlsQHSdccks6KsYnzuHUJ4p/nWVJTq41xLMr++x6Y0N4TDWcWTVsCbZX3BybyfR7uVY = X-Gm-Gg: ASbGnctRQG/wlYeZ7ZIwX9sGyK7SBgubdanUuLgYgbfvmZA8T3zHzjiKJ4Qithtiyzd 5bN8w+B9Loxbpfkf40DoO1OKQckNpGT0Jucau5Q/KZ7ZpeKjF7sNZNnA/PchLRbiYpbwtQ0H+HO 8hXGQbTyj7JMACSe1dKzJnuHtG0GWgg0I4eO+fEW+kq4Dms/lkP7OG2I9sHbylLAK24+PWi+Pts qDGF1y4b/bQWO4/TQpRqXQUuOEfRX6kLl+87X2DaK5htAcESGC6tKlWgSI2XLPjziM8NDbgnKqk oN4UqTqtgtqUvI+3 X-Google-Smtp-Source: AGHT+IFDQEqOhJ8KcW5hxgZ66IH4yDj0baAF4r4nIsJWMYMN24P9qYeX3ZNq7tg7iGXkv+BHGgdPXQ== X-Received: by 2002:a05:6602:6409:b0:83b:29a5:ff89 with SMTP id ca18e2360f4ac-83ecdd15e9emr24943339f.15.1732221322563; Thu, 21 Nov 2024 12:35:22 -0800 (PST) Received: from localhost.localdomain (97-122-113-155.hlrn.qwest.net. [97.122.113.155]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ecd43fb95sm9263139f.51.2024.11.21.12.35.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 12:35:21 -0800 (PST) From: Tom Tromey Date: Thu, 21 Nov 2024 13:35:18 -0700 Subject: [PATCH 3/7] Add call_function_later to DAP MIME-Version: 1.0 Message-Id: <20241121-dap-launch-v3-v1-3-c1fa046b3285@adacore.com> References: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> In-Reply-To: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.3 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 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This adds a new call_function_later API to DAP. This arranges to run a function after the current request has completed. This isn't used yet, but will be at the end of this series. --- gdb/python/lib/gdb/dap/server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index ceffefc81dc1c42d695008a0fe67454deab71ee5..09190452edff174cc913dc52d524739e1478ca86 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -281,6 +281,12 @@ class Server: return self.send_event(event, body) + @in_dap_thread + def call_function_later(self, fn): + """Call FN later -- after the current request's response has been sent.""" + with self.delayed_fns_lock: + self.delayed_fns.append(fn) + # Note that this does not need to be run in any particular thread, # because it just creates an object and writes it to a thread-safe # queue. @@ -321,6 +327,12 @@ def send_event_maybe_later(event, body=None): _server.send_event_maybe_later(event, body) +def call_function_later(fn): + """Call FN later -- after the current request's response has been sent.""" + global _server + _server.call_function_later(fn) + + # A helper decorator that checks whether the inferior is running. def _check_not_running(func): @functools.wraps(func) From patchwork Thu Nov 21 20:35:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 101701 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 218FC385783B for ; Thu, 21 Nov 2024 20:40:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 218FC385783B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=KmSk+ejy X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id A53583857BBA for ; Thu, 21 Nov 2024 20:35:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A53583857BBA Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A53583857BBA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221324; cv=none; b=a/nswuu/D+quhqUCwRiVlSAKYuu6l5x/SM5kcForUXf/lnZtBtLNgcXbN4dIfDazl8IfAKgiBEyW39PeAkH9Hk1YrHTYnuAWZSRkoFlKpm50SlZoABIjIWvHJOdSVJj6zLA6OAApeuvzI3h4QhPSA6YAjt+dErVPp7YfC/YwzE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221324; c=relaxed/simple; bh=k/jAcAD6zpqkw4uH7/jb7zOVI7Z1tX91fn/FWghrq2U=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=WDaKUqn0Qa/Bkpq5GNC3HutWbw/AgrSNY/ggXo6csZg+hGbai1yY5gviZWMBpMaLs7wgYM5FhKEzKv+jvtbv78Medmf4umErniWwyNmhMv2MBqUOpDc9FJ4oiOqT8D+E8XnIYiFC/C+uerFJye71uaYKGdlDudQ29XBhdp8OJgo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A53583857BBA Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-83eb38883b5so52303239f.1 for ; Thu, 21 Nov 2024 12:35:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1732221324; x=1732826124; darn=sourceware.org; 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=/8rmI4gxuEVNqqGKo7/SbCK2zwlLvnBwu4hX1lVH7oE=; b=KmSk+ejy/I6mu72oBDywKUILKDVnt57DXk2PP9FvNyyHv/vCvtroSeRSXwP5u4vmio cOA6PdsXAKg7hSDM8y/u4dscWnlXdMf1d7ZbNfChLW1TVt16gkEvl/BeFOV1vBP8YsR2 myTR1OOYp+GQCmkYjPgkskRfCGHfP2+Lspq38iSY7lKiCN0BGvy7sQY+/ki0Fk29Ybet 84V928TddjzfiaaoGpx2pcSZ2BkDKacKSyK8O1iSLTQGDxV+6X9vm17vEonMyKavnple FLTOqQ7MKx9eGjNGuFrG7JXGxsuONKzxjQYS0iKBjByvnuFmNbbjsgdmQVvDRfcpXSZD TelA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732221324; x=1732826124; 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=/8rmI4gxuEVNqqGKo7/SbCK2zwlLvnBwu4hX1lVH7oE=; b=BJ5waPDDikaAZYh7BRMXiYupmkBJpR1Y1EfHbS4OKphvVn7NW3DJH3E2Fx0Vzs3BvY bU/xyAiIsCNlC93dgcgp3pt1jLbQiC/6xwrVKjL/i3xjJEFDbtKKGf2Ae7bvSrlxXHgO C/j/3K1CeGN5mjr+bKULVXx1XTqg6AsnRyozbjlbnFRGaeSbEH6bGDD0myDyMsWshFFv A49zebjp7Ubjqrleh+ESwr+YrEXUdB+vz8iXeGHK+DilrQ1vzgRb1HdRRr37yLVtKkKH maiS12yIeaT5nnHpPLIxofSpdqqNa/5Wi3duodPEbkGTW49AG55iEWXxCJtAI5s0kZTZ qK7w== X-Gm-Message-State: AOJu0Yyh8fpY96V79I9axwhidqRPqtvwouO+dpur542mamRNo2kfraPk 0itNeTXgBk8DneH0+YBfbz7472qplAP0Z2vZIvYb0ehQCt3+CFi7SuofBuBq6drdTYiA5fRMepw = X-Gm-Gg: ASbGnctxgXoiogDJczE4W+jHAXHhQxmbJvtcuq0GOPZR9kqOC6Zy771zR/atfVjXOMP 565lJDyR0f4WqIQdAyvcqxJ3ya5Gglj59MSBwZtUInRQ9C0wjy1rQeqo9O8Zrhpi/bZyUh4Owck l3H0s2CdABX0arzA9zQuDUqkidY6YDEYxmstmBle/GhDLSsjjVnenlEkxfHuAlrR8eibPIwFcHl yhwMvmeksuXv7qVCitb2eXTJuJjUQvJDRpu2X0wT0tIpR3P/rQyMMZaZsduz/5BEB+GxnQm0pRb gRQZXPaarBdUEpKO X-Google-Smtp-Source: AGHT+IG6Alf53yI+jlR4rv/uTzveXflfD0HeInscNBcj+TAHNjBNg4Btk42QHsJqADMVgY4XcJu/Gg== X-Received: by 2002:a05:6602:164c:b0:83a:a9cc:69ff with SMTP id ca18e2360f4ac-83ecdd2ff2cmr29752539f.13.1732221323930; Thu, 21 Nov 2024 12:35:23 -0800 (PST) Received: from localhost.localdomain (97-122-113-155.hlrn.qwest.net. [97.122.113.155]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ecd43fb95sm9263139f.51.2024.11.21.12.35.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 12:35:23 -0800 (PST) From: Tom Tromey Date: Thu, 21 Nov 2024 13:35:19 -0700 Subject: [PATCH 4/7] Refactor CancellationHandler in DAP MIME-Version: 1.0 Message-Id: <20241121-dap-launch-v3-v1-4-c1fa046b3285@adacore.com> References: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> In-Reply-To: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.3 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 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This refactors the DAP CancellationHandler to be a context manager, and reorganizes the caller to use this. This is a bit more robust and also simplifies a subsequent patch in this series. --- gdb/python/lib/gdb/dap/server.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 09190452edff174cc913dc52d524739e1478ca86..0f3991da77fb3180e5a15a4460b402b9bc7590d0 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -65,15 +65,17 @@ class CancellationHandler: self.in_flight_gdb_thread = None self.reqs = [] - def starting(self, req): - """Call at the start of the given request.""" - with self.lock: - self.in_flight_dap_thread = req - - def done(self, req): - """Indicate that the request is done.""" - with self.lock: - self.in_flight_dap_thread = None + @contextmanager + def current_request(self, req): + """Return a new context manager that registers that request + REQ has started.""" + try: + with self.lock: + self.in_flight_dap_thread = req + yield + finally: + with self.lock: + self.in_flight_dap_thread = None def cancel(self, req): """Call to cancel a request. @@ -150,7 +152,6 @@ class Server: "command": params["command"], } try: - self.canceller.starting(req) if "arguments" in params: args = params["arguments"] else: @@ -181,11 +182,6 @@ class Server: result["message"] = str(e) return result - @in_dap_thread - def _handle_command_finish(self, params): - req = params["seq"] - self.canceller.done(req) - # Read inferior output and sends OutputEvents to the client. It # is run in its own thread. def _read_inferior_output(self): @@ -243,9 +239,10 @@ class Server: # A None value here means the reader hit EOF. if cmd is None: break - result = self._handle_command(cmd) - self._send_json(result) - self._handle_command_finish(cmd) + req = cmd["seq"] + with self.canceller.current_request(req): + result = self._handle_command(cmd) + self._send_json(result) fns = None with self.delayed_fns_lock: fns = self.delayed_fns From patchwork Thu Nov 21 20:35:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 101702 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 644B4385783B for ; Thu, 21 Nov 2024 20:41:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 644B4385783B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=HoAigIqT X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 208DB385780C for ; Thu, 21 Nov 2024 20:35:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 208DB385780C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 208DB385780C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::132 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221326; cv=none; b=ELqTxRmQb94TEr/x7NtcZFkKk1SWOXP4QBtKJm7VlnpDyC662eCF2RwQXAoX7f6jyoX4iW7YZyxIOqKuXaRkA86SWAniH4ZiU33eqqaEVgILQ66yWmsnX8t325uPSrv+MERhUSYe3eNmtS1yi7lEg5v/YohXaaXlbaPN6CXmLYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221326; c=relaxed/simple; bh=HWQk+9Mna8rtQoGuRdc8ydh4xAMagJ3m134j9TfYSVA=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=MvqSNVzQ1SU/c5efR3F2PNvZw35q3sGT/OPX78P2GPv2TS5MT2ryXaSunFQ2kDtLkWW9PbO8oinNt2v6xlSAVTZsDbuHT5tRdxnWjB5WcDY6AuwIWW2k5Sy9t/4nzBeEapbVuFOup/JWoDw6TZbqCIhchhHnF2e4w+8Ai7cd9lM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 208DB385780C Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-3a77c066a15so4710625ab.3 for ; Thu, 21 Nov 2024 12:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1732221325; x=1732826125; darn=sourceware.org; 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=vSlGAAO517fyysPpgovI1UQj//jgMAOWd9Ao8OLcvyA=; b=HoAigIqT1XWrEp7GByQjY0DLYHVveoxCTeXiyixLXjzCFpDNU8gRmP2vNHJ59/KaGi 803OJ6ejp8tajQa6m9P2i6GxEQuNUyt4rMclW/u/PafhtpCx74cojyJHAg92mfzAIpUy N80BqTxniLlRrL5okmhQQCTpLrWTldD/etpIw8nwqiO9gBriNfQ5XZegr5UhssmkEE09 7NiLv+Ci+27ZrmTBwT0Qfskiu3seFGc4XhxQ7ssgG6PfJlhsx19kTzG9aL5CO7sDa7p5 kn1h8Q7fna+kL64fdYDnpmyOCjjYQyMjY8uZdq63BcSgV6gnrgp3oEcmLjZVe8gV6/CT tVow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732221325; x=1732826125; 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=vSlGAAO517fyysPpgovI1UQj//jgMAOWd9Ao8OLcvyA=; b=pErAvdXa6GS1YUqd0ug85UJ6zIQ/hcC2+eRmaGXivkghmlAm8QEJlR+axgBMeT3Q7W 6IrOOF0tL9x8Ssm0BLFywjKZCX0PJYp19VQzyEHHqF+HlRl6NBzlCz3mL2FIG9yLCNMN DEVrv7uqb7URPkcH3SNpqtvhKdO7g4Y+E9TmKZWRKlyakTsrtim1tQ78Da2f408yGXSN ennxZYpZ48Mgwxchm0rDvU5U0VqMOVv9WLc0g4UYklEBfKw/K2oXRlTYoMeqbzaR0kaS bYSWe8KeNW+DDWl+B3HpZgd75ISNYUxt2ItZl/YdLXfV8JkZV+K4ByfbkO4g8nVF1woP tx7w== X-Gm-Message-State: AOJu0YwtJujWOGAO6cZTcFZ7PoTf0nCde2sC+16aG1ybroldd6+Bqkx4 BZ2NJpsj3zY/LVagrsMcxvvO0vTse8TpWomCuFaNX+oxamVOwUgF2mU8DWSxGSD+dCKvR3CERgM = X-Gm-Gg: ASbGnctXhC5T3HckgxALCGglRH6FKcsE1mIzFsFDCquImmHk92DWltTjIGsnZXyMwQy 9p3XjRNvoFJEMgSuFF0tx7LA7Mb6IUOt1aarvLQNq9p6qFwp2R8s8G1f7ZPeLWYfqAcPfhl11IA bsrfqqeBOI9kp/yJFNX5KM8E/zuriTNGt96ckm2c1g3hiCjOj3JtlEOYC4/RxjxAm29fKHAgO0z hvb+KqSF+kKoT0QHjXpkia9/gTJDIBbQfVJr5rAco75DEdtdQV1LBxcCWJJEY7JfKuwLXj38hZ5 v39+nKR9uolhkleB X-Google-Smtp-Source: AGHT+IE3xJBbVCudkPu7IB4hmWYfq5n/VjgXWzl03/CcBVdwSEtJuc8BiliXBKQwk/qqy1TPnRjHuw== X-Received: by 2002:a05:6602:6d8e:b0:81f:75bf:6570 with SMTP id ca18e2360f4ac-83ecdc602afmr36353539f.5.1732221325277; Thu, 21 Nov 2024 12:35:25 -0800 (PST) Received: from localhost.localdomain (97-122-113-155.hlrn.qwest.net. [97.122.113.155]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ecd43fb95sm9263139f.51.2024.11.21.12.35.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 12:35:24 -0800 (PST) From: Tom Tromey Date: Thu, 21 Nov 2024 13:35:20 -0700 Subject: [PATCH 5/7] Allow cancellation of DAP-thread requests MIME-Version: 1.0 Message-Id: <20241121-dap-launch-v3-v1-5-c1fa046b3285@adacore.com> References: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> In-Reply-To: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.3 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 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This patch started as an attempt to fix the comment in CancellationHandler.cancel, but while working on it I found that the code could be improved as well. The current DAP cancellation code only handles the case where work is done on the gdb thread -- by checking for cancellation in interruptable_region. This means that if a request is handled completely in tthe DAP thread, then cancellation will never work. Now, this isn't a bug per se. DAP doesn't actually require that cancellation succeed. In fact, I think it can't, because cancellation is inherently racy. However, a coming patch will add a sort of "pending" request, and it would be nice if that were cancellable before any commands are sent to the gdb thread. No test in this patch, but one will arrive at the end of the series. --- gdb/python/lib/gdb/dap/server.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 0f3991da77fb3180e5a15a4460b402b9bc7590d0..8f2a531113def6efd5b989ae6d166fe12fb30ad3 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -59,7 +59,9 @@ class NotStoppedException(Exception): class CancellationHandler: def __init__(self): # Methods on this class acquire this lock before proceeding. - self.lock = threading.Lock() + # A recursive lock is used to simplify the 'check_cancel' + # callers. + self.lock = threading.RLock() # The request currently being handled, or None. self.in_flight_dap_thread = None self.in_flight_gdb_thread = None @@ -72,11 +74,23 @@ class CancellationHandler: try: with self.lock: self.in_flight_dap_thread = req + # Note we do not call check_cancel here. This is a bit of + # a hack, but it's because the direct callers of this + # aren't prepared for a KeyboardInterrupt. yield finally: with self.lock: self.in_flight_dap_thread = None + def check_cancel(self, req): + """Check whether request REQ is cancelled. + If so, raise KeyboardInterrupt.""" + with self.lock: + # If the request is cancelled, don't execute the region. + while len(self.reqs) > 0 and self.reqs[0] <= req: + if heapq.heappop(self.reqs) == req: + raise KeyboardInterrupt() + def cancel(self, req): """Call to cancel a request. @@ -88,7 +102,7 @@ class CancellationHandler: gdb.interrupt() else: # We don't actually ignore the request here, but in - # the 'starting' method. This way we don't have to + # the 'check_cancel' method. This way we don't have to # track as much state. Also, this implementation has # the weird property that a request can be cancelled # before it is even sent. It didn't seem worthwhile @@ -105,10 +119,7 @@ class CancellationHandler: return try: with self.lock: - # If the request is cancelled, don't execute the region. - while len(self.reqs) > 0 and self.reqs[0] <= req: - if heapq.heappop(self.reqs) == req: - raise KeyboardInterrupt() + self.check_cancel(req) # Request is being handled by the gdb thread. self.in_flight_gdb_thread = req # Execute region. This may be interrupted by gdb.interrupt. @@ -152,6 +163,7 @@ class Server: "command": params["command"], } try: + self.canceller.check_cancel(req) if "arguments" in params: args = params["arguments"] else: From patchwork Thu Nov 21 20:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 101700 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 010C33857BBA for ; Thu, 21 Nov 2024 20:39:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 010C33857BBA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Oi4kyBBx X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 925483857734 for ; Thu, 21 Nov 2024 20:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 925483857734 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 925483857734 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221327; cv=none; b=WmrPiAzKNPbj3HJLQfaMCh2bMO18E2DR3XtqDQycpKks4UmL/oFkeBLpfyppIHKvgU+eUvaxAWXag2e6Qgbhd6VqMmnhl3V5oHJpOLxszsjCMMKk8rExxQYicZ7xHJ2X1vEZocJ7jRBuEc1z9unJgBLPYPaX/KFDAkNiv5E+32k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221327; c=relaxed/simple; bh=joGe5yj5AK6LjWMKOD9wNtstIuBmS6jKQfFmgevMwoU=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=pOp7d4VQu+HmC9wGn4AFJvdNzz3WGkJHkpttfiswjxXXZTatOyie7TKiKvnqLAyDFKmylvswTN13yO0E7GHwK+DfhNb+QEH33aY5BqINzatJP9E7DVf3FeuwPQqWe5Q5Jbzx7bvvtq1EEeMIKBBsLdvn603FRpW+BVXuqQufn+g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 925483857734 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-83a9cd37a11so51229939f.3 for ; Thu, 21 Nov 2024 12:35:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1732221327; x=1732826127; darn=sourceware.org; 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=qIhX/MDt8fztRHhK1x8MxDrNrHnOIwAIYmxVS7WB5Lw=; b=Oi4kyBBxjb1HACaGdkgBy8hAywGT56zhxdOoRfI3gG/cQuYhIEVDrKeTSQO7GzI3d3 LOQmHemR0JeFEUh1sMc9gmlcfunb4vI6UXyUHi1ElNdwhHCyHFIUlnzQnIHS4eQfVYAp trWdV0jQ0vKSMZc1EWstyyjaZDBFTSg2m6nT9MIjpUxM6AcLuSq+JoRERgtr37YmrZKb N48KkWnXdCd9rEDZZr2aWpx3arrD3GLKaJhkezFSd3C8h36L0UYwX6KzqR8t4yRKqjn8 Rt49MRBp6v+iWteCqsYv0oPfP2hezHTkEpN6k/WIZaEs5ewP8TsYk8eIBsl2nAsvu0E/ zsgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732221327; x=1732826127; 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=qIhX/MDt8fztRHhK1x8MxDrNrHnOIwAIYmxVS7WB5Lw=; b=oFm7VgO72RH9nSbaYga5n9ETqZjmr0RpChDUD2OoGgWlnozHiQN9LAZHaOqkrgho5E BsE3e8tRTn+rmQ8DDje2rtziWXfgLmrjDF7JL4eDxFXYgN0LvwqCnWC1nv8H3l1TQfaO 8trAoqdyEJ5W+6NFRDhG/dfrXQUQ/nxRVwLrZsIXjMAk9/BSsLXC9ztJG4S8w3aJuYyI Tht6vV1y9ERzSoxMmqLxa0wLUMT4R1jRA8YF82eF1PB20gNlAZ+gV4IKkJWZtMcPkETn AlFLPemERSbVqHnME1J4Ft4zh4QAEalLXSjaoRbxx3SCsj4bHLeCB+MqSyPgCzpBQ/YA byAA== X-Gm-Message-State: AOJu0YzrVUkmm1srjs6n6PvrqWkaSfeMYl0gwXPIf5GGr42vGBXkkhMa BWLO9yZ2pyqoRVC3m1SR7oVpryognmoE0D04qsWirV1HJl1WwiQJf7ZGBiOQDsYk+Q9tQpNWsOo = X-Gm-Gg: ASbGncu6o3niFhGPFtFvUBAyFfgAu4TATuJfr+RHoYaJfQymkH/t+A6KKuBwmLelCF2 oy0nWNVTLng9QYrASAgnP1DQD76zU+QuTYYzcRyCKugqodJmdVtnBhbugsMAgY6+TChyzmyQ1Kj b+GO+pCd0HdHw8C/g2wjAnLrzhAjJiaQNiOcN4vZEILVammglesi4eOfjyYiiXvBstZXwcNpmh8 0RU6hqzZXH3oYoIHAAKvvEC9AkSKu69cWnHUr/PimL+JPPphoVEB14ZA89nPThxAmXly1j25zSJ 6C1pSyqb5oz2u4Ci X-Google-Smtp-Source: AGHT+IHK0MFUSh9+dP8JRdQUrf6IkzPR3miyNgbmwliHZkVSZEOuqKqVqaHW54Q7bnF52/HqEWDV8A== X-Received: by 2002:a05:6602:6405:b0:837:7e21:1688 with SMTP id ca18e2360f4ac-83ecdcf315cmr34313039f.11.1732221326627; Thu, 21 Nov 2024 12:35:26 -0800 (PST) Received: from localhost.localdomain (97-122-113-155.hlrn.qwest.net. [97.122.113.155]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ecd43fb95sm9263139f.51.2024.11.21.12.35.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 12:35:26 -0800 (PST) From: Tom Tromey Date: Thu, 21 Nov 2024 13:35:21 -0700 Subject: [PATCH 6/7] Add DAP deferred requests MIME-Version: 1.0 Message-Id: <20241121-dap-launch-v3-v1-6-c1fa046b3285@adacore.com> References: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> In-Reply-To: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.3 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 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This adds a new "deferred request" capability to DAP. The idea here is that if a request returns a DeferredRequest object, then no response is sent immediately to the client. Instead, the request is pending until the deferred request is rescheduled. Some minor refactorings, particularly in cancellation, were needed to make this work. There's no use of this in the tree yet -- that is the next patch. --- gdb/python/lib/gdb/dap/server.py | 160 +++++++++++++++++++++++++++++++++------ 1 file changed, 136 insertions(+), 24 deletions(-) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 8f2a531113def6efd5b989ae6d166fe12fb30ad3..68801efb9e04205b76121b619cf3a0236c8077d7 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -47,6 +47,52 @@ _commands = {} _server = None +class DeferredRequest: + """If a DAP request function returns a deferred request, no + response is sent immediately. + + Instead, request processing continues, with this particular + request remaining un-replied-to. + + Later, when the result is available, the deferred request can be + scheduled. This causes 'invoke' to be called and then the + response to be sent to the client. + + """ + + # This is for internal use by the server. It should not be + # overridden by any subclass. This adds the request ID and the + # result template object to this object. These are then used + # during rescheduling. + def set_request(self, req, result): + self._req = req + self._result = result + + @in_dap_thread + def invoke(self): + """Implement the deferred request. + + This will be called from 'reschedule' (and should not be + called elsewhere). It should return the 'body' that will be + sent in the response. None means no 'body' field will be set. + + Subclasses must override this. + + """ + pass + + @in_dap_thread + def reschedule(self): + """Call this to reschedule this deferred request. + + This will call 'invoke' after the appropriate bookkeeping and + will arrange for its result to be reported to the client. + + """ + with _server.canceller.current_request(self._req): + _server.invoke_request(self._req, self._result, self.invoke) + + # A subclass of Exception that is used solely for reporting that a # request needs the inferior to be stopped, but it is not stopped. class NotStoppedException(Exception): @@ -66,6 +112,9 @@ class CancellationHandler: self.in_flight_dap_thread = None self.in_flight_gdb_thread = None self.reqs = [] + # A set holding the request IDs of all deferred requests that + # are still unresolved. + self.deferred_ids = set() @contextmanager def current_request(self, req): @@ -82,14 +131,52 @@ class CancellationHandler: with self.lock: self.in_flight_dap_thread = None + def defer_request(self, req): + """Indicate that the request REQ has been deferred.""" + with self.lock: + self.deferred_ids.add(req) + + def request_finished(self, req): + """Indicate that the request REQ is finished. + + It doesn't matter whether REQ succeeded or failed, only that + processing for it is done. + + """ + with self.lock: + # Use discard here, not remove, because this is called + # regardless of whether REQ was deferred. + self.deferred_ids.discard(req) + def check_cancel(self, req): """Check whether request REQ is cancelled. If so, raise KeyboardInterrupt.""" with self.lock: - # If the request is cancelled, don't execute the region. - while len(self.reqs) > 0 and self.reqs[0] <= req: - if heapq.heappop(self.reqs) == req: - raise KeyboardInterrupt() + # We want to drop any cancellations that come before REQ, + # but keep ones for any deferred requests that are still + # unresolved. This holds any such requests that were + # popped during the loop. + deferred = [] + try: + # If the request is cancelled, don't execute the region. + while len(self.reqs) > 0 and self.reqs[0] <= req: + # In most cases, if we see a cancellation request + # on the heap that is before REQ, we can just + # ignore it -- we missed our chance to cancel that + # request. + next_id = heapq.heappop(self.reqs) + if next_id == req: + raise KeyboardInterrupt() + elif next_id in self.deferred_ids: + # We could be in a situation where we're + # processing request 23, but request 18 is + # still deferred. In this case, popping + # request 18 here will lose the cancellation. + # So, we preserve it. + deferred.append(next_id) + finally: + for x in deferred: + heapq.heappush(self.reqs, x) def cancel(self, req): """Call to cancel a request. @@ -152,27 +239,27 @@ class Server: global _server _server = self - # Treat PARAMS as a JSON-RPC request and perform its action. - # PARAMS is just a dictionary from the JSON. + # A helper for request processing. REQ is the request ID. RESULT + # is a result "template" -- a dictionary with a few items already + # filled in. This helper calls FN and then fills in the remaining + # parts of RESULT, as needed. If FN returns an ordinary result, + # or if it fails, then the final RESULT is sent as a response to + # the client. However, if FN returns a DeferredRequest, then that + # request is updated (see DeferredRequest.set_request) and no + # response is sent. @in_dap_thread - def _handle_command(self, params): - req = params["seq"] - result = { - "request_seq": req, - "type": "response", - "command": params["command"], - } + def invoke_request(self, req, result, fn): try: self.canceller.check_cancel(req) - if "arguments" in params: - args = params["arguments"] - else: - args = {} - global _commands - body = _commands[params["command"]](**args) - if body is not None: - result["body"] = body + fn_result = fn() result["success"] = True + if isinstance(fn_result, DeferredRequest): + fn_result.set_request(req, result) + self.canceller.defer_request(req) + # Do not send a response. + return + elif fn_result is not None: + result["body"] = fn_result except NotStoppedException: # This is an expected exception, and the result is clearly # visible in the log, so do not log it. @@ -192,7 +279,33 @@ class Server: log_stack() result["success"] = False result["message"] = str(e) - return result + + self.canceller.request_finished(req) + # We have a response for the request, so send it back to the + # client. + self._send_json(result) + + # Treat PARAMS as a JSON-RPC request and perform its action. + # PARAMS is just a dictionary from the JSON. + @in_dap_thread + def _handle_command(self, params): + req = params["seq"] + result = { + "request_seq": req, + "type": "response", + "command": params["command"], + } + + if "arguments" in params: + args = params["arguments"] + else: + args = {} + + def fn(): + global _commands + return _commands[params["command"]](**args) + + self.invoke_request(req, result, fn) # Read inferior output and sends OutputEvents to the client. It # is run in its own thread. @@ -253,8 +366,7 @@ class Server: break req = cmd["seq"] with self.canceller.current_request(req): - result = self._handle_command(cmd) - self._send_json(result) + self._handle_command(cmd) fns = None with self.delayed_fns_lock: fns = self.delayed_fns From patchwork Thu Nov 21 20:35:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 101703 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 D93123857350 for ; Thu, 21 Nov 2024 20:41:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D93123857350 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Qb5C774x X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id DE960385783B for ; Thu, 21 Nov 2024 20:35:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE960385783B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE960385783B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221329; cv=none; b=evnU1AXM69bUzvti/pSrNUCPNWs2Ydr6r3BdaTknNr6vqFFDUwpGiSl0e5oAQwZ3y4pYmM01PXrhdRCP2575t6RLP7oe9GqpgJPu9zPF21T84cnUYE36cGfLMyuWJ36Zw0arjNhMPmPMV2YEPuVQxKwO0NlaMzAhkyX96pdIDYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732221329; c=relaxed/simple; bh=venAU+ZmpYpeXRWZl6E+J0QQabDqrPXx4+TR2KPToz0=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=gSb9nf7amltz0Yqe7b1cnzCQCFWL/W0GM57woCX2lnHsf3Mi+NS2L9y3aQmL6WlB6BspoHrjr9Yj5ybuV79+TTwI1CDLp38UA14amsrMw8Dm3x06Q1cRHCsELeM0pLzqt1N0bnnnXtgj0ZN6X/4xUaC3JUNZQHeDmfNCby2AzaE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE960385783B Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-83aba237c03so47072439f.3 for ; Thu, 21 Nov 2024 12:35:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1732221328; x=1732826128; darn=sourceware.org; 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=OWMu9y0+FRpuZW7/9SYeYOSxGv8LnpLv5TXRD1K/9TQ=; b=Qb5C774xWoH7TGjU1qki5JunMdUNCj8VVvZ32xGrcsXPZm0DpIDCDUc+Cbq18KDR0D bLnt9UwfnAe1l11b0pNXGMhi5GIbRo+lqtXtTjfW9RIH2PQ+DeAfkBY01Zu55UpjMalt PnBIVfaJUpT/t9+3PraLTqmMH1ag6KGU5LbIN4G9XzvVcJgn6jpyK9TmKUn6yOp+pO7w lNMFaT3HkuNG13idpaLfoEG8Bo1atj+s1/7GWdb27EslN8fTBRyXoSFMEhYCXOeiqGXw HmGdMNdMAklClJp+f3g+hRYeYDoXi5swyeq5XCufO/8YhNQ87+e1C0M40T61ttLOKhNC jVFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732221328; x=1732826128; 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=OWMu9y0+FRpuZW7/9SYeYOSxGv8LnpLv5TXRD1K/9TQ=; b=S+1/RvrOL6KBKIJJtzm5vPfduydHtw+FrJlyl+S1U6Q/dTJZao4aD3VR+c5sszBjyt HZ2xthUuDs7V7owlwWrXXPJg5fNByt4vYKFKJ4NEkbtCQBIOw4YavOhXDFjZpS3+Z8vh BfdfEGMwDqLU/h//eOQtek0Bm2ySHH/21mb3q1N6psYogzfsIQSYTBUm4ueaWL/+PZci oUYszhZtTRrJ50bgC/ZJZCV5b8Lf3tNfTNRIX9cWk9Cgsxr+fdHlmlOAhqoTOBVIToay 65YuBAljrtdb8o9tXgvGlJ1S6zkMZ8g4w62Na5K0puQCOw11yBwhntl4SERD9jEhdxX4 9h4A== X-Gm-Message-State: AOJu0YwlO6GQ7wwdTKm/YdBZ0lHzRAJ44NhxJi1RPat9Fh0s/KuIiVEm pGaMxUOFOhaSzlU/rMCax08m2AL2JPdWLia2/duCt78oboeCENqhFDu6Lax6a3UFLFFf1feVUYo = X-Gm-Gg: ASbGncuPsUnB18tkRrHRPYKThUFquxQzQVm3Y/hqE14uzuekb4ALqlOHE6fBkoRrhpn DlxKyRK5Dq/NgOuQD6h84VIs3TVr9nCwpUS+tK1QwHO30dKtpzgyplKUTRsYO3+iFc4BdiZNeoy NimrWIqRzVohzh0jvUls9eWQaRJLQj3eb9WrRaagnSuA/XCvNJagEtiyn/XeNmLaGqnjRc9rRB1 i+cW0L107LaRWoAhwpR5Rh5RbpLKiLwMSfgVD8+KCy4eKPrxEtXj5Z39IknJVqnlVR6Y0FGNVX/ Hxcms4CyDwIDVuol X-Google-Smtp-Source: AGHT+IFUG39hrB2vbEEa/7tZ8e6HYd9iLYlz8UPc6gv4DEjagHozpEoYTIuHV3fzx+ajwRDXsrBkLw== X-Received: by 2002:a05:6602:3c6:b0:83a:9820:f26b with SMTP id ca18e2360f4ac-83ecdc370ddmr40975539f.2.1732221327712; Thu, 21 Nov 2024 12:35:27 -0800 (PST) Received: from localhost.localdomain (97-122-113-155.hlrn.qwest.net. [97.122.113.155]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ecd43fb95sm9263139f.51.2024.11.21.12.35.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 12:35:27 -0800 (PST) From: Tom Tromey Date: Thu, 21 Nov 2024 13:35:22 -0700 Subject: [PATCH 7/7] Defer DAP launch command until after configurationDone MIME-Version: 1.0 Message-Id: <20241121-dap-launch-v3-v1-7-c1fa046b3285@adacore.com> References: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> In-Reply-To: <20241121-dap-launch-v3-v1-0-c1fa046b3285@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org PR dap/32090 points out that gdb's DAP "launch" sequencing is incorrect. The current approach (which is itself a 2nd implementation...) was based on a misreading of the spec. The spec has since been clarified here: https://github.com/microsoft/debug-adapter-protocol/issues/497 The clarification here is that a client is free to send the "launch" (or "attach") request at any point after the "initialized" event has been sent by gdb. However, the "launch" does not cause any action to be taken -- and does not send a response -- until after "configurationDone" has been seen. This patch implements this by arranging for the launch and attach commands to return a DeferredRequest object. All the tests needed updates. I've also added a new test that checks that the deferred "launch" request can be cancelled. (Note that the cancellation is lazy -- it also waits until configurationDone is seen. This could be fixed, but I was not sure whether it is important to do so.) Finally, the "launch" command has a somewhat funny sequencing now. Simply sending the command and waiting for a response yielded strange results if the inferior did not stop -- in this case, the repsonse was never sent. So now, the command is split into two parts, with some setup being done synchronously (for better error propagation) and the actual "run" being done async. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32090 --- gdb/NEWS | 6 ++ gdb/python/lib/gdb/dap/launch.py | 152 ++++++++++++++++++++++-------- gdb/testsuite/gdb.dap/ada-arrays.exp | 7 +- gdb/testsuite/gdb.dap/ada-nested.exp | 7 +- gdb/testsuite/gdb.dap/ada-scopes.exp | 7 +- gdb/testsuite/gdb.dap/args-env.exp | 7 +- gdb/testsuite/gdb.dap/assign.exp | 7 +- gdb/testsuite/gdb.dap/attach.exp | 19 ++-- gdb/testsuite/gdb.dap/basic-dap.exp | 7 +- gdb/testsuite/gdb.dap/bt-nodebug.exp | 7 +- gdb/testsuite/gdb.dap/cancel-launch.exp | 56 +++++++++++ gdb/testsuite/gdb.dap/catch-exception.exp | 7 +- gdb/testsuite/gdb.dap/children.exp | 7 +- gdb/testsuite/gdb.dap/cond-bp.exp | 7 +- gdb/testsuite/gdb.dap/cwd.exp | 10 +- gdb/testsuite/gdb.dap/cxx-exception.exp | 7 +- gdb/testsuite/gdb.dap/disassem.exp | 7 +- gdb/testsuite/gdb.dap/frameless.exp | 7 +- gdb/testsuite/gdb.dap/global.exp | 7 +- gdb/testsuite/gdb.dap/hover.exp | 7 +- gdb/testsuite/gdb.dap/insn-bp.exp | 12 +-- gdb/testsuite/gdb.dap/lazy-string.exp | 7 +- gdb/testsuite/gdb.dap/log-message.exp | 7 +- gdb/testsuite/gdb.dap/memory.exp | 7 +- gdb/testsuite/gdb.dap/modules.exp | 7 +- gdb/testsuite/gdb.dap/pause.exp | 7 +- gdb/testsuite/gdb.dap/ptrref.exp | 7 +- gdb/testsuite/gdb.dap/remote-dap.exp | 10 +- gdb/testsuite/gdb.dap/rust-slices.exp | 7 +- gdb/testsuite/gdb.dap/scopes.exp | 7 +- gdb/testsuite/gdb.dap/sources.exp | 14 +-- gdb/testsuite/gdb.dap/stack-format.exp | 7 +- gdb/testsuite/gdb.dap/step-out.exp | 7 +- gdb/testsuite/gdb.dap/stop-at-main.exp | 7 +- gdb/testsuite/gdb.dap/terminate.exp | 7 +- gdb/testsuite/lib/dap-support.exp | 33 ++++--- 36 files changed, 337 insertions(+), 164 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 046daad0eae5fe8d853beb6cb0bb751ee6f23a77..327da08cf2f7137bc3b3685000454ba3d9b61e7a 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -92,6 +92,12 @@ the return value from the latest "stepOut" command, when appropriate. + ** The "launch" and "attach" requests were rewritten in accordance + with some clarifications to the spec. Now they can be sent at + any time after the "initialized" event, but will not take effect + (or send a response) until after the "configurationDone" request + has been sent. + * New commands set style line-number foreground COLOR diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 6444c8b7b6741c4847a6c12df78685afca37847a..fc1890c5a43d645d18da586c614ec8d30cf51071 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -21,8 +21,42 @@ from typing import Mapping, Optional, Sequence import gdb from .events import exec_and_expect_stop, expect_process, expect_stop -from .server import capability, request -from .startup import DAPException, exec_and_log, in_gdb_thread +from .server import ( + DeferredRequest, + call_function_later, + capability, + request, + send_gdb, + send_gdb_with_response, +) +from .startup import DAPException, exec_and_log, in_dap_thread, in_gdb_thread + +# A launch or attach promise that that will be fulfilled after a +# configurationDone request has been processed. +_launch_or_attach_promise = None + + +# A DeferredRequest that handles either a "launch" or "attach" +# request. +class _LaunchOrAttachDeferredRequest(DeferredRequest): + def __init__(self, callback): + self._callback = callback + global _launch_or_attach_promise + if _launch_or_attach_promise is not None: + raise DAPException("launch or attach already specified") + _launch_or_attach_promise = self + + # Invoke the callback and return the result. + @in_dap_thread + def invoke(self): + return self._callback() + + # Override this so we can clear the global when rescheduling. + @in_dap_thread + def reschedule(self): + global _launch_or_attach_promise + _launch_or_attach_promise = None + super().reschedule() # A wrapper for the 'file' command that correctly quotes its argument. @@ -37,7 +71,7 @@ def file_command(program): # Any parameters here are necessarily extensions -- DAP requires this # from implementations. Any additions or changes here should be # documented in the gdb manual. -@request("launch", response=False) +@request("launch", on_dap_thread=True) def launch( *, program: Optional[str] = None, @@ -48,27 +82,51 @@ def launch( stopOnEntry: bool = False, **extra, ): - if cwd is not None: - exec_and_log("cd " + cwd) - if program is not None: - file_command(program) - inf = gdb.selected_inferior() - inf.arguments = args - if env is not None: - inf.clear_env() - for name, value in env.items(): - inf.set_env(name, value) - expect_process("process") - if stopAtBeginningOfMainSubprogram: - cmd = "start" - elif stopOnEntry: - cmd = "starti" - else: - cmd = "run" - exec_and_expect_stop(cmd) - - -@request("attach") + # Launch setup is handled here. This is done synchronously so + # that errors can be reported in a natural way. + @in_gdb_thread + def _setup_launch(): + if cwd is not None: + exec_and_log("cd " + cwd) + if program is not None: + file_command(program) + inf = gdb.selected_inferior() + inf.arguments = args + if env is not None: + inf.clear_env() + for name, value in env.items(): + inf.set_env(name, value) + + # Actual launching done here. See below for more info. + @in_gdb_thread + def _do_launch(): + expect_process("process") + if stopAtBeginningOfMainSubprogram: + cmd = "start" + elif stopOnEntry: + cmd = "starti" + else: + cmd = "run" + exec_and_expect_stop(cmd) + + @in_dap_thread + def _launch_impl(): + send_gdb_with_response(_setup_launch) + # We do not wait for the result here. It might be a little + # nicer if we did -- perhaps the various thread events would + # occur in a more logical sequence -- but if the inferior does + # not stop, then the launch response will not be seen either, + # which seems worse. + send_gdb(_do_launch) + # Launch response does not have a body. + return None + + # The launch itself is deferred until the configurationDone + # request. + return _LaunchOrAttachDeferredRequest(_launch_impl) + + +@request("attach", on_dap_thread=True) def attach( *, program: Optional[str] = None, @@ -76,21 +134,39 @@ def attach( target: Optional[str] = None, **args, ): - if program is not None: - file_command(program) - if pid is not None: - cmd = "attach " + str(pid) - elif target is not None: - cmd = "target remote " + target - else: - raise DAPException("attach requires either 'pid' or 'target'") - expect_process("attach") - expect_stop("attach") - exec_and_log(cmd) + # The actual attach is handled by this function. + @in_gdb_thread + def _do_attach(): + if program is not None: + file_command(program) + if pid is not None: + cmd = "attach " + str(pid) + elif target is not None: + cmd = "target remote " + target + else: + raise DAPException("attach requires either 'pid' or 'target'") + expect_process("attach") + expect_stop("attach") + exec_and_log(cmd) + # Attach response does not have a body. + return None + + @in_dap_thread + def _attach_impl(): + return send_gdb_with_response(_do_attach) + + # The attach itself is deferred until the configurationDone + # request. + return _LaunchOrAttachDeferredRequest(_attach_impl) @capability("supportsConfigurationDoneRequest") -@request("configurationDone") +@request("configurationDone", on_dap_thread=True) def config_done(**args): - # Nothing to do. - return None + # Handle the launch or attach. + global _launch_or_attach_promise + if _launch_or_attach_promise is None: + raise DAPException("launch or attach not specified") + # Resolve the launch or attach, but only after the + # configurationDone response has been sent. + call_function_later(_launch_or_attach_promise.reschedule) diff --git a/gdb/testsuite/gdb.dap/ada-arrays.exp b/gdb/testsuite/gdb.dap/ada-arrays.exp index 0de361f96bd78cfddf8f3cf67a26c794bef081aa..64c6eb28c892821dbf3f31c06c98f46bc3eba24f 100644 --- a/gdb/testsuite/gdb.dap/ada-arrays.exp +++ b/gdb/testsuite/gdb.dap/ada-arrays.exp @@ -33,6 +33,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + # Stop in a C frame, but examine values in an Ada frame, to make sure # cross-language scenarios work correctly. set line [gdb_get_line_number "STOP" $testdir/cstuff.c] @@ -44,9 +46,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/ada-nested.exp b/gdb/testsuite/gdb.dap/ada-nested.exp index 3415da3e9cbd9ebe2a6055e7289b1e4270479b68..7f28d27e365615e8880f0af1496bf2cfd1e94a6a 100644 --- a/gdb/testsuite/gdb.dap/ada-nested.exp +++ b/gdb/testsuite/gdb.dap/ada-nested.exp @@ -31,6 +31,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "STOP"] set obj [dap_check_request_and_response "set breakpoint" \ setBreakpoints \ @@ -41,9 +43,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $binfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $fn_bpno diff --git a/gdb/testsuite/gdb.dap/ada-scopes.exp b/gdb/testsuite/gdb.dap/ada-scopes.exp index 4d895a5270d7c32d10c717f8b1428d4d2c5fdd6e..ef1302e0644dfe1435f453fd72ece3548d14dff4 100644 --- a/gdb/testsuite/gdb.dap/ada-scopes.exp +++ b/gdb/testsuite/gdb.dap/ada-scopes.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "STOP"] set obj [dap_check_request_and_response "set breakpoint" \ setBreakpoints \ @@ -39,9 +41,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $binfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $fn_bpno diff --git a/gdb/testsuite/gdb.dap/args-env.exp b/gdb/testsuite/gdb.dap/args-env.exp index d6511733348d78572a518a975bae4005a908a254..5f02b00dd5a5ae35a184230985f7f96d5563b915 100644 --- a/gdb/testsuite/gdb.dap/args-env.exp +++ b/gdb/testsuite/gdb.dap/args-env.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile arguments {a "b c"} env {{DEI something}}] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -38,9 +40,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile arguments {a "b c"} env {{DEI something}}] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/assign.exp b/gdb/testsuite/gdb.dap/assign.exp index 6703a97bb7a549f3fce5885348ebd4dceac0def0..6665b6a6a31f122f7b87405dfed4fbb73303b5be 100644 --- a/gdb/testsuite/gdb.dap/assign.exp +++ b/gdb/testsuite/gdb.dap/assign.exp @@ -36,6 +36,8 @@ save_vars GDBFLAGS { } } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "STOP"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -45,9 +47,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $line_bpno diff --git a/gdb/testsuite/gdb.dap/attach.exp b/gdb/testsuite/gdb.dap/attach.exp index ce2a16c1193b2a4ac3f3519fbb7c724126ac6e01..e0cd57b2009e115af5ae80d2aeed40545ae9e308 100644 --- a/gdb/testsuite/gdb.dap/attach.exp +++ b/gdb/testsuite/gdb.dap/attach.exp @@ -29,17 +29,14 @@ set test_spawn_id [spawn_wait_for_attach $binfile] set testpid [spawn_id_get_pid $test_spawn_id] # Test that attaching works at all. -set result [dap_attach $testpid $binfile] - -set found 0 -foreach ev [lindex $result 1] { - if {[dict get $ev type] == "event" - && [dict get $ev event] == "stopped" - && [dict get $ev body reason] == "attach"} { - set found 1 - } -} -gdb_assert {$found} "saw stopped event for attach" +set attach_id [dap_attach $testpid $binfile] + +dap_check_request_and_response "configurationDone" configurationDone + +dap_wait_for_event_and_check "stopped" stopped \ + "body reason" attach + +dap_check_response "attach response" attach $attach_id dap_shutdown true diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index 6ef9a5b0f6e11d0ca62b2e6afe6c4931245637c9..dd785ef53644b0451d57752f3f4995db38ea595a 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set breakpoint on two functions" \ setFunctionBreakpoints \ {o breakpoints [a [o name [s function_breakpoint_here]] \ @@ -86,9 +88,8 @@ gdb_assert {$new_line_bpno == $line_bpno} "re-setting kept same breakpoint numbe dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started # While waiting for the stopped event, we might receive breakpoint changed diff --git a/gdb/testsuite/gdb.dap/bt-nodebug.exp b/gdb/testsuite/gdb.dap/bt-nodebug.exp index 550b9c5c5ac242c0449d49bf7b38140680d42683..319dcf0c583d09428467976a5e50a87268c87ce1 100644 --- a/gdb/testsuite/gdb.dap/bt-nodebug.exp +++ b/gdb/testsuite/gdb.dap/bt-nodebug.exp @@ -31,6 +31,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set breakpoint on inner" \ setFunctionBreakpoints \ {o breakpoints [a [o name [s function_breakpoint_here]]]}] @@ -38,9 +40,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started lassign [dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/cancel-launch.exp b/gdb/testsuite/gdb.dap/cancel-launch.exp new file mode 100644 index 0000000000000000000000000000000000000000..94eba7ebe513b2a2344524349af4c6e63824905e --- /dev/null +++ b/gdb/testsuite/gdb.dap/cancel-launch.exp @@ -0,0 +1,56 @@ +# Copyright 2024 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 cancellation of a "launch" command. + +require allow_dap_tests + +load_lib dap-support.exp + +# Anything will work, we aren't going to run it. +standard_testfile sources.c + +if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { + return +} + +if {[dap_initialize] == ""} { + return +} + +set launch_id [dap_launch $testfile] + +# Set a breakpoint. This is done to ensure that the launch request is +# definitely in the deferred state when we try to cancel it. +set line [gdb_get_line_number "Distinguishing comment"] +dap_check_request_and_response "set breakpoint by line number" \ + setBreakpoints \ + [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \ + [list s $srcfile] $line] + +set cancel_id [dap_send_request cancel \ + [format {o requestId [i %d]} $launch_id]] + +dap_read_response cancel $cancel_id + +# The cancellation isn't actually processed until configurationDone is +# sent. While this seems fine, it's unclear if gdb should be more +# eager here and try to cancel a deferred task before it is +# rescheduled. +dap_check_request_and_response "configurationDone" configurationDone + +dap_read_response launch $launch_id + +dap_shutdown diff --git a/gdb/testsuite/gdb.dap/catch-exception.exp b/gdb/testsuite/gdb.dap/catch-exception.exp index a1ced06cad2d108983452b391650e6f6c6c685a3..97937466c406b374fa16c33406e846ca3ea1a90f 100644 --- a/gdb/testsuite/gdb.dap/catch-exception.exp +++ b/gdb/testsuite/gdb.dap/catch-exception.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set exception catchpoints" \ setExceptionBreakpoints \ {o filters [a [s nosuchfilter] [s assert]] \ @@ -69,9 +71,8 @@ foreach spec $bps { dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $binfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at first raise" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" 2 diff --git a/gdb/testsuite/gdb.dap/children.exp b/gdb/testsuite/gdb.dap/children.exp index f5dfe2cbb91e57183989a63b61351ec332f71d30..783fff98ce91dd342ebd03f70cb74af4cedbdf89 100644 --- a/gdb/testsuite/gdb.dap/children.exp +++ b/gdb/testsuite/gdb.dap/children.exp @@ -36,6 +36,8 @@ save_vars GDBFLAGS { } } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "STOP"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -45,9 +47,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $line_bpno diff --git a/gdb/testsuite/gdb.dap/cond-bp.exp b/gdb/testsuite/gdb.dap/cond-bp.exp index 2bd52ba83a0d6d62b56e3616b0998ffb7f3d2f2b..28d4b8e8ff3663fca99f8cf67525a0dbf143d8ea 100644 --- a/gdb/testsuite/gdb.dap/cond-bp.exp +++ b/gdb/testsuite/gdb.dap/cond-bp.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "STOP"] # Test some breakpoint-setting failure modes. @@ -65,9 +67,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $fn_bpno diff --git a/gdb/testsuite/gdb.dap/cwd.exp b/gdb/testsuite/gdb.dap/cwd.exp index 6b8829965c522c7e34fea0e93566e42f07c8dcba..b3c9f9c21dea99c8bfffadb226f71d664574dac1 100644 --- a/gdb/testsuite/gdb.dap/cwd.exp +++ b/gdb/testsuite/gdb.dap/cwd.exp @@ -29,14 +29,14 @@ if {[dap_initialize] == ""} { return } -dap_check_request_and_response "configurationDone" configurationDone - # Starting the inferior will fail if the change of cwd does not work. set the_dir [file dirname $testfile] set the_file [file tail $testfile] -if {[dap_launch $the_file cwd $the_dir stop_at_main 1] == ""} { - return -} +set launch_id [dap_launch $the_file cwd $the_dir stop_at_main 1] + +dap_check_request_and_response "configurationDone" configurationDone + +dap_check_response "launch response" launch $launch_id # We didn't explicitly set a breakpoint, so if we hit one, it worked. dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/cxx-exception.exp b/gdb/testsuite/gdb.dap/cxx-exception.exp index 13320439b6d5b9343a806ea9a4bd19cc052a3ff0..c79c5dba6a70dc0fcb8b0f83533f7eac233c974b 100644 --- a/gdb/testsuite/gdb.dap/cxx-exception.exp +++ b/gdb/testsuite/gdb.dap/cxx-exception.exp @@ -28,6 +28,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set exception catchpoints" \ setExceptionBreakpoints \ {o filters [a [s throw] [s rethrow] [s catch]]}] @@ -49,9 +51,8 @@ foreach bp $bps { dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at throw" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" 1 diff --git a/gdb/testsuite/gdb.dap/disassem.exp b/gdb/testsuite/gdb.dap/disassem.exp index 87fb516931a4e85cb317e0a54d81aa9966ad1b97..6fdfc6358cf72baadb6d54755e5b75e14fd88f99 100644 --- a/gdb/testsuite/gdb.dap/disassem.exp +++ b/gdb/testsuite/gdb.dap/disassem.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set breakpoint" \ setFunctionBreakpoints \ {o breakpoints [a [o name [s main]]]}] @@ -36,9 +38,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/frameless.exp b/gdb/testsuite/gdb.dap/frameless.exp index 63ee521af656ae441a9a211f7af687d55d2ecf87..6963eed62c4e78912c05f0ebbb51f4a1d0f99e26 100644 --- a/gdb/testsuite/gdb.dap/frameless.exp +++ b/gdb/testsuite/gdb.dap/frameless.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -38,9 +40,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ diff --git a/gdb/testsuite/gdb.dap/global.exp b/gdb/testsuite/gdb.dap/global.exp index 79f7f2facf570c41764ed70d2d8908ea84c90299..2704f46cfaf0c56be83a08934d53016fdc9680a3 100644 --- a/gdb/testsuite/gdb.dap/global.exp +++ b/gdb/testsuite/gdb.dap/global.exp @@ -27,6 +27,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -36,9 +38,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/hover.exp b/gdb/testsuite/gdb.dap/hover.exp index 0c80650b152e3636244aba0f8a9df007b8d26cf0..f637c4a06d108bb0353e094dca58aa65fb2e29a4 100644 --- a/gdb/testsuite/gdb.dap/hover.exp +++ b/gdb/testsuite/gdb.dap/hover.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -38,9 +40,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/insn-bp.exp b/gdb/testsuite/gdb.dap/insn-bp.exp index 4a4c14484e176fb9d3026462f5758e0d9103da9c..6542262b21d11722fdfc053c75387445e053857e 100644 --- a/gdb/testsuite/gdb.dap/insn-bp.exp +++ b/gdb/testsuite/gdb.dap/insn-bp.exp @@ -39,6 +39,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set breakpoint on main" \ setFunctionBreakpoints \ {o breakpoints [a [o name [s main]]]}] @@ -56,14 +58,12 @@ gdb_assert {[dict get $bp verified] == "false"} \ dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} - # The event we're looking for should occur during startup, but we want # to leave open the possibility that it occurs when waiting for the -# stopped event. So, keep both event lists around and search them +# stopped event. So, keep all event lists around and search them # once below. +lassign [dap_check_response "launch response" launch $launch_id] \ + unused objs0 lassign [dap_wait_for_event_and_check "inferior started" \ thread "body reason" started] \ unused objs1 @@ -72,7 +72,7 @@ lassign [dap_wait_for_event_and_check "stopped at breakpoint" stopped \ "body hitBreakpointIds" $fn_bpno] unused objs2 set found_bp_event 0 -foreach obj [concat $objs1 $objs2] { +foreach obj [concat $objs0 $objs1 $objs2] { if { [dict get $obj "type"] != "event" } { continue } diff --git a/gdb/testsuite/gdb.dap/lazy-string.exp b/gdb/testsuite/gdb.dap/lazy-string.exp index 54422209fdacbda59c9b932991733377e4b07351..d070347e760bc44b37a77a4abcb5d06599784329 100644 --- a/gdb/testsuite/gdb.dap/lazy-string.exp +++ b/gdb/testsuite/gdb.dap/lazy-string.exp @@ -36,6 +36,8 @@ save_vars GDBFLAGS { } } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "STOP"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -45,9 +47,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $line_bpno diff --git a/gdb/testsuite/gdb.dap/log-message.exp b/gdb/testsuite/gdb.dap/log-message.exp index e966b962a7128d43943c8d2aca420eb9603ded75..a0070afdb2ff28e94afd2e2f6a02cfe71d3a9211 100644 --- a/gdb/testsuite/gdb.dap/log-message.exp +++ b/gdb/testsuite/gdb.dap/log-message.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "HERE"] set obj [dap_check_request_and_response "set breakpoint" \ setBreakpoints \ @@ -40,9 +42,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "logging output" output \ diff --git a/gdb/testsuite/gdb.dap/memory.exp b/gdb/testsuite/gdb.dap/memory.exp index c4e4fb3238b55f194a6041b6da8c427e47a58b4b..89ae8bb7b1a3ba681281906900ac2df3cfd6bd39 100644 --- a/gdb/testsuite/gdb.dap/memory.exp +++ b/gdb/testsuite/gdb.dap/memory.exp @@ -37,6 +37,8 @@ save_vars { env(ASAN_OPTIONS) env(TSAN_OPTIONS) } { } } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -46,9 +48,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/modules.exp b/gdb/testsuite/gdb.dap/modules.exp index 87cebda7131f2ac829f1c3c5479ce87ec7eff54a..2e41679e691fe3252bd0391cc63cac03b661f0b6 100644 --- a/gdb/testsuite/gdb.dap/modules.exp +++ b/gdb/testsuite/gdb.dap/modules.exp @@ -42,6 +42,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set breakpoint on stop function" \ setFunctionBreakpoints \ {o breakpoints [a [o name [s stop]]]}] @@ -49,9 +51,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $fn_bpno diff --git a/gdb/testsuite/gdb.dap/pause.exp b/gdb/testsuite/gdb.dap/pause.exp index 9038d0f037fcc7fa16fc25b79a1f5fbd3a86c780..c74fea3ebfd95496c4763d91646240c2c220f1c8 100644 --- a/gdb/testsuite/gdb.dap/pause.exp +++ b/gdb/testsuite/gdb.dap/pause.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + # Set a conditional breakpoint that will never fire. This is done to # test the state-tracking in events -- an inferior call from a # breakpoint condition should not cause any sort of stop or continue @@ -43,9 +45,8 @@ dap_check_request_and_response "set conditional breakpoint" \ dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "process event generated" process \ "body startMethod" process dap_wait_for_event_and_check "inferior started" thread "body reason" started diff --git a/gdb/testsuite/gdb.dap/ptrref.exp b/gdb/testsuite/gdb.dap/ptrref.exp index 236ffae12d54f02b1dfc1a2ad74a0ff69ad6ab39..2a972aca0455b52fdaba5924bd552bf1fd09aec5 100644 --- a/gdb/testsuite/gdb.dap/ptrref.exp +++ b/gdb/testsuite/gdb.dap/ptrref.exp @@ -27,6 +27,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -36,9 +38,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/remote-dap.exp b/gdb/testsuite/gdb.dap/remote-dap.exp index 5c28a045e7032433e0389c32964efa31ddc6078e..bca66dd10550a7349e7b5cf0143959e01555e04f 100644 --- a/gdb/testsuite/gdb.dap/remote-dap.exp +++ b/gdb/testsuite/gdb.dap/remote-dap.exp @@ -42,8 +42,12 @@ lassign [gdbserver_start "" $target_exec] protocol port gdb_assert {$protocol == "remote"} # We just want to test that attaching works at all. -if {[dap_target_remote $port] != ""} { - dap_shutdown true -} +set attach_id [dap_target_remote $port] + +dap_check_request_and_response "configurationDone" configurationDone + +dap_check_response "attach response" attach $attach_id + +dap_shutdown true close_gdbserver diff --git a/gdb/testsuite/gdb.dap/rust-slices.exp b/gdb/testsuite/gdb.dap/rust-slices.exp index 4af8c11e6848372621db80334250f7d064b6f14c..1ed640a9af179be01ce552af0dc5b0dfbdaf827d 100644 --- a/gdb/testsuite/gdb.dap/rust-slices.exp +++ b/gdb/testsuite/gdb.dap/rust-slices.exp @@ -32,6 +32,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "STOP"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -41,9 +43,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/scopes.exp b/gdb/testsuite/gdb.dap/scopes.exp index aa3bb688c0e85f0492b578b40f3d235a1a4fb95f..a8a0c01690eda1758bdf94763169f85c574ddb2f 100644 --- a/gdb/testsuite/gdb.dap/scopes.exp +++ b/gdb/testsuite/gdb.dap/scopes.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -38,9 +40,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/sources.exp b/gdb/testsuite/gdb.dap/sources.exp index ee853cc68aab636bb22a93ee53afe4b4ca9bfd45..305a27c72616d11c4bd4d94a4049114d486a0c30 100644 --- a/gdb/testsuite/gdb.dap/sources.exp +++ b/gdb/testsuite/gdb.dap/sources.exp @@ -29,14 +29,16 @@ if {[dap_initialize] == ""} { return } -if {[dap_launch $testfile stop_at_main 1] == ""} { - return -} +set launch_id [dap_launch $testfile stop_at_main 1] -proc do_tests {} { - dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ - "body reason" breakpoint +dap_check_request_and_response "configurationDone" configurationDone +dap_check_response "launch response" launch $launch_id + +dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ + "body reason" breakpoint + +proc do_tests {} { set obj [dap_check_request_and_response loadedSources loadedSources] if { $obj == "" } { return diff --git a/gdb/testsuite/gdb.dap/stack-format.exp b/gdb/testsuite/gdb.dap/stack-format.exp index b81183a016ebb8b1aa0bbf571d602ab4de26ebab..4056e1f1f68f96f34685226269757ad2b04854b9 100644 --- a/gdb/testsuite/gdb.dap/stack-format.exp +++ b/gdb/testsuite/gdb.dap/stack-format.exp @@ -36,6 +36,8 @@ save_vars GDBFLAGS { } } +set launch_id [dap_launch $testfile] + set line [gdb_get_line_number "BREAK"] set obj [dap_check_request_and_response "set breakpoint by line number" \ setBreakpoints \ @@ -45,9 +47,8 @@ set line_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $line_bpno diff --git a/gdb/testsuite/gdb.dap/step-out.exp b/gdb/testsuite/gdb.dap/step-out.exp index 193264fa2504238d80b430bf511ed31b989f1842..cfe730e03f16bcc2b12a40906966bf908b7526ef 100644 --- a/gdb/testsuite/gdb.dap/step-out.exp +++ b/gdb/testsuite/gdb.dap/step-out.exp @@ -29,6 +29,8 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + set obj [dap_check_request_and_response "set breakpoint on function" \ setFunctionBreakpoints \ {o breakpoints [a [o name [s function_breakpoint_here]]]}] @@ -36,9 +38,8 @@ set fn_bpno [dap_get_breakpoint_number $obj] dap_check_request_and_response "configurationDone" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ diff --git a/gdb/testsuite/gdb.dap/stop-at-main.exp b/gdb/testsuite/gdb.dap/stop-at-main.exp index 4c3e57a23e4407443f72c43d51be49c4e5a06607..52b94f40c678686f120b15482efe73d508f0ed3b 100644 --- a/gdb/testsuite/gdb.dap/stop-at-main.exp +++ b/gdb/testsuite/gdb.dap/stop-at-main.exp @@ -29,11 +29,12 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile stop_at_main 1] + dap_check_request_and_response "start inferior" configurationDone -if {[dap_launch $testfile stop_at_main 1] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + # We didn't explicitly set a breakpoint, so if we hit one, it worked. dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ "body reason" breakpoint diff --git a/gdb/testsuite/gdb.dap/terminate.exp b/gdb/testsuite/gdb.dap/terminate.exp index 90d01945a64cec480258612694dc4c84ab02ebe9..9872351a292f6d7e22d123e3b5249326342da4f0 100644 --- a/gdb/testsuite/gdb.dap/terminate.exp +++ b/gdb/testsuite/gdb.dap/terminate.exp @@ -31,11 +31,12 @@ if {[dap_initialize] == ""} { return } +set launch_id [dap_launch $testfile] + dap_check_request_and_response "start inferior" configurationDone -if {[dap_launch $testfile] == ""} { - return -} +dap_check_response "launch response" launch $launch_id + dap_wait_for_event_and_check "inferior started" thread "body reason" started dap_wait_for_event_and_check "terminated event" terminated diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index 61355b56fee70f43b3e637dc4eed4f2c09e2fac2..0e481ac083d073a5f1491d2d59ce1f323b601e4e 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -248,10 +248,10 @@ proc dap_request_and_response {command {obj {}}} { return [dap_read_response $command $seq] } -# Like dap_request_and_response, but also checks that the response -# indicates success. NAME is used to issue a test result. -proc dap_check_request_and_response {name command {obj {}}} { - set response_and_events [dap_request_and_response $command $obj] +# Wait for a response to the given request, and issue a pass/fail. +# Returns the response and events like dap_request_and_response. +proc dap_check_response {name cmd request} { + set response_and_events [dap_read_response $cmd $request] set response [lindex $response_and_events 0] if {[dict get $response success] != "true"} { verbose "request failure: $response" @@ -262,6 +262,13 @@ proc dap_check_request_and_response {name command {obj {}}} { return $response_and_events } +# Like dap_request_and_response, but also checks that the response +# indicates success. NAME is used to issue a test result. +proc dap_check_request_and_response {name command {obj {}}} { + set seq [dap_send_request $command $obj] + return [dap_check_response $name $command $seq] +} + # Start gdb, send a DAP initialization request and return the # response. This approach lets the caller check the feature list, if # desired. Returns the empty string on failure. NAME is used as the @@ -278,10 +285,9 @@ proc dap_initialize {{name "initialize"}} { } # Send a launch request specifying FILE as the program to use for the -# inferior. Returns the empty string on failure, or the response -# object from the launch request. If specified, ARGS is a dictionary -# of key-value pairs, each passed to the launch request. Valid keys -# are: +# inferior. Returns the request ID. If specified, ARGS is a +# dictionary of key-value pairs, each passed to the launch request. +# Valid keys are: # # * arguments - value is a list of strings passed as command-line # arguments to the inferior @@ -334,12 +340,12 @@ proc dap_launch {file {args {}}} { } } - return [dap_check_request_and_response "startup - launch" launch $params] + return [dap_send_request launch $params] } # Start gdb, send a DAP initialize request, and then an attach request # specifying PID as the inferior process ID. Returns the empty string -# on failure, or the response object from the attach request. +# on failure, or the attach request sequence ID. proc dap_attach {pid {prog ""}} { if {[dap_initialize "startup - initialize"] == ""} { return "" @@ -350,18 +356,17 @@ proc dap_attach {pid {prog ""}} { append args [format { program [s %s]} $prog] } - return [dap_check_request_and_response "startup - attach" attach $args] + return [dap_send_request attach $args] } # Start gdb, send a DAP initialize request, and then an attach request # specifying TARGET as the remote target. Returns the empty string on -# failure, or the response object from the attach request. +# failure, or the attach request sequence ID. proc dap_target_remote {target} { if {[dap_initialize "startup - initialize"] == ""} { return "" } - return [dap_check_request_and_response "startup - target" attach \ - [format {o target [s %s]} $target]] + return [dap_send_request attach [format {o target [s %s]} $target]] } # Read the most recent DAP log file and check it for exceptions.