Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] Remove ExecutionInvoker
Date: Tue, 07 Nov 2023 11:29:30 -0700	[thread overview]
Message-ID: <20231107-dap-not-stopped-v1-2-3d91c935255d@adacore.com> (raw)
In-Reply-To: <20231107-dap-not-stopped-v1-0-3d91c935255d@adacore.com>

ExecutionInvoker is no longer really needed, due to the previous DAP
refactoring.  This patch removes it in favor of an ordinary function.
One spot (the 'continue' request) could still have used it, but is
more succinctly expressed as a lambda.
---
 gdb/python/lib/gdb/dap/events.py | 29 +++++++----------------------
 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, 16 insertions(+), 31 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py
index e9ddcab135f..09214ec3dc8 100644
--- a/gdb/python/lib/gdb/dap/events.py
+++ b/gdb/python/lib/gdb/dap/events.py
@@ -17,7 +17,7 @@ import enum
 import gdb
 
 from .server import send_event
-from .startup import in_gdb_thread, Invoker, log
+from .startup import exec_and_log, in_gdb_thread, log
 from .modules import is_module, make_module
 
 
@@ -111,29 +111,14 @@ _expected_stop = None
 
 
 @in_gdb_thread
-def expect_stop(reason):
-    """Indicate that a stop is expected, for the reason given."""
+def exec_and_expect_stop(cmd, reason):
+    """Indicate that a stop is expected, then execute CMD"""
     global _expected_stop
     _expected_stop = reason
-
-
-# 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."""
-
-    def __init__(self, cmd, expected):
-        super().__init__(cmd)
-        self.expected = expected
-
-    @in_gdb_thread
-    def __call__(self):
-        expect_stop(self.expected)
-        global _suppress_cont
-        _suppress_cont = True
-        # FIXME if the call fails should we clear _suppress_cont?
-        super().__call__()
+    global _suppress_cont
+    _suppress_cont = True
+    # FIXME if the call fails should we clear _suppress_cont?
+    exec_and_log(cmd)
 
 
 @in_gdb_thread
diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py
index e81d2849a8e..ab704c7a7cc 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 ExecutionInvoker
+from .events import exec_and_expect_stop
 from .server import request, capability
 from .startup import in_gdb_thread, exec_and_log
 
@@ -85,4 +85,4 @@ def config_done(**args):
     if _program is not None:
         # Suppress the continue event, but don't set any particular
         # expected stop.
-        ExecutionInvoker("run", None)()
+        exec_and_expect_stop("run", None)
diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py
index ddab9d304a1..d12267ea354 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 StopKinds, exec_and_expect_stop
 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"
-    ExecutionInvoker(cmd, StopKinds.STEP)()
+    exec_and_expect_stop(cmd, StopKinds.STEP)
 
 
 @capability("supportsSteppingGranularity")
@@ -70,13 +70,13 @@ def step_in(
     cmd = "step"
     if granularity == "instruction":
         cmd += "i"
-    ExecutionInvoker(cmd, StopKinds.STEP)()
+    exec_and_expect_stop(cmd, StopKinds.STEP)
 
 
 @request("stepOut", response=False)
 def step_out(*, threadId: int, singleThread: bool = False, **args):
     _handle_thread_step(threadId, singleThread, True)
-    ExecutionInvoker("finish", StopKinds.STEP)()
+    exec_and_expect_stop("finish", StopKinds.STEP)
 
 
 # This is a server-side request because it is funny: it wants to
@@ -87,5 +87,5 @@ def step_out(*, threadId: int, singleThread: bool = False, **args):
 @request("continue", server=True)
 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(lambda: exec_and_expect_stop("continue", None))
     return {"allThreadsContinued": not locked}
diff --git a/gdb/python/lib/gdb/dap/pause.py b/gdb/python/lib/gdb/dap/pause.py
index d96172c0757..d276ab1cb92 100644
--- a/gdb/python/lib/gdb/dap/pause.py
+++ b/gdb/python/lib/gdb/dap/pause.py
@@ -13,10 +13,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from .events import StopKinds, ExecutionInvoker
+from .events import StopKinds, exec_and_expect_stop
 from .server import request
 
 
 @request("pause", response=False)
 def pause(**args):
-    ExecutionInvoker("interrupt -a", StopKinds.PAUSE)()
+    exec_and_expect_stop("interrupt -a", StopKinds.PAUSE)

-- 
2.41.0


  parent reply	other threads:[~2023-11-07 18:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 18:29 [PATCH 0/3] Implement the DAP notStopped response Tom Tromey
2023-11-07 18:29 ` [PATCH 1/3] Automatically run (most) DAP requests in gdb thread Tom Tromey
2023-11-13 12:59   ` Alexandra Petlanova Hajkova
2023-11-07 18:29 ` Tom Tromey [this message]
2023-11-13 13:57   ` [PATCH 2/3] Remove ExecutionInvoker Alexandra Petlanova Hajkova
2023-11-07 18:29 ` [PATCH 3/3] Implement the notStopped DAP response Tom Tromey
2023-11-08  8:23   ` Kévin Le Gouguec
2023-11-10 14:52     ` Tom Tromey
2023-11-10 15:14       ` Kévin Le Gouguec
2023-11-10 15:18         ` Tom Tromey
2023-11-10 15:08     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231107-dap-not-stopped-v1-2-3d91c935255d@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox