From patchwork Tue Dec 12 17:44:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81994 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 36250385B836 for ; Tue, 12 Dec 2023 17:45:02 +0000 (GMT) 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 46EF3385841A for ; Tue, 12 Dec 2023 17:44:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46EF3385841A Authentication-Results: sourceware.org; dmarc=pass (p=none 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 46EF3385841A 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=1702403087; cv=none; b=l6KjOJuQAUMATzud5HDcJBbTmGSIddyEh0NbNOMG6d3HIH73UOFxTg+FH42Fd990+1Fgo8PQHVinx12Umdr4kGC9pf9ut/cVx96eHIFA3R/6nIKNBlxEQ4VYP3ySppD2S0dR6WWpm5Fjx92FoyWWfEstW69zhOPkmN2Gv6Ihm5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403087; c=relaxed/simple; bh=hoDEA6sxfW1je5mpL8IUfqEC0wjCcV0PTIPHINmON+o=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=DAFXne7STq87iZXldBSr9s1220w6B3TVlI4RFmevUo/1ZIJL4EfcFDu0aZ7CI2tu9SIiCEhbN3qrHR9BZAflIq4oOGYf7iZGuG0DcP4lOJE3Qya8lMf6fqJhslDZt62l8+n4xOGp734X3eO0y9/LPqTsN0/TRZ9HStpXF0V6o/A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7b75f681237so62459139f.0 for ; Tue, 12 Dec 2023 09:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702403085; x=1703007885; 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=cXGhii8N9wgVqvm+mdeAlYmIg3VUoPaCmU8xRnuHZTY=; b=TghZaVlcmJ7bt/emE1sDMtA3HebY79uRrwbEsYgfMzjiLffXWrQr2pJ+3yxk0/Cwu9 bgFxD/chRdY/dAD5QrZRxw/+/Cu0oWJ1w1VYo2GJFhyDQ89XponGItYgCyPR/1UNdxiX Sl3ldiCOrjdyxLNsmPsV8sbgXEN7CJlbpkJ8ZTWPnxbC/30odDfl/1TQzY1CF4iGW98k 3CxQAEoGQb1IXxaiG/1hBfidCiCwOnvG9x9kX68xjcCZhUNDHtcjZxDHlAuNEWgWaYX0 Jk0TOCVk4rKRQp/nM65mCxmNLn59zDqg0UPjGgs6y30RQ4PpqtNGwI4VKCEA5oYClKUq vlow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702403085; x=1703007885; 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=cXGhii8N9wgVqvm+mdeAlYmIg3VUoPaCmU8xRnuHZTY=; b=X9Lt6gY501CN86KH11MeTmlrRSPCgaY404XePBjIIBq1hyTcwJ5hup/vx+EXJfehhi yGz/wtCwr3AEyvXAt4lsSYEksCW0eZ4MPc30mlbWxHuqV/IiTOEbDdqACfGyLw89z0c/ ADZzOE6JZDF4pjYoyyzffd8GfIlwuHagiCz8XH02dG9OKwahqY5u/elXAdRW8JL9HETN x+diq1xGYMhrZ24EgUUTNUb69iQeoaDQfjlSRpiiahurWx9/Us2gobgw/dOidDcXfXbm zRcnNkTDIMGogwvyK+qmOQ+8YPvtTVwPKpBgxFkTuElJ7UUfKAYw2/IVbxcwD0yymEyJ SOQA== X-Gm-Message-State: AOJu0YyR0arZyWQixBDWlK0wpzgkU/WwmR7ejJ/yv2+iehqGTlFl5x/m 7A4dLQ/f7zKHxSe0/ZT5OlJ2rJz6avmCeINNycA= X-Google-Smtp-Source: AGHT+IEJz3w29kARwNjGsWLp2/vxhHU5nyuBKDNAR6o604AMdUe39HvPkhBJwDkGg9T/TBMbjKggTQ== X-Received: by 2002:a05:6e02:148a:b0:35d:5128:d379 with SMTP id n10-20020a056e02148a00b0035d5128d379mr8457100ilk.24.1702403085512; Tue, 12 Dec 2023 09:44:45 -0800 (PST) Received: from localhost.localdomain (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id u26-20020a02aa9a000000b004693a30f295sm2479819jai.170.2023.12.12.09.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:44:45 -0800 (PST) From: Tom Tromey Date: Tue, 12 Dec 2023 10:44:44 -0700 Subject: [PATCH 3/4] Avoid exception from attach in DAP MIME-Version: 1.0 Message-Id: <20231212-dap-no-test-exceptions-v1-3-af0e33f10093@adacore.com> References: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> In-Reply-To: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.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 I noticed that the DAP attach test case (and similarly remoted-dap.exp) had a rogue exception stack trace in the log. It turns out that an attach will generate a stop that does not have a reason. This patch fixes the problem in the _on_stop event listener by making it a bit more careful when examining the event reason. It also adds some machinery so that attach stops can be suppressed, which I think is the right thing to do. Reviewed-By: Kévin Le Gouguec --- gdb/python/lib/gdb/dap/events.py | 43 +++++++++++++++++++++++++++++++--------- gdb/python/lib/gdb/dap/launch.py | 3 ++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index cbefe90e4ca..82fe99632d5 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -147,6 +147,16 @@ def _cont(event): ) +_suppress_stop = False + + +@in_gdb_thread +def suppress_stop(): + """Indicate that the next stop should not emit an event.""" + global _suppress_stop + _suppress_stop = True + + _expected_pause = False @@ -198,6 +208,13 @@ stop_reason_map = { def _on_stop(event): global inferior_running inferior_running = False + + global _suppress_stop + if _suppress_stop: + _suppress_stop = False + log("suppressing stop in _on_stop") + return + log("entering _on_stop: " + repr(event)) log(" details: " + repr(event.details)) obj = { @@ -206,17 +223,25 @@ def _on_stop(event): } if isinstance(event, gdb.BreakpointEvent): obj["hitBreakpointIds"] = [x.number for x in event.breakpoints] - global stop_reason_map - reason = event.details["reason"] global _expected_pause - if ( - _expected_pause - and reason == "signal-received" - and event.details["signal-name"] in ("SIGINT", "SIGSTOP") - ): - obj["reason"] = "pause" + # Some stop events still do not emit details. For example, + # 'attach' causes a reason-less stop. + if "reason" not in event.details: + # This can only really happen via a "repl" evaluation of + # something like "attach". In this case just emit a generic + # stop. + obj["reason"] = "stopped" else: - obj["reason"] = stop_reason_map[reason] + reason = event.details["reason"] + if ( + _expected_pause + and reason == "signal-received" + and event.details["signal-name"] in ("SIGINT", "SIGSTOP") + ): + obj["reason"] = "pause" + else: + global stop_reason_map + obj["reason"] = stop_reason_map[reason] _expected_pause = False send_event("stopped", obj) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index a8adb125707..a20009c190d 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -18,7 +18,7 @@ import gdb # These are deprecated in 3.9, but required in older versions. from typing import Mapping, Optional, Sequence -from .events import exec_and_expect_stop, expect_process +from .events import exec_and_expect_stop, expect_process, suppress_stop from .server import request, capability from .startup import exec_and_log, DAPException @@ -71,6 +71,7 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): else: raise DAPException("attach requires either 'pid' or 'target'") expect_process("attach") + suppress_stop() exec_and_log(cmd)