From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id C1C0C3858CD1 for ; Tue, 14 Nov 2023 18:44:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1C0C3858CD1 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 C1C0C3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987449; cv=none; b=BpPQH4m6GJYB8nT78mGOSdVmZqY1ko/lAopVj1Erf07T+6T5/wihmYU8fgpMkNx92k8P7o9lCVvYUDG1MnoNZMT2jx7LUtfaGnTI1YsMKGmdoJFtmGWc5dxpu2XMeMnH2Y/uzjbAHryYo7cWdPrUs3XWvU6bHLRVOOZ7/rtq5TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987449; c=relaxed/simple; bh=TxrLMdttqSFaaYomlwSWR7SwKBo7wwHRyJjnBp8dEaw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=P2P6jiwPiV0151/4MsfuDnMEmogPAVRG6sVpzSaPdH1913hKMlGGI1LzJu8lyeeliJfRlmNiZA4cTk5Ha3GvxRgKu9GqFdk4Hs1T2bD9kkQfXSH4F3rAVdueP21HaMCpB1osuz0hQzrm9BQdoj3+J8IbGxXAyjRu8Y0PgVJ7t3M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7afff3ea94dso184729839f.3 for ; Tue, 14 Nov 2023 10:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699987447; x=1700592247; 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=akdQa/FlNRu6qUaNtTGdAovd9pls1oOWrc9QwkbOcys=; b=R/HY5Q8ji9SRFuOmoB1s7If/kxkgwOVju1x0LqKgC2dJs2mWz86sYeG1GsDOw8Qb9r ROl2GtImEJ+SvPKMCD3CkCjuPqj36Ydt6DaWie46F5VMu6t5++SVD0tAOpSBvEOVhgEQ o+U7HoWvKEuCee23H5ygEpm1mmutk8KE6Ed2YFdFHoEOJZhJeUmQiPo5NmDj7i/8pEY5 HxFWRjVvJmuRpLvfnYoMtm3KNMIHKUDu/9H5Ge0mKFr0lu5IVE359otJaS8CL9HKQmjv Mr15HnkYT1rT2hKtqxktuTVhjNJCsl7Mpd9coefPeS7wCAZRmwiAiZ3+J20SHr2dqOAA mvZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699987447; x=1700592247; 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=akdQa/FlNRu6qUaNtTGdAovd9pls1oOWrc9QwkbOcys=; b=HKnGCSCK9atCb34SRJmAi1Cr9ox9kylJQtgUjl7tQGFNgKctC6nHB5R7fO3H1qrkkg 1iP760UdgDno5i/G0bEiscspF0Bs7Tkpao9l69JIZWNUCyz6J4nEfWXQD0OtVqkLSP4x pxOIFZZFPrEOUkzaS832Ydv2aEsxL2R/IMnlCLjpcHXxOGfh0sf/GMLOZvNLSWszf6Sg qA0WJmGXkL+tc6rnUKZ5jw3uGMFoFMZfZw7efAoVAYJFEHXGi0FMYBkPTdC1m6tjWCzc 4XvYBkRsUrCnj8ydj4JEFVQL3upoKUHHcwD4IphtLOgagb2V7rPljC0FWi3x8v8vssp/ a18A== X-Gm-Message-State: AOJu0Yw+YPSZH84ufww00quSiWvnE2B2QosCdzUIKrIwoxzlfo6RMTmx 3ic/2rLnPwykX7tB2w65HJv6HHmi43f4d38ri9/IPw== X-Google-Smtp-Source: AGHT+IFeunLcv0yidKwsHM+XnirUPTN4cNqcds3oM0a822vIRq2qQwceVaix4s1QCXWdnjfauXl3Yw== X-Received: by 2002:a05:6e02:1d96:b0:359:4199:1fe2 with SMTP id h22-20020a056e021d9600b0035941991fe2mr15563314ila.8.1699987446961; Tue, 14 Nov 2023 10:44:06 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id e97-20020a02866a000000b0043194542229sm528513jai.52.2023.11.14.10.44.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 10:44:06 -0800 (PST) From: Tom Tromey Date: Tue, 14 Nov 2023 11:44:05 -0700 Subject: [PATCH 3/3] Simplify DAP stop-reason code MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231114-py-stop-reason-v1-3-4ff440c956a9@adacore.com> References: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> In-Reply-To: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Now that gdb adds stop-reason details to stop events, we can simplify the DAP code to emit correct stop reasons in its own events. For the most part a simple renaming of gdb reasons is sufficient; however, "pause" must still be handled specially. --- gdb/python/lib/gdb/dap/events.py | 79 +++++++++++++++++++++++++--------------- gdb/python/lib/gdb/dap/launch.py | 4 +- gdb/python/lib/gdb/dap/next.py | 10 ++--- gdb/python/lib/gdb/dap/pause.py | 4 +- 4 files changed, 57 insertions(+), 40 deletions(-) diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index e9ddcab135f..bdd2a6ebadc 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -99,60 +99,79 @@ def _cont(event): ) -class StopKinds(enum.Enum): - # The values here are chosen to follow the DAP spec. - STEP = "step" - BREAKPOINT = "breakpoint" - PAUSE = "pause" - EXCEPTION = "exception" - - -_expected_stop = None - - -@in_gdb_thread -def expect_stop(reason): - """Indicate that a stop is expected, for the reason given.""" - global _expected_stop - _expected_stop = reason +_expected_pause = False # A wrapper for Invoker that also sets the expected stop. class ExecutionInvoker(Invoker): - """A subclass of Invoker that sets the expected stop. - Note that this assumes that the command will restart the inferior, - so it will also cause ContinuedEvents to be suppressed.""" + """A subclass of Invoker that sets the continue-suppression flag. - def __init__(self, cmd, expected): + When EXPECTED_PAUSE is True, a stop that looks like a pause (e.g., + a SIGINT) will be reported as "pause" instead. + """ + + def __init__(self, cmd, expected_pause=False): super().__init__(cmd) - self.expected = expected + self.expected_pause = expected_pause @in_gdb_thread def __call__(self): - expect_stop(self.expected) + global _expected_pause + _expected_pause = self.expected_pause global _suppress_cont _suppress_cont = True # FIXME if the call fails should we clear _suppress_cont? super().__call__() +# Map from gdb stop reasons to DAP stop reasons. Some of these can't +# be seen ordinarily in DAP -- only if the client lets the user toggle +# some settings (e.g. stop-on-solib-events) or enter commands (e.g., +# 'until'). +stop_reason_map = { + "breakpoint-hit": "breakpoint", + "watchpoint-trigger": "data breakpoint", + "read-watchpoint-trigger": "data breakpoint", + "access-watchpoint-trigger": "data breakpoint", + "function-finished": "step", + "location-reached": "step", + "watchpoint-scope": "data breakpoint", + "end-stepping-range": "step", + "exited-signalled": "exited", + "exited": "exited", + "exited-normally": "exited", + "signal-received": "signal", + "solib-event": "solib", + "fork": "fork", + "vfork": "vfork", + "syscall-entry": "syscall-entry", + "syscall-return": "syscall-return", + "exec": "exec", + "no-history": "no-history", +} + + @in_gdb_thread def _on_stop(event): log("entering _on_stop: " + repr(event)) - global _expected_stop + log(" details: " + repr(event.details)) obj = { "threadId": gdb.selected_thread().global_num, "allThreadsStopped": True, } if isinstance(event, gdb.BreakpointEvent): - # Ignore the expected stop, we hit a breakpoint instead. - _expected_stop = StopKinds.BREAKPOINT obj["hitBreakpointIds"] = [x.number for x in event.breakpoints] - elif _expected_stop is None: - # FIXME what is even correct here - _expected_stop = StopKinds.EXCEPTION - obj["reason"] = _expected_stop.value - _expected_stop = None + 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" + else: + obj["reason"] = stop_reason_map[reason] send_event("stopped", obj) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index d13037fa476..7dead0c7c35 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -88,6 +88,4 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): def config_done(**args): global _program if _program is not None: - # Suppress the continue event, but don't set any particular - # expected stop. - send_gdb(ExecutionInvoker("run", None)) + send_gdb(ExecutionInvoker("run")) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index e5bb8d64da0..76c9360383a 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -15,7 +15,7 @@ import gdb -from .events import StopKinds, ExecutionInvoker +from .events import ExecutionInvoker from .server import capability, request from .startup import in_gdb_thread, send_gdb, send_gdb_with_response from .state import set_thread @@ -57,7 +57,7 @@ def next( cmd = "next" if granularity == "instruction": cmd += "i" - send_gdb(ExecutionInvoker(cmd, StopKinds.STEP)) + send_gdb(ExecutionInvoker(cmd)) @capability("supportsSteppingGranularity") @@ -70,17 +70,17 @@ def step_in( cmd = "step" if granularity == "instruction": cmd += "i" - send_gdb(ExecutionInvoker(cmd, StopKinds.STEP)) + send_gdb(ExecutionInvoker(cmd)) @request("stepOut") def step_out(*, threadId: int, singleThread: bool = False, **args): send_gdb(lambda: _handle_thread_step(threadId, singleThread, True)) - send_gdb(ExecutionInvoker("finish", StopKinds.STEP)) + send_gdb(ExecutionInvoker("finish")) @request("continue") def continue_request(*, threadId: int, singleThread: bool = False, **args): locked = send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread)) - send_gdb(ExecutionInvoker("continue", None)) + send_gdb(ExecutionInvoker("continue")) return {"allThreadsContinued": not locked} diff --git a/gdb/python/lib/gdb/dap/pause.py b/gdb/python/lib/gdb/dap/pause.py index 1e59d630523..a89741cbf69 100644 --- a/gdb/python/lib/gdb/dap/pause.py +++ b/gdb/python/lib/gdb/dap/pause.py @@ -13,11 +13,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from .events import StopKinds, ExecutionInvoker +from .events import ExecutionInvoker from .server import request from .startup import send_gdb @request("pause") def pause(**args): - send_gdb(ExecutionInvoker("interrupt -a", StopKinds.PAUSE)) + send_gdb(ExecutionInvoker("interrupt -a", True)) -- 2.41.0