public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Farre <simon.farre.cx@gmail.com>
To: gdb-patches@sourceware.org
Cc: tom@tromey.com, Simon Farre <simon.farre.cx@gmail.com>
Subject: [PATCH v2] [gdb/python]: Add StepEndedEvent (simplifies DAP)
Date: Mon, 16 Oct 2023 17:50:09 +0200	[thread overview]
Message-ID: <20231016155009.156773-1-simon.farre.cx@gmail.com> (raw)

Bug fix at py-stopevent.c:105.

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     | 20 ++++++++++++++++++++
 4 files changed, 31 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..b000ff17bf9 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,10 @@ emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal)
 	return -1;
     }
 
+  /* Must first make sure an event has not already been created. */
+  if (stop_event_obj == nullptr)
+    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


             reply	other threads:[~2023-10-16 15:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16 15:50 Simon Farre [this message]
2023-10-16 19:05 ` Eli Zaretskii

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=20231016155009.156773-1-simon.farre.cx@gmail.com \
    --to=simon.farre.cx@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).