public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v1] [gdb/python]: Add StepEndedEvent (simplifies DAP)
@ 2023-10-16 11:50 Simon Farre
  2023-10-16 12:11 ` Eli Zaretskii
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Simon Farre @ 2023-10-16 11:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: tromey, Simon Farre

Adds the StepEndedEvent which signals that one of the thread finite state machines
finished. Matches the behavior of what is generated by MI; the "end stepping range".

This should simplify some of the DAP code, where "expected stop reason" is being tracked.
This logic should be handled by the Python interpreter to begin with, instead.
---
 gdb/NEWS                      |  3 +++
 gdb/doc/python.texi           |  3 +++
 gdb/python/py-event-types.def |  5 +++++
 gdb/python/py-stopevent.c     | 17 +++++++++++++++++
 4 files changed, 28 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index 81264c0cfb3..b2abaa6a2ce 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -11,6 +11,9 @@
   ** New function gdb.notify_mi(NAME, DATA), that emits custom
      GDB/MI async notification.
 
+  ** Added StepEndedEvent which is emitted during stops where it could be determined
+     that what triggered the stop was that the stepping state machine finished.
+
 *** Changes in GDB 14
 
 * GDB now supports the AArch64 Scalable Matrix Extension 2 (SME2), which
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 546b4d4b962..c6968791eb1 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3733,6 +3733,9 @@ registry extend @code{gdb.StopEvent}.  As a child of
 thread when @value{GDBN} is running in non-stop mode.  Refer to
 @code{gdb.ThreadEvent} above for more details.
 
+Emits @code{gdb.StepEndedEvent} that signals that this stop event was generated
+because one of the step-like commands finished.
+
 Emits @code{gdb.SignalEvent}, which extends @code{gdb.StopEvent}.
 
 This event indicates that the inferior or one of its threads has
diff --git a/gdb/python/py-event-types.def b/gdb/python/py-event-types.def
index c6225115027..36146b181c5 100644
--- a/gdb/python/py-event-types.def
+++ b/gdb/python/py-event-types.def
@@ -106,6 +106,11 @@ GDB_PY_DEFINE_EVENT_TYPE (signal,
 			  "GDB signal event object",
 			  stop_event_object_type);
 
+GDB_PY_DEFINE_EVENT_TYPE (step_ended,
+			  "StepEndedEvent",
+			  "GDB step ended event object",
+			  stop_event_object_type);
+
 GDB_PY_DEFINE_EVENT_TYPE (stop,
 			  "StopEvent",
 			  "GDB stop event object",
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index 0aa9d5381f8..13e1b12d33a 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -18,6 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "mi/mi-common.h"
 #include "py-stopevent.h"
 
 gdbpy_ref<>
@@ -27,6 +28,21 @@ create_stop_event_object (PyTypeObject *py_type)
   return create_thread_event_object (py_type, thread.get ());
 }
 
+/** If thread finite state machine reports that it has finished, inform
+    the Python-interpreter of this. */
+
+static gdbpy_ref<> maybe_create_step_ended () 
+{
+  const auto tp = inferior_thread();
+  const auto fsm = tp != nullptr ? tp->thread_fsm() : nullptr;
+  if (fsm != nullptr && fsm->finished_p () && 
+	fsm->async_reply_reason () == EXEC_ASYNC_END_STEPPING_RANGE)
+    {
+      return create_stop_event_object (&step_ended_event_object_type);
+    }
+   return nullptr;
+}
+
 /* Callback observers when a stop event occurs.  This function will create a
    new Python stop event object.  If only a specific thread is stopped the
    thread object of the event will be set to that thread.  Otherwise, if all
@@ -86,6 +102,7 @@ emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal)
 	return -1;
     }
 
+  stop_event_obj = maybe_create_step_ended();
   /* If all fails emit an unknown stop event.  All event types should
      be known and this should eventually be unused.  */
   if (stop_event_obj == NULL)
-- 
2.41.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-14 18:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-16 11:50 [PATCH v1] [gdb/python]: Add StepEndedEvent (simplifies DAP) Simon Farre
2023-10-16 12:11 ` Eli Zaretskii
2023-10-16 15:01 ` Andrew Burgess
2023-10-16 16:09   ` Simon Farre
2023-10-16 18:36 ` Tom Tromey
2023-11-14 18:43 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).