From patchwork Wed Jan 17 16:20:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84262 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 D029B3858403 for ; Wed, 17 Jan 2024 16:20:51 +0000 (GMT) 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 D52AD3858C66 for ; Wed, 17 Jan 2024 16:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D52AD3858C66 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 D52AD3858C66 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=1705508429; cv=none; b=LxqIIJbCmre43vnNrTYwmzGZn6GCmq9vu6dEXZqLdlgbIZn5buwuNgG6/xYfxRWP78vdNEi2YC2wdcP1mJk2syMLs221/Z0MFMR32IlonzepQdzZhocLHBkF0FHeL0MRNJ0sNahBPrn3CffFloeq+69pBLUDPRiR6NeKdDVY43U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705508429; c=relaxed/simple; bh=D+lNkPJgSTFJP1LCfhzxy7staCvvHiJQXnk38FM/hyg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=H18ym/lPnXyHMDEECQdtZpjQdM+r/uGjFfI2CUM8UnrMdVs8Rq6cJH8s1KhMv+uv8BV+GIsCUkaERtvwojJ07rv37m4tNliEA8js6jazEyKDxLPlV5MWSd1qie5l4/zLytW0IDZBWw3Foh/2gy8jiBCd1eB/DpkWbIOPc4RtE0k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7bed9c7d33fso294537039f.1 for ; Wed, 17 Jan 2024 08:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1705508426; x=1706113226; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sn8d0z/Nh+SBt3n8uvRIXnrDHqQ5TeUIwtJB8Lh3fxY=; b=g8CorWiWKh1oYxtWnXFxaRdwTvQCjN8LoarEN5Y/pkH369LyeTM5xp5B0DY5cidoYQ SRtZeB5annpKMQLXORVBjflGKZNKly1jKpfrFvWYdrTzHUBP/fwZYI1K+GnlqcjiXfTj Gj0cNkIWfsp9K2Bq6zOPFYkQ9IgjVfA76I/dqe5rLNSDWX1wyk6zDhw0jLbjc9LmGgeQ ETqytGxCFAJwF01Pw0QBzhbuyCa5vZ4NpMn22wap5HQ/r2k6sf8BT8iqBZ+DVkaiK7iI 2dE38Mf3+HW8i5l9pNYLtr0LuaC6ZE0YR6dm0fz1mbMCKSIpR+DpKg2Kqgu9jZVU7Iro oi5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705508426; x=1706113226; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sn8d0z/Nh+SBt3n8uvRIXnrDHqQ5TeUIwtJB8Lh3fxY=; b=kDcFxjFIUP2nn36+OK3g/JxcYhqdgu2n9JLH8tH4SKWDRH4gduz7bKK5BActlMk1Um szBgTg7n/Wx/8op3NcRen/hV3iA853aiBcgiHIlY38jdnRez99xfBwfAiCf+RVjStdPP qBa8HhHQJEutZjqAdCqnrXMA5wk/UqUaPUDRSEn6MC8CZehMI019mVU4TMoyp/KldqHM YrE+yKOE9vxfRF6ve/hucyHjc7GxoLFsdauNUaXSc7caMPx2uihbc2+eYrQmYZWX58fH g1quDXaJDKg84cO5NuWNBfrTTO6bZjaK5lEVz+C13Ud0Cv16UopvOlIh6H9mpopc7OBX 9P0A== X-Gm-Message-State: AOJu0YyBotEAGMfScdvUHFjJgkgG5AqyB3QUpYtt4DkOV2ozibZDNxAO aHETfctClG7DOrMR6xaHTB//eA58zwLBbEvwOOymCF5DXg== X-Google-Smtp-Source: AGHT+IFx/h4P2fnwswQPgQYd4wJLwGSHMotf/28TKPzgc/iLfCOJaU3n/2aZCWheuYXjLhafTf3GcQ== X-Received: by 2002:a05:6602:1648:b0:7bb:2f0a:2a2c with SMTP id y8-20020a056602164800b007bb2f0a2a2cmr11496610iow.12.1705508426007; Wed, 17 Jan 2024 08:20:26 -0800 (PST) Received: from localhost.localdomain (97-122-68-157.hlrn.qwest.net. [97.122.68.157]) by smtp.gmail.com with ESMTPSA id n26-20020a056602341a00b007bef3151723sm3399876ioz.16.2024.01.17.08.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 08:20:25 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Emit stopped event for DAP attach request Date: Wed, 17 Jan 2024 09:20:14 -0700 Message-ID: <20240117162014.2927548-1-tromey@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 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 In an earlier patch, I wrote: ... It also adds some machinery so that attach stops can be suppressed, which I think is the right thing to do. However, after some discussions here at AdaCore, I now believe this to be incorrect -- while DAP says that expected "continue" events should be suppressed, there is no corresponding language for expected "stop" events, and indeed "stop" events explicitly mention cases like "step". This patch arranges for the stop event to be emitted again. --- gdb/python/lib/gdb/dap/events.py | 28 +++++++++++++--------------- gdb/python/lib/gdb/dap/launch.py | 4 ++-- gdb/testsuite/gdb.dap/attach.exp | 16 +++++++++++++--- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index bb2d1c9d342..41302229ee5 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -147,14 +147,14 @@ def _cont(event): ) -_suppress_stop = False +_expected_stop_reason = None @in_gdb_thread -def suppress_stop(): - """Indicate that the next stop should not emit an event.""" - global _suppress_stop - _suppress_stop = True +def expect_stop(reason: str): + """Indicate that the next stop should be for REASON.""" + global _expected_stop_reason + _expected_stop_reason = reason _expected_pause = False @@ -209,24 +209,22 @@ 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)) + if hasattr(event, "details"): + log(" details: " + repr(event.details)) obj = { "threadId": gdb.selected_thread().global_num, "allThreadsStopped": True, } if isinstance(event, gdb.BreakpointEvent): obj["hitBreakpointIds"] = [x.number for x in event.breakpoints] + global _expected_pause - # Some stop events still do not emit details. For example, - # 'attach' causes a reason-less stop. - if "reason" not in event.details: + global _expected_stop_reason + if _expected_stop_reason is not None: + obj["reason"] = _expected_stop_reason + _expected_stop_reason = None + elif "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. diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index bf9640a4d92..184af16955c 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, suppress_stop +from .events import exec_and_expect_stop, expect_process, expect_stop from .server import request, capability from .startup import exec_and_log, DAPException @@ -88,7 +88,7 @@ def attach( else: raise DAPException("attach requires either 'pid' or 'target'") expect_process("attach") - suppress_stop() + expect_stop("attach") exec_and_log(cmd) diff --git a/gdb/testsuite/gdb.dap/attach.exp b/gdb/testsuite/gdb.dap/attach.exp index 2b30e53cce0..ce2a16c1193 100644 --- a/gdb/testsuite/gdb.dap/attach.exp +++ b/gdb/testsuite/gdb.dap/attach.exp @@ -28,9 +28,19 @@ if {[build_executable ${testfile}.exp $testfile] == -1} { set test_spawn_id [spawn_wait_for_attach $binfile] set testpid [spawn_id_get_pid $test_spawn_id] -# We just want to test that attaching works at all. -if {[dap_attach $testpid $binfile] != ""} { - dap_shutdown true +# 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" + +dap_shutdown true kill_wait_spawned_process $test_spawn_id