public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 04/30] gdb: add interp::on_normal_stop method
Date: Tue,  2 May 2023 16:49:44 -0400	[thread overview]
Message-ID: <20230502205011.132151-5-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230502205011.132151-1-simon.marchi@efficios.com>

Same idea as the previous patch, but for the normal_stop event.

Change-Id: I4fc8ca8a51c63829dea390a2b6ce30b77f9fb863
---
 gdb/cli/cli-interp.c | 21 +++++-------------
 gdb/cli/cli-interp.h |  1 +
 gdb/infrun.c         | 19 +++++++++++------
 gdb/infrun.h         |  4 ++++
 gdb/interps.c        |  8 +++++++
 gdb/interps.h        |  7 ++++++
 gdb/mi/mi-interp.c   | 51 ++++++++++++++------------------------------
 gdb/mi/mi-interp.h   |  1 +
 gdb/remote.c         |  3 ++-
 9 files changed, 57 insertions(+), 58 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 51c78d96ee20..9508171e87d5 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -112,10 +112,8 @@ should_print_stop_to_console (struct interp *console_interp,
    interpreter-exec), print nothing.  These are named "cli_base" as
    they print to both CLI interpreters and TUI interpreters.  */
 
-/* Observer for the normal_stop notification.  */
-
-static void
-cli_base_on_normal_stop (struct bpstat *bs, int print_frame)
+void
+cli_interp_base::on_normal_stop (struct bpstat *bs, int print_frame)
 {
   if (!print_frame)
     return;
@@ -124,17 +122,10 @@ cli_base_on_normal_stop (struct bpstat *bs, int print_frame)
   if (cli_suppress_notification.normal_stop)
     return;
 
-  SWITCH_THRU_ALL_UIS ()
-    {
-      struct interp *interp = top_level_interpreter ();
-      cli_interp_base *cli = as_cli_interp_base (interp);
-      if (cli == nullptr)
-	continue;
+  thread_info *thread = inferior_thread ();
+  if (should_print_stop_to_console (this, thread))
+    print_stop_event (this->interp_ui_out ());
 
-      thread_info *thread = inferior_thread ();
-      if (should_print_stop_to_console (interp, thread))
-	print_stop_event (cli->interp_ui_out ());
-    }
 }
 
 void
@@ -397,8 +388,6 @@ _initialize_cli_interp ()
   interp_factory_register (INTERP_CONSOLE, cli_interp_factory);
 
   /* Note these all work for both the CLI and TUI interpreters.  */
-  gdb::observers::normal_stop.attach (cli_base_on_normal_stop,
-				      "cli-interp-base");
   gdb::observers::signal_exited.attach (cli_base_on_signal_exited,
 					"cli-interp-base");
   gdb::observers::exited.attach (cli_base_on_exited, "cli-interp-base");
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index f7bee4530b42..4fca801d4fd6 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -34,6 +34,7 @@ class cli_interp_base : public interp
   bool supports_command_editing () override;
 
   void on_signal_received (gdb_signal sig) override;
+  void on_normal_stop(bpstat *bs, int print_frame) override;
 
 private:
   struct saved_output_files
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4716d73571c5..8fa2cacc4149 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -6273,6 +6273,15 @@ notify_signal_received (gdb_signal sig)
   gdb::observers::signal_received.notify (sig);
 }
 
+/* See infrun.h.  */
+
+void
+notify_normal_stop (bpstat *bs, int print_frame)
+{
+  interps_notify_normal_stop (bs, print_frame);
+  gdb::observers::normal_stop.notify (bs, print_frame);
+}
+
 /* Come here when the program has stopped with a signal.  */
 
 static void
@@ -8955,12 +8964,10 @@ normal_stop ()
 
   /* Notify observers about the stop.  This is where the interpreters
      print the stop event.  */
-  if (inferior_ptid != null_ptid)
-    gdb::observers::normal_stop.notify (inferior_thread ()->control.stop_bpstat,
-					stop_print_frame);
-  else
-    gdb::observers::normal_stop.notify (nullptr, stop_print_frame);
-
+  notify_normal_stop ((inferior_ptid != null_ptid
+		       ? inferior_thread ()->control.stop_bpstat
+		       : nullptr),
+		      stop_print_frame);
   annotate_stopped ();
 
   if (target_has_execution ())
diff --git a/gdb/infrun.h b/gdb/infrun.h
index f7b60a4d9fb7..cbafc3ea4407 100644
--- a/gdb/infrun.h
+++ b/gdb/infrun.h
@@ -214,6 +214,10 @@ extern void set_step_info (thread_info *tp,
    signal SIG.  */
 extern void notify_signal_received (gdb_signal sig);
 
+/* Notify interpreters and observers that the current inferior has stopped
+   normally.  */
+extern void notify_normal_stop (bpstat *bs, int print_frame);
+
 /* Several print_*_reason helper functions to print why the inferior
    has stopped to the passed in UIOUT.  */
 
diff --git a/gdb/interps.c b/gdb/interps.c
index 5d061ad52aff..80160bc45f34 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -406,6 +406,14 @@ interps_notify_signal_received (gdb_signal sig)
   interps_notify (&interp::on_signal_received, sig);
 }
 
+/* See interps.h.  */
+
+void
+interps_notify_normal_stop (bpstat *bs, int print_frame)
+{
+  interps_notify (&interp::on_normal_stop, bs, print_frame);
+}
+
 /* This just adds the "interpreter-exec" command.  */
 void _initialize_interpreter ();
 void
diff --git a/gdb/interps.h b/gdb/interps.h
index 4762c4c93ff1..dd5a9b70e339 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -24,6 +24,7 @@
 
 #include "gdbsupport/intrusive_list.h"
 
+struct bpstat;
 struct ui_out;
 struct interp;
 struct ui;
@@ -86,6 +87,9 @@ class interp : public intrusive_list_node<interp>
      SIG.  */
   virtual void on_signal_received (gdb_signal sig) {}
 
+  /* Notify the interpreter that the current inferior has stopped normally.  */
+  virtual void on_normal_stop (bpstat *bs, int print_frame) {}
+
 private:
   /* The memory for this is static, it comes from literal strings (e.g. "cli").  */
   const char *m_name;
@@ -178,6 +182,9 @@ extern void interpreter_completer (struct cmd_list_element *ignore,
    SIG.  */
 extern void interps_notify_signal_received (gdb_signal sig);
 
+/* Notify all interpreters that the current inferior has stopped normally.  */
+extern void interps_notify_normal_stop (bpstat *bs, int print_frame);
+
 /* well-known interpreters */
 #define INTERP_CONSOLE		"console"
 #define INTERP_MI2             "mi2"
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 43e49a9b94af..5aeba46c4c28 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -62,7 +62,6 @@ static void mi_remove_notify_hooks (void);
 
 static void mi_on_signal_exited (enum gdb_signal siggnal);
 static void mi_on_exited (int exitstatus);
-static void mi_on_normal_stop (struct bpstat *bs, int print_frame);
 static void mi_on_no_history (void);
 
 static void mi_new_thread (struct thread_info *t);
@@ -581,33 +580,28 @@ mi_on_no_history (void)
     }
 }
 
-static void
-mi_on_normal_stop_1 (struct bpstat *bs, int print_frame)
+void
+mi_interp::on_normal_stop (struct bpstat *bs, int print_frame)
 {
   /* Since this can be called when CLI command is executing,
      using cli interpreter, be sure to use MI uiout for output,
      not the current one.  */
-  struct ui_out *mi_uiout = top_level_interpreter ()->interp_ui_out ();
-  struct mi_interp *mi = (struct mi_interp *) top_level_interpreter ();
+  struct ui_out *mi_uiout = this->interp_ui_out ();
 
   if (print_frame)
     {
-      struct thread_info *tp;
-      int core;
-      struct interp *console_interp;
-
-      tp = inferior_thread ();
+      thread_info *tp = inferior_thread ();
 
       if (tp->thread_fsm () != nullptr
 	  && tp->thread_fsm ()->finished_p ())
 	{
-	  enum async_reply_reason reason;
-
-	  reason = tp->thread_fsm ()->async_reply_reason ();
+	  async_reply_reason reason
+	    = tp->thread_fsm ()->async_reply_reason ();
 	  mi_uiout->field_string ("reason", async_reason_lookup (reason));
 	}
 
-      console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
+      interp *console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
+
       /* We only want to print the displays once, and we want it to
 	 look just how it would on the console, so we use this to
 	 decide whether the MI stop should include them.  */
@@ -615,7 +609,7 @@ mi_on_normal_stop_1 (struct bpstat *bs, int print_frame)
       print_stop_event (mi_uiout, !console_print);
 
       if (console_print)
-	print_stop_event (mi->cli_uiout);
+	print_stop_event (this->cli_uiout);
 
       mi_uiout->field_signed ("thread-id", tp->global_num);
       if (non_stop)
@@ -627,29 +621,17 @@ mi_on_normal_stop_1 (struct bpstat *bs, int print_frame)
       else
 	mi_uiout->field_string ("stopped-threads", "all");
 
-      core = target_core_of_thread (tp->ptid);
+      int core = target_core_of_thread (tp->ptid);
       if (core != -1)
 	mi_uiout->field_signed ("core", core);
     }
-  
-  gdb_puts ("*stopped", mi->raw_stdout);
-  mi_out_put (mi_uiout, mi->raw_stdout);
-  mi_out_rewind (mi_uiout);
-  mi_print_timing_maybe (mi->raw_stdout);
-  gdb_puts ("\n", mi->raw_stdout);
-  gdb_flush (mi->raw_stdout);
-}
 
-static void
-mi_on_normal_stop (struct bpstat *bs, int print_frame)
-{
-  SWITCH_THRU_ALL_UIS ()
-    {
-      if (as_mi_interp (top_level_interpreter ()) == NULL)
-	continue;
-
-      mi_on_normal_stop_1 (bs, print_frame);
-    }
+  gdb_puts ("*stopped", this->raw_stdout);
+  mi_out_put (mi_uiout, this->raw_stdout);
+  mi_out_rewind (mi_uiout);
+  mi_print_timing_maybe (this->raw_stdout);
+  gdb_puts ("\n", this->raw_stdout);
+  gdb_flush (this->raw_stdout);
 }
 
 static void
@@ -1302,7 +1284,6 @@ _initialize_mi_interp ()
   gdb::observers::inferior_exit.attach (mi_inferior_exit, "mi-interp");
   gdb::observers::inferior_removed.attach (mi_inferior_removed, "mi-interp");
   gdb::observers::record_changed.attach (mi_record_changed, "mi-interp");
-  gdb::observers::normal_stop.attach (mi_on_normal_stop, "mi-interp");
   gdb::observers::target_resumed.attach (mi_on_resume, "mi-interp");
   gdb::observers::solib_loaded.attach (mi_solib_loaded, "mi-interp");
   gdb::observers::solib_unloaded.attach (mi_solib_unloaded, "mi-interp");
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index 75c17568d6fc..444625f22c88 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -43,6 +43,7 @@ class mi_interp final : public interp
   void pre_command_loop () override;
 
   void on_signal_received (gdb_signal sig) override;
+  void on_normal_stop (struct bpstat *bs, int print_frame) override;
 
   /* MI's output channels */
   mi_console_file *out;
diff --git a/gdb/remote.c b/gdb/remote.c
index 829cdbdef757..ec0dba239303 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4722,7 +4722,8 @@ remote_target::print_one_stopped_thread (thread_info *thread)
       if (signal_print_state (sig))
 	notify_signal_received (sig);
     }
-  gdb::observers::normal_stop.notify (NULL, 1);
+
+  notify_normal_stop (nullptr, 1);
 }
 
 /* Process all initial stop replies the remote side sent in response
-- 
2.40.1


  parent reply	other threads:[~2023-05-02 20:50 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 20:49 [PATCH 00/30] Switch interpreters to use virtual methods Simon Marchi
2023-05-02 20:49 ` [PATCH 01/30] gdb/mi: fix ^running record with multiple MI interpreters Simon Marchi
2023-05-03 14:42   ` Alexandra Petlanova Hajkova
2023-05-03 15:02     ` Simon Marchi
2023-05-29 14:53   ` Simon Marchi
2023-05-02 20:49 ` [PATCH 02/30] gdb/mi: make current_token a field of mi_interp Simon Marchi
2023-05-04 12:31   ` Alexandra Petlanova Hajkova
2023-05-02 20:49 ` [PATCH 03/30] gdb: add interp::on_signal_received method Simon Marchi
2023-05-04 14:38   ` Alexandra Petlanova Hajkova
2023-05-02 20:49 ` Simon Marchi [this message]
2023-05-02 20:49 ` [PATCH 05/30] gdb: add interp::on_signal_exited method Simon Marchi
2023-05-02 20:49 ` [PATCH 06/30] gdb: add interp::on_exited method Simon Marchi
2023-05-02 20:49 ` [PATCH 07/30] gdb: add interp::on_no_history method Simon Marchi
2023-05-02 20:49 ` [PATCH 08/30] gdb: add interp::on_sync_execution_done method Simon Marchi
2023-05-02 20:49 ` [PATCH 09/30] gdb: add interp::on_command_error method Simon Marchi
2023-05-02 20:49 ` [PATCH 10/30] gdb: add interp::on_user_selected_context_changed method Simon Marchi
2023-05-02 20:49 ` [PATCH 11/30] gdb: add interp::on_new_thread method Simon Marchi
2023-05-02 20:49 ` [PATCH 12/30] gdb: add interp::on_thread_exited method Simon Marchi
2023-05-02 20:49 ` [PATCH 13/30] gdb: add interp::on_inferior_added method Simon Marchi
2023-05-02 20:49 ` [PATCH 14/30] gdb: add interp::on_inferior_appeared method Simon Marchi
2023-05-02 20:49 ` [PATCH 15/30] gdb: add interp::on_inferior_disappeared method Simon Marchi
2023-05-02 20:49 ` [PATCH 16/30] gdb: add interp::on_inferior_removed method Simon Marchi
2023-05-02 20:49 ` [PATCH 17/30] gdb: add interp::on_record_changed method Simon Marchi
2023-05-02 20:49 ` [PATCH 18/30] gdb: add interp::on_target_resumed method Simon Marchi
2023-05-02 20:49 ` [PATCH 19/30] gdb: add interp::on_solib_loaded method Simon Marchi
2023-05-02 20:50 ` [PATCH 20/30] gdb: add interp::on_solib_unloaded method Simon Marchi
2023-05-02 20:50 ` [PATCH 21/30] gdb: add interp::on_about_to_proceed method Simon Marchi
2023-05-02 20:50 ` [PATCH 22/30] gdb: add interp::on_traceframe_changed method Simon Marchi
2023-05-02 20:50 ` [PATCH 23/30] gdb: add interp::on_tsv_created method Simon Marchi
2023-05-02 20:50 ` [PATCH 24/30] gdb: add interp::on_tsv_deleted method Simon Marchi
2023-05-02 20:50 ` [PATCH 25/30] gdb: add interp::on_tsv_modified method Simon Marchi
2023-05-02 20:50 ` [PATCH 26/30] gdb: add interp::on_breakpoint_created method Simon Marchi
2023-05-02 20:50 ` [PATCH 27/30] gdb: add interp::on_breakpoint_deleted method Simon Marchi
2023-05-02 20:50 ` [PATCH 28/30] gdb: add interp::on_breakpoint_modified method Simon Marchi
2023-05-02 20:50 ` [PATCH 29/30] gdb: add interp::on_param_changed method Simon Marchi
2023-05-02 20:50 ` [PATCH 30/30] gdb: add interp::on_memory_changed method Simon Marchi
2023-05-02 20:50 ` [PATCH 00/30] Make interpreters use virtual methods (instead of observers) Simon Marchi
2023-05-23 12:43 ` [PATCH 00/30] Switch interpreters to use virtual methods Simon Marchi
2023-05-30 19:09   ` Simon Marchi

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=20230502205011.132151-5-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).