[28/30] gdb: add interp::on_breakpoint_modified method

Message ID 20230502205011.132151-29-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 breakpoint_modified.

Change-Id: I4f0a9edea912de431e32451d74224b2022a7c328
---
 gdb/breakpoint.c      | 47 ++++++++++++++++++++++++++-----------------
 gdb/breakpoint.h      |  5 +++++
 gdb/interps.c         |  8 ++++++++
 gdb/interps.h         |  6 ++++++
 gdb/mi/mi-cmd-break.c |  2 +-
 gdb/mi/mi-interp.c    | 28 +++++++-------------------
 gdb/mi/mi-interp.h    |  1 +
 gdb/tracepoint.c      |  4 ++--
 8 files changed, 58 insertions(+), 43 deletions(-)
  

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 430e3b959ddf..853fe4978256 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1002,6 +1002,15 @@  set_breakpoint_location_condition (const char *cond_string, bp_location *loc,
     error (_("Garbage '%s' follows condition"), cond_string);
 }
 
+/* See breakpoint.h.  */
+
+void
+notify_breakpoint_modified (breakpoint *b)
+{
+  interps_notify_breakpoint_modified (b);
+  gdb::observers::breakpoint_modified.notify (b);
+}
+
 void
 set_breakpoint_condition (struct breakpoint *b, const char *exp,
 			  int from_tty, bool force)
@@ -1094,7 +1103,7 @@  set_breakpoint_condition (struct breakpoint *b, const char *exp,
     }
   mark_breakpoint_modified (b);
 
-  gdb::observers::breakpoint_modified.notify (b);
+  notify_breakpoint_modified (b);
 }
 
 /* See breakpoint.h.  */
@@ -1438,7 +1447,7 @@  breakpoint_set_commands (struct breakpoint *b,
   validate_commands_for_breakpoint (b, commands.get ());
 
   b->commands = std::move (commands);
-  gdb::observers::breakpoint_modified.notify (b);
+  notify_breakpoint_modified (b);
 }
 
 /* Set the internal `silent' flag on the breakpoint.  Note that this
@@ -1452,7 +1461,7 @@  breakpoint_set_silent (struct breakpoint *b, int silent)
 
   b->silent = silent;
   if (old_silent != silent)
-    gdb::observers::breakpoint_modified.notify (b);
+    notify_breakpoint_modified (b);
 }
 
 /* See breakpoint.h.  */
@@ -1469,7 +1478,7 @@  breakpoint_set_thread (struct breakpoint *b, int thread)
 
   b->thread = thread;
   if (old_thread != thread)
-    gdb::observers::breakpoint_modified.notify (b);
+    notify_breakpoint_modified (b);
 }
 
 /* See breakpoint.h.  */
@@ -1486,7 +1495,7 @@  breakpoint_set_task (struct breakpoint *b, int task)
 
   b->task = task;
   if (old_task != task)
-    gdb::observers::breakpoint_modified.notify (b);
+    notify_breakpoint_modified (b);
 }
 
 static void
@@ -1555,7 +1564,7 @@  commands_command_1 (const char *arg, int from_tty,
 	 {
 	   validate_commands_for_breakpoint (b, cmd.get ());
 	   b->commands = cmd;
-	   gdb::observers::breakpoint_modified.notify (b);
+	   notify_breakpoint_modified (b);
 	 }
      });
 }
@@ -2893,7 +2902,7 @@  insert_bp_location (struct bp_location *bl,
 	    {
 	      /* See also: disable_breakpoints_in_shlibs.  */
 	      bl->shlib_disabled = 1;
-	      gdb::observers::breakpoint_modified.notify (bl->owner);
+	      notify_breakpoint_modified (bl->owner);
 	      if (!*disabled_breaks)
 		{
 		  gdb_printf (tmp_error_stream, 
@@ -5599,7 +5608,7 @@  bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
       bs->stop = false;
       /* Increase the hit count even though we don't stop.  */
       ++(b->hit_count);
-      gdb::observers::breakpoint_modified.notify (b);
+      notify_breakpoint_modified (b);
       return;
     }
 
@@ -5762,7 +5771,7 @@  bpstat_stop_status (const address_space *aspace,
 		    b->enable_state = bp_disabled;
 		  removed_any = 1;
 		}
-	      gdb::observers::breakpoint_modified.notify (b);
+	      notify_breakpoint_modified (b);
 	      if (b->silent)
 		bs->print = false;
 	      bs->commands = b->commands;
@@ -7893,7 +7902,7 @@  disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
 	  loc->inserted = 0;
 
 	  /* This may cause duplicate notifications for the same breakpoint.  */
-	  gdb::observers::breakpoint_modified.notify (b);
+	  notify_breakpoint_modified (b);
 
 	  if (!disabled_shlib_breaks)
 	    {
@@ -7973,7 +7982,7 @@  disable_breakpoints_in_freed_objfile (struct objfile *objfile)
 	}
 
       if (bp_modified)
-	gdb::observers::breakpoint_modified.notify (b);
+	notify_breakpoint_modified (b);
     }
 }
 
@@ -11095,7 +11104,7 @@  download_tracepoint_locations (void)
       t = (struct tracepoint *) b;
       t->number_on_target = b->number;
       if (bp_location_downloaded)
-	gdb::observers::breakpoint_modified.notify (b);
+	notify_breakpoint_modified (b);
     }
 }
 
@@ -12863,7 +12872,7 @@  update_breakpoint_locations (code_breakpoint *b,
   }
 
   if (!locations_are_equal (existing_locations, b->loc))
-    gdb::observers::breakpoint_modified.notify (b);
+    notify_breakpoint_modified (b);
 }
 
 /* Find the SaL locations corresponding to the given LOCSPEC.
@@ -13111,7 +13120,7 @@  set_ignore_count (int bptnum, int count, int from_tty)
 			    "crossings of breakpoint %d."),
 			  count, bptnum);
 	  }
-	gdb::observers::breakpoint_modified.notify (b);
+	notify_breakpoint_modified (b);
 	return;
       }
 
@@ -13365,7 +13374,7 @@  enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
     }
   update_global_location_list (UGLL_DONT_INSERT);
 
-  gdb::observers::breakpoint_modified.notify (loc->owner);
+  notify_breakpoint_modified (loc->owner);
 }
 
 /* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
@@ -13422,7 +13431,7 @@  enable_disable_bp_location (bp_location *loc, bool enable)
     target_disable_tracepoint (loc);
 
   update_global_location_list (UGLL_DONT_INSERT);
-  gdb::observers::breakpoint_modified.notify (loc->owner);
+  notify_breakpoint_modified (loc->owner);
 }
 
 /* Enable or disable a range of breakpoint locations.  BP_NUM is the
@@ -13467,7 +13476,7 @@  disable_breakpoint (struct breakpoint *bpt)
 
   update_global_location_list (UGLL_DONT_INSERT);
 
-  gdb::observers::breakpoint_modified.notify (bpt);
+  notify_breakpoint_modified (bpt);
 }
 
 /* Enable or disable the breakpoint(s) or breakpoint location(s)
@@ -13592,7 +13601,7 @@  enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
   bpt->enable_count = count;
   update_global_location_list (UGLL_MAY_INSERT);
 
-  gdb::observers::breakpoint_modified.notify (bpt);
+  notify_breakpoint_modified (bpt);
 }
 
 
@@ -14063,7 +14072,7 @@  static void
 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
 {
   tp->pass_count = count;
-  gdb::observers::breakpoint_modified.notify (tp);
+  notify_breakpoint_modified (tp);
   if (from_tty)
     gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
 		tp->number, count);
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 7c5cf3f2bef4..5cf49c4d7cce 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1946,4 +1946,9 @@  extern void describe_other_breakpoints (struct gdbarch *,
 
 extern void enable_disable_bp_location (bp_location *loc, bool enable);
 
+
+/* Notify interpreters and observers that breakpoint B was modified.  */
+
+extern void notify_breakpoint_modified (breakpoint *b);
+
 #endif /* !defined (BREAKPOINT_H) */
diff --git a/gdb/interps.c b/gdb/interps.c
index dc36af64f4c4..d572f92f4aa0 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -575,6 +575,14 @@  interps_notify_breakpoint_deleted (breakpoint *b)
   interps_notify (&interp::on_breakpoint_deleted, b);
 }
 
+/* See interps.h.  */
+
+void
+interps_notify_breakpoint_modified (breakpoint *b)
+{
+  interps_notify (&interp::on_breakpoint_modified, b);
+}
+
 /* This just adds the "interpreter-exec" command.  */
 void _initialize_interpreter ();
 void
diff --git a/gdb/interps.h b/gdb/interps.h
index 0e17b14735c0..6fda2ba372f1 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -172,6 +172,9 @@  class interp : public intrusive_list_node<interp>
   /* Notify the interpreter that breakpoint B was deleted.  */
   virtual void on_breakpoint_deleted (breakpoint *b) {}
 
+  /* Notify the interpreter that breakpoint B was modified.  */
+  virtual void on_breakpoint_modified (breakpoint *b) {}
+
 private:
   /* The memory for this is static, it comes from literal strings (e.g. "cli").  */
   const char *m_name;
@@ -347,6 +350,9 @@  extern void interps_notify_breakpoint_created (breakpoint *b);
 /* Notify all interpreters that breakpoint B was deleted.  */
 extern void interps_notify_breakpoint_deleted (breakpoint *b);
 
+/* Notify all interpreters that breakpoint B was modified.  */
+extern void interps_notify_breakpoint_modified (breakpoint *b);
+
 /* well-known interpreters */
 #define INTERP_CONSOLE		"console"
 #define INTERP_MI2             "mi2"
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index e5432d589900..72d30a8d44e3 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -467,7 +467,7 @@  mi_cmd_break_passcount (const char *command, char **argv, int argc)
   if (t)
     {
       t->pass_count = p;
-      gdb::observers::breakpoint_modified.notify (t);
+      notify_breakpoint_modified (t);
     }
   else
     {
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 334d7f9c5a82..2e30b15a4862 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_breakpoint_modified (struct breakpoint *b);
 static void mi_command_param_changed (const char *param, const char *value);
 static void mi_memory_changed (struct inferior *inf, CORE_ADDR memaddr,
 			       ssize_t len, const bfd_byte *myaddr);
@@ -620,10 +619,8 @@  mi_interp::on_breakpoint_deleted (breakpoint *b)
   gdb_flush (this->event_channel);
 }
 
-/* Emit notification about modified breakpoint.  */
-
-static void
-mi_breakpoint_modified (struct breakpoint *b)
+void
+mi_interp::on_breakpoint_modified (breakpoint *b)
 {
   if (mi_suppress_notification.breakpoint)
     return;
@@ -631,21 +628,12 @@  mi_breakpoint_modified (struct breakpoint *b)
   if (b->number <= 0)
     return;
 
-  SWITCH_THRU_ALL_UIS ()
-    {
-      struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-
-      if (mi == NULL)
-	continue;
-
-      target_terminal::scoped_restore_terminal_state term_state;
-      target_terminal::ours_for_output ();
-      gdb_printf (mi->event_channel,
-		  "breakpoint-modified");
-      mi_print_breakpoint_for_event (mi, b);
+  target_terminal::scoped_restore_terminal_state term_state;
+  target_terminal::ours_for_output ();
+  gdb_printf (this->event_channel, "breakpoint-modified");
+  mi_print_breakpoint_for_event (this, b);
 
-      gdb_flush (mi->event_channel);
-    }
+  gdb_flush (this->event_channel);
 }
 
 static void
@@ -984,8 +972,6 @@  _initialize_mi_interp ()
   interp_factory_register (INTERP_MI4, mi_interp_factory);
   interp_factory_register (INTERP_MI, mi_interp_factory);
 
-  gdb::observers::breakpoint_modified.attach (mi_breakpoint_modified,
-					      "mi-interp");
   gdb::observers::command_param_changed.attach (mi_command_param_changed,
 						"mi-interp");
   gdb::observers::memory_changed.attach (mi_memory_changed, "mi-interp");
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index 61b8739b9b3c..52cce4c7cf4c 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -68,6 +68,7 @@  class mi_interp final : public interp
   void on_tsv_modified (const trace_state_variable *tsv) override;
   void on_breakpoint_created (breakpoint *b) override;
   void on_breakpoint_deleted (breakpoint *b) override;
+  void on_breakpoint_modified (breakpoint *b) override;
 
   /* MI's output channels */
   mi_console_file *out;
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index e6ef87475060..2f4eb9c48a46 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1639,7 +1639,7 @@  start_tracing (const char *notes)
 					  loc->gdbarch);
 
       if (bp_location_downloaded)
-	gdb::observers::breakpoint_modified.notify (b);
+	notify_breakpoint_modified (b);
     }
 
   /* Send down all the trace state variables too.  */
@@ -3138,7 +3138,7 @@  merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps)
   /* Notify 'breakpoint-modified' observer that at least one of B's
      locations was changed.  */
   for (breakpoint *b : modified_tp)
-    gdb::observers::breakpoint_modified.notify (b);
+    notify_breakpoint_modified (b);
 
   free_uploaded_tps (uploaded_tps);
 }