[21/30] gdb: add interp::on_about_to_proceed method

Message ID 20230502205011.132151-22-simon.marchi@efficios.com
State New
Headers
Series Switch interpreters to use virtual methods |

Commit Message

Simon Marchi May 2, 2023, 8:50 p.m. UTC
  Same idea as previous patches, but for about_to_proceed.  We only need
(and want, as far as the mi_interp implementation is concerned) to
notify the interpreter that caused the proceed.

Change-Id: Id259bca10dbc3d43d46607ff7b95243a9cbe2f89
---
 gdb/infrun.c       | 12 +++++++++++-
 gdb/interps.h      |  4 ++++
 gdb/mi/mi-interp.c | 13 +++----------
 gdb/mi/mi-interp.h |  1 +
 4 files changed, 19 insertions(+), 11 deletions(-)
  

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index aa2d34aa6b35..aeeae8b50fd8 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2893,6 +2893,16 @@  clear_proceed_status_thread (struct thread_info *tp)
   bpstat_clear (&tp->control.stop_bpstat);
 }
 
+/* Notify the current interpreter and observers that the target is about to
+   proceed.  */
+
+static void
+notify_about_to_proceed ()
+{
+  top_level_interpreter ()->on_about_to_proceed ();
+  gdb::observers::about_to_proceed.notify ();
+}
+
 void
 clear_proceed_status (int step)
 {
@@ -2935,7 +2945,7 @@  clear_proceed_status (int step)
       inferior->control.stop_soon = NO_STOP_QUIETLY;
     }
 
-  gdb::observers::about_to_proceed.notify ();
+  notify_about_to_proceed ();
 }
 
 /* Returns true if TP is still stopped at a breakpoint that needs
diff --git a/gdb/interps.h b/gdb/interps.h
index 3339ae3d3013..a88c40581bb3 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -149,6 +149,10 @@  class interp : public intrusive_list_node<interp>
   /* Notify the interpreter that solib SO has been unloaded.  */
   virtual void on_solib_unloaded (so_list *so) {}
 
+  /* Notify the interpreter that a command it is executing is about to cause
+     the inferior to proceed.  */
+  virtual void on_about_to_proceed () {}
+
 private:
   /* The memory for this is static, it comes from literal strings (e.g. "cli").  */
   const char *m_name;
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 8be165e21544..40a1fc93b48d 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -60,7 +60,6 @@  static int mi_interp_query_hook (const char *ctlstr, va_list ap)
 static void mi_insert_notify_hooks (void);
 static void mi_remove_notify_hooks (void);
 
-static void mi_about_to_proceed (void);
 static void mi_traceframe_changed (int tfnum, int tpnum);
 static void mi_tsv_created (const struct trace_state_variable *tsv);
 static void mi_tsv_deleted (const struct trace_state_variable *tsv);
@@ -468,8 +467,8 @@  mi_interp::on_normal_stop (struct bpstat *bs, int print_frame)
   gdb_flush (this->raw_stdout);
 }
 
-static void
-mi_about_to_proceed (void)
+void
+mi_interp::on_about_to_proceed ()
 {
   /* Suppress output while calling an inferior function.  */
 
@@ -481,12 +480,7 @@  mi_about_to_proceed (void)
 	return;
     }
 
-  mi_interp *mi = as_mi_interp (top_level_interpreter ());
-
-  if (mi == nullptr)
-    return;
-
-  mi->mi_proceeded = 1;
+  this->mi_proceeded = 1;
 }
 
 /* When the element is non-zero, no MI notifications will be emitted in
@@ -1060,7 +1054,6 @@  _initialize_mi_interp ()
   interp_factory_register (INTERP_MI4, mi_interp_factory);
   interp_factory_register (INTERP_MI, mi_interp_factory);
 
-  gdb::observers::about_to_proceed.attach (mi_about_to_proceed, "mi-interp");
   gdb::observers::traceframe_changed.attach (mi_traceframe_changed,
 					     "mi-interp");
   gdb::observers::tsv_created.attach (mi_tsv_created, "mi-interp");
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index 08a47523272c..2bb6840e786f 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -61,6 +61,7 @@  class mi_interp final : public interp
   void on_target_resumed (ptid_t ptid) override;
   void on_solib_loaded (so_list *so) override;
   void on_solib_unloaded (so_list *so) override;
+  void on_about_to_proceed () override;
 
   /* MI's output channels */
   mi_console_file *out;