public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/36] C++-ify breakpoints
@ 2022-01-18 19:39 Tom Tromey
  2022-01-18 19:39 ` [PATCH 01/36] Move "catch load" to a new file Tom Tromey
                   ` (36 more replies)
  0 siblings, 37 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches

This series somewhat C++-ifies breakpoints.  It turns most
breakpoint_ops function pointers into virtual methods, and introduces
a class hierarchy for breakpoints.

The series starts with a few minor cleanups and clarifications.  Then
it introduces a new vtable-based breakpoint_ops structure.  This is
used to convert breakpoint types one-by-one, to avoid having a monster
patch.  Then, near the end, this is removed again and some final
cleanups applied.

I built and regression tested each patch in this series on x86-64
Fedora 34.

There is still more work that could be done to improve this code in
the future:

* Right now, if you want to add a new breakpoint type, you may need a
  new bptype enumerator constant.  However, these can be a pain to
  add.  I think it would be better to remove this enum entirely, in
  favor of ordinary object-oriented techniques like methods.
  Similarly, perhaps create_breakpoint could be replaced with
  constructors.

* breakpoint_ops isn't fully removed, as it has a couple of "static
  virtual" methods -- methods that vary by breakpoint type, but which
  can't be methods on the breakpoint itself.  This could probably be
  fixed somehow.

* I left the base class name as "breakpoint" to avoid rewriting a lot
  of code.  However, this isn't really the best name, so this could be
  changed.

* Some methods on the base class could probably be made pure virtual.
  This is currently faked, following the approach already used in the
  source: the methods abort when called.  Changing this to use the
  real C++ feature would be an improvement.

* Relatedly, some members of 'breakpoint' could be pushed into the
  relevant subclasses.  For example, breakpoint::location_range_end is
  only used by ranged breakpoints, and so could be moved to struct
  ranged_breakpoint.  This same idea probably applies to some methods
  as well.

Tom



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

* [PATCH 01/36] Move "catch load" to a new file
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-04-23  2:34   ` Simon Marchi
  2022-01-18 19:39 ` [PATCH 02/36] Boolify print_solib_event Tom Tromey
                   ` (35 subsequent siblings)
  36 siblings, 1 reply; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The "catch load" code is reasonably self-contained, and so this patch
moves it out of breakpoint.c and into a new file, break-catch-load.c.
One function from breakpoint.c, print_solib_event, now has to be
exposed, but this seems pretty reasonable.  This patch moves it to the
new file, to keep it near the other solib code.  After this change,
breakpoint.c drops to third place in size, now after remote.c.
---
 gdb/Makefile.in        |   1 +
 gdb/break-catch-load.c | 354 +++++++++++++++++++++++++++++++++++++++++
 gdb/breakpoint.c       | 308 -----------------------------------
 gdb/breakpoint.h       |   6 +
 4 files changed, 361 insertions(+), 308 deletions(-)
 create mode 100644 gdb/break-catch-load.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 3efd2227698..874883c8009 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1001,6 +1001,7 @@ COMMON_SFILES = \
 	blockframe.c \
 	break-catch-exec.c \
 	break-catch-fork.c \
+	break-catch-load.c \
 	break-catch-sig.c \
 	break-catch-syscall.c \
 	break-catch-throw.c \
diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
new file mode 100644
index 00000000000..352b56404b3
--- /dev/null
+++ b/gdb/break-catch-load.c
@@ -0,0 +1,354 @@
+/* Everything about load/unload catchpoints, for GDB.
+
+   Copyright (C) 1986-2022 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+
+#include "annotate.h"
+#include "arch-utils.h"
+#include "breakpoint.h"
+#include "cli/cli-decode.h"
+#include "mi/mi-common.h"
+#include "progspace.h"
+#include "solist.h"
+#include "target.h"
+#include "valprint.h"
+
+/* See breakpoint.h.  */
+
+void
+print_solib_event (int is_catchpoint)
+{
+  bool any_deleted = !current_program_space->deleted_solibs.empty ();
+  bool any_added = !current_program_space->added_solibs.empty ();
+
+  if (!is_catchpoint)
+    {
+      if (any_added || any_deleted)
+	current_uiout->text (_("Stopped due to shared library event:\n"));
+      else
+	current_uiout->text (_("Stopped due to shared library event (no "
+			       "libraries added or removed)\n"));
+    }
+
+  if (current_uiout->is_mi_like_p ())
+    current_uiout->field_string ("reason",
+				 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
+
+  if (any_deleted)
+    {
+      current_uiout->text (_("  Inferior unloaded "));
+      ui_out_emit_list list_emitter (current_uiout, "removed");
+      for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++)
+	{
+	  const std::string &name = current_program_space->deleted_solibs[ix];
+
+	  if (ix > 0)
+	    current_uiout->text ("    ");
+	  current_uiout->field_string ("library", name);
+	  current_uiout->text ("\n");
+	}
+    }
+
+  if (any_added)
+    {
+      current_uiout->text (_("  Inferior loaded "));
+      ui_out_emit_list list_emitter (current_uiout, "added");
+      bool first = true;
+      for (so_list *iter : current_program_space->added_solibs)
+	{
+	  if (!first)
+	    current_uiout->text ("    ");
+	  first = false;
+	  current_uiout->field_string ("library", iter->so_name);
+	  current_uiout->text ("\n");
+	}
+    }
+}
+
+/* An instance of this type is used to represent an solib catchpoint.
+   A breakpoint is really of this type iff its ops pointer points to
+   CATCH_SOLIB_BREAKPOINT_OPS.  */
+
+struct solib_catchpoint : public breakpoint
+{
+  /* True for "catch load", false for "catch unload".  */
+  bool is_load;
+
+  /* Regular expression to match, if any.  COMPILED is only valid when
+     REGEX is non-NULL.  */
+  gdb::unique_xmalloc_ptr<char> regex;
+  std::unique_ptr<compiled_regex> compiled;
+};
+
+static int
+insert_catch_solib (struct bp_location *ignore)
+{
+  return 0;
+}
+
+static int
+remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
+{
+  return 0;
+}
+
+static int
+breakpoint_hit_catch_solib (const struct bp_location *bl,
+			    const address_space *aspace,
+			    CORE_ADDR bp_addr,
+			    const target_waitstatus &ws)
+{
+  struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
+
+  if (ws.kind () == TARGET_WAITKIND_LOADED)
+    return 1;
+
+  for (breakpoint *other : all_breakpoints ())
+    {
+      if (other == bl->owner)
+	continue;
+
+      if (other->type != bp_shlib_event)
+	continue;
+
+      if (self->pspace != NULL && other->pspace != self->pspace)
+	continue;
+
+      for (bp_location *other_bl : other->locations ())
+	{
+	  if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
+	    return 1;
+	}
+    }
+
+  return 0;
+}
+
+static void
+check_status_catch_solib (struct bpstat *bs)
+{
+  struct solib_catchpoint *self
+    = (struct solib_catchpoint *) bs->breakpoint_at;
+
+  if (self->is_load)
+    {
+      for (so_list *iter : current_program_space->added_solibs)
+	{
+	  if (!self->regex
+	      || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
+	    return;
+	}
+    }
+  else
+    {
+      for (const std::string &iter : current_program_space->deleted_solibs)
+	{
+	  if (!self->regex
+	      || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0)
+	    return;
+	}
+    }
+
+  bs->stop = 0;
+  bs->print_it = print_it_noop;
+}
+
+static enum print_stop_action
+print_it_catch_solib (bpstat *bs)
+{
+  struct breakpoint *b = bs->breakpoint_at;
+  struct ui_out *uiout = current_uiout;
+
+  annotate_catchpoint (b->number);
+  maybe_print_thread_hit_breakpoint (uiout);
+  if (b->disposition == disp_del)
+    uiout->text ("Temporary catchpoint ");
+  else
+    uiout->text ("Catchpoint ");
+  uiout->field_signed ("bkptno", b->number);
+  uiout->text ("\n");
+  if (uiout->is_mi_like_p ())
+    uiout->field_string ("disp", bpdisp_text (b->disposition));
+  print_solib_event (1);
+  return PRINT_SRC_AND_LOC;
+}
+
+static void
+print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
+{
+  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
+  struct value_print_options opts;
+  struct ui_out *uiout = current_uiout;
+
+  get_user_print_options (&opts);
+  /* Field 4, the address, is omitted (which makes the columns not
+     line up too nicely with the headers, but the effect is relatively
+     readable).  */
+  if (opts.addressprint)
+    {
+      annotate_field (4);
+      uiout->field_skip ("addr");
+    }
+
+  std::string msg;
+  annotate_field (5);
+  if (self->is_load)
+    {
+      if (self->regex)
+	msg = string_printf (_("load of library matching %s"),
+			     self->regex.get ());
+      else
+	msg = _("load of library");
+    }
+  else
+    {
+      if (self->regex)
+	msg = string_printf (_("unload of library matching %s"),
+			     self->regex.get ());
+      else
+	msg = _("unload of library");
+    }
+  uiout->field_string ("what", msg);
+
+  if (uiout->is_mi_like_p ())
+    uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
+}
+
+static void
+print_mention_catch_solib (struct breakpoint *b)
+{
+  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
+
+  printf_filtered (_("Catchpoint %d (%s)"), b->number,
+		   self->is_load ? "load" : "unload");
+}
+
+static void
+print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
+{
+  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
+
+  fprintf_unfiltered (fp, "%s %s",
+		      b->disposition == disp_del ? "tcatch" : "catch",
+		      self->is_load ? "load" : "unload");
+  if (self->regex)
+    fprintf_unfiltered (fp, " %s", self->regex.get ());
+  fprintf_unfiltered (fp, "\n");
+}
+
+static struct breakpoint_ops catch_solib_breakpoint_ops;
+
+/* See breakpoint.h.  */
+
+void
+add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled)
+{
+  struct gdbarch *gdbarch = get_current_arch ();
+
+  if (!arg)
+    arg = "";
+  arg = skip_spaces (arg);
+
+  std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
+
+  if (*arg != '\0')
+    {
+      c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
+					     _("Invalid regexp")));
+      c->regex = make_unique_xstrdup (arg);
+    }
+
+  c->is_load = is_load;
+  init_catchpoint (c.get (), gdbarch, is_temp, NULL,
+		   &catch_solib_breakpoint_ops);
+
+  c->enable_state = enabled ? bp_enabled : bp_disabled;
+
+  install_breakpoint (0, std::move (c), 1);
+}
+
+/* A helper function that does all the work for "catch load" and
+   "catch unload".  */
+
+static void
+catch_load_or_unload (const char *arg, int from_tty, int is_load,
+		      struct cmd_list_element *command)
+{
+  const int enabled = 1;
+  bool temp = command->context () == CATCH_TEMPORARY;
+
+  add_solib_catchpoint (arg, is_load, temp, enabled);
+}
+
+static void
+catch_load_command_1 (const char *arg, int from_tty,
+		      struct cmd_list_element *command)
+{
+  catch_load_or_unload (arg, from_tty, 1, command);
+}
+
+static void
+catch_unload_command_1 (const char *arg, int from_tty,
+			struct cmd_list_element *command)
+{
+  catch_load_or_unload (arg, from_tty, 0, command);
+}
+
+static void
+initialize_ops ()
+{
+  struct breakpoint_ops *ops;
+
+  initialize_breakpoint_ops ();
+
+  /* Solib-related catchpoints.  */
+  ops = &catch_solib_breakpoint_ops;
+  *ops = base_breakpoint_ops;
+  ops->insert_location = insert_catch_solib;
+  ops->remove_location = remove_catch_solib;
+  ops->breakpoint_hit = breakpoint_hit_catch_solib;
+  ops->check_status = check_status_catch_solib;
+  ops->print_it = print_it_catch_solib;
+  ops->print_one = print_one_catch_solib;
+  ops->print_mention = print_mention_catch_solib;
+  ops->print_recreate = print_recreate_catch_solib;
+
+}
+
+void _initialize_break_catch_load ();
+void
+_initialize_break_catch_load ()
+{
+  initialize_ops ();
+
+  add_catch_command ("load", _("Catch loads of shared libraries.\n\
+Usage: catch load [REGEX]\n\
+If REGEX is given, only stop for libraries matching the regular expression."),
+		     catch_load_command_1,
+		     NULL,
+		     CATCH_PERMANENT,
+		     CATCH_TEMPORARY);
+  add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
+Usage: catch unload [REGEX]\n\
+If REGEX is given, only stop for libraries matching the regular expression."),
+		     catch_unload_command_1,
+		     NULL,
+		     CATCH_PERMANENT,
+		     CATCH_TEMPORARY);
+}
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 1812bfe42f9..964e557f984 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4625,58 +4625,6 @@ print_bp_stop_message (bpstat *bs)
     }
 }
 
-/* A helper function that prints a shared library stopped event.  */
-
-static void
-print_solib_event (int is_catchpoint)
-{
-  bool any_deleted = !current_program_space->deleted_solibs.empty ();
-  bool any_added = !current_program_space->added_solibs.empty ();
-
-  if (!is_catchpoint)
-    {
-      if (any_added || any_deleted)
-	current_uiout->text (_("Stopped due to shared library event:\n"));
-      else
-	current_uiout->text (_("Stopped due to shared library event (no "
-			       "libraries added or removed)\n"));
-    }
-
-  if (current_uiout->is_mi_like_p ())
-    current_uiout->field_string ("reason",
-				 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
-
-  if (any_deleted)
-    {
-      current_uiout->text (_("  Inferior unloaded "));
-      ui_out_emit_list list_emitter (current_uiout, "removed");
-      for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++)
-	{
-	  const std::string &name = current_program_space->deleted_solibs[ix];
-
-	  if (ix > 0)
-	    current_uiout->text ("    ");
-	  current_uiout->field_string ("library", name);
-	  current_uiout->text ("\n");
-	}
-    }
-
-  if (any_added)
-    {
-      current_uiout->text (_("  Inferior loaded "));
-      ui_out_emit_list list_emitter (current_uiout, "added");
-      bool first = true;
-      for (so_list *iter : current_program_space->added_solibs)
-	{
-	  if (!first)
-	    current_uiout->text ("    ");
-	  first = false;
-	  current_uiout->field_string ("library", iter->so_name);
-	  current_uiout->text ("\n");
-	}
-    }
-}
-
 /* Print a message indicating what happened.  This is called from
    normal_stop().  The input to this routine is the head of the bpstat
    list - a list of the eventpoints that caused this stop.  KIND is
@@ -7722,235 +7670,6 @@ disable_breakpoints_in_freed_objfile (struct objfile *objfile)
     }
 }
 
-/* An instance of this type is used to represent an solib catchpoint.
-   A breakpoint is really of this type iff its ops pointer points to
-   CATCH_SOLIB_BREAKPOINT_OPS.  */
-
-struct solib_catchpoint : public breakpoint
-{
-  /* True for "catch load", false for "catch unload".  */
-  bool is_load;
-
-  /* Regular expression to match, if any.  COMPILED is only valid when
-     REGEX is non-NULL.  */
-  gdb::unique_xmalloc_ptr<char> regex;
-  std::unique_ptr<compiled_regex> compiled;
-};
-
-static int
-insert_catch_solib (struct bp_location *ignore)
-{
-  return 0;
-}
-
-static int
-remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
-{
-  return 0;
-}
-
-static int
-breakpoint_hit_catch_solib (const struct bp_location *bl,
-			    const address_space *aspace,
-			    CORE_ADDR bp_addr,
-			    const target_waitstatus &ws)
-{
-  struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
-
-  if (ws.kind () == TARGET_WAITKIND_LOADED)
-    return 1;
-
-  for (breakpoint *other : all_breakpoints ())
-    {
-      if (other == bl->owner)
-	continue;
-
-      if (other->type != bp_shlib_event)
-	continue;
-
-      if (self->pspace != NULL && other->pspace != self->pspace)
-	continue;
-
-      for (bp_location *other_bl : other->locations ())
-	{
-	  if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
-	    return 1;
-	}
-    }
-
-  return 0;
-}
-
-static void
-check_status_catch_solib (struct bpstat *bs)
-{
-  struct solib_catchpoint *self
-    = (struct solib_catchpoint *) bs->breakpoint_at;
-
-  if (self->is_load)
-    {
-      for (so_list *iter : current_program_space->added_solibs)
-	{
-	  if (!self->regex
-	      || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
-	    return;
-	}
-    }
-  else
-    {
-      for (const std::string &iter : current_program_space->deleted_solibs)
-	{
-	  if (!self->regex
-	      || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0)
-	    return;
-	}
-    }
-
-  bs->stop = 0;
-  bs->print_it = print_it_noop;
-}
-
-static enum print_stop_action
-print_it_catch_solib (bpstat *bs)
-{
-  struct breakpoint *b = bs->breakpoint_at;
-  struct ui_out *uiout = current_uiout;
-
-  annotate_catchpoint (b->number);
-  maybe_print_thread_hit_breakpoint (uiout);
-  if (b->disposition == disp_del)
-    uiout->text ("Temporary catchpoint ");
-  else
-    uiout->text ("Catchpoint ");
-  uiout->field_signed ("bkptno", b->number);
-  uiout->text ("\n");
-  if (uiout->is_mi_like_p ())
-    uiout->field_string ("disp", bpdisp_text (b->disposition));
-  print_solib_event (1);
-  return PRINT_SRC_AND_LOC;
-}
-
-static void
-print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
-{
-  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
-  struct value_print_options opts;
-  struct ui_out *uiout = current_uiout;
-
-  get_user_print_options (&opts);
-  /* Field 4, the address, is omitted (which makes the columns not
-     line up too nicely with the headers, but the effect is relatively
-     readable).  */
-  if (opts.addressprint)
-    {
-      annotate_field (4);
-      uiout->field_skip ("addr");
-    }
-
-  std::string msg;
-  annotate_field (5);
-  if (self->is_load)
-    {
-      if (self->regex)
-	msg = string_printf (_("load of library matching %s"),
-			     self->regex.get ());
-      else
-	msg = _("load of library");
-    }
-  else
-    {
-      if (self->regex)
-	msg = string_printf (_("unload of library matching %s"),
-			     self->regex.get ());
-      else
-	msg = _("unload of library");
-    }
-  uiout->field_string ("what", msg);
-
-  if (uiout->is_mi_like_p ())
-    uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
-}
-
-static void
-print_mention_catch_solib (struct breakpoint *b)
-{
-  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
-
-  printf_filtered (_("Catchpoint %d (%s)"), b->number,
-		   self->is_load ? "load" : "unload");
-}
-
-static void
-print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
-{
-  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
-
-  fprintf_unfiltered (fp, "%s %s",
-		      b->disposition == disp_del ? "tcatch" : "catch",
-		      self->is_load ? "load" : "unload");
-  if (self->regex)
-    fprintf_unfiltered (fp, " %s", self->regex.get ());
-  fprintf_unfiltered (fp, "\n");
-}
-
-static struct breakpoint_ops catch_solib_breakpoint_ops;
-
-/* See breakpoint.h.  */
-
-void
-add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled)
-{
-  struct gdbarch *gdbarch = get_current_arch ();
-
-  if (!arg)
-    arg = "";
-  arg = skip_spaces (arg);
-
-  std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
-
-  if (*arg != '\0')
-    {
-      c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
-					     _("Invalid regexp")));
-      c->regex = make_unique_xstrdup (arg);
-    }
-
-  c->is_load = is_load;
-  init_catchpoint (c.get (), gdbarch, is_temp, NULL,
-		   &catch_solib_breakpoint_ops);
-
-  c->enable_state = enabled ? bp_enabled : bp_disabled;
-
-  install_breakpoint (0, std::move (c), 1);
-}
-
-/* A helper function that does all the work for "catch load" and
-   "catch unload".  */
-
-static void
-catch_load_or_unload (const char *arg, int from_tty, int is_load,
-		      struct cmd_list_element *command)
-{
-  const int enabled = 1;
-  bool temp = command->context () == CATCH_TEMPORARY;
-
-  add_solib_catchpoint (arg, is_load, temp, enabled);
-}
-
-static void
-catch_load_command_1 (const char *arg, int from_tty,
-		      struct cmd_list_element *command)
-{
-  catch_load_or_unload (arg, from_tty, 1, command);
-}
-
-static void
-catch_unload_command_1 (const char *arg, int from_tty,
-			struct cmd_list_element *command)
-{
-  catch_load_or_unload (arg, from_tty, 0, command);
-}
-
 /* See breakpoint.h.  */
 
 void
@@ -14867,18 +14586,6 @@ initialize_breakpoint_ops (void)
   ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
   ops->decode_location = strace_marker_decode_location;
 
-  /* Solib-related catchpoints.  */
-  ops = &catch_solib_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->insert_location = insert_catch_solib;
-  ops->remove_location = remove_catch_solib;
-  ops->breakpoint_hit = breakpoint_hit_catch_solib;
-  ops->check_status = check_status_catch_solib;
-  ops->print_it = print_it_catch_solib;
-  ops->print_one = print_one_catch_solib;
-  ops->print_mention = print_mention_catch_solib;
-  ops->print_recreate = print_recreate_catch_solib;
-
   ops = &dprintf_breakpoint_ops;
   *ops = bkpt_base_breakpoint_ops;
   ops->re_set = dprintf_re_set;
@@ -15171,21 +14878,6 @@ Set temporary catchpoints to catch events."),
 			&tcatch_cmdlist,
 			0/*allow-unknown*/, &cmdlist);
 
-  add_catch_command ("load", _("Catch loads of shared libraries.\n\
-Usage: catch load [REGEX]\n\
-If REGEX is given, only stop for libraries matching the regular expression."),
-		     catch_load_command_1,
-		     NULL,
-		     CATCH_PERMANENT,
-		     CATCH_TEMPORARY);
-  add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
-Usage: catch unload [REGEX]\n\
-If REGEX is given, only stop for libraries matching the regular expression."),
-		     catch_unload_command_1,
-		     NULL,
-		     CATCH_PERMANENT,
-		     CATCH_TEMPORARY);
-
   const auto opts = make_watch_options_def_group (nullptr);
 
   static const std::string watch_help = gdb::option::build_help (_("\
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index ba28219c236..0db3d986bbe 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1784,4 +1784,10 @@ extern void catch_exception_event (enum exception_event_kind ex_event,
 				   const char *regex, bool tempflag,
 				   int from_tty);
 
+/* A helper function that prints a shared library stopped event.
+   IS_CATCHPOINT is true if the event is due to a "catch load"
+   catchpoint, false otherwise.  */
+
+extern void print_solib_event (int is_catchpoint);
+
 #endif /* !defined (BREAKPOINT_H) */
-- 
2.31.1


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

* [PATCH 02/36] Boolify print_solib_event
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
  2022-01-18 19:39 ` [PATCH 01/36] Move "catch load" to a new file Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 03/36] Add an assertion to clone_momentary_breakpoint Tom Tromey
                   ` (34 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Change print_solib_event to accept a bool parameter and update the
callers.
---
 gdb/break-catch-load.c | 4 ++--
 gdb/breakpoint.c       | 4 ++--
 gdb/breakpoint.h       | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
index 352b56404b3..34340c260e6 100644
--- a/gdb/break-catch-load.c
+++ b/gdb/break-catch-load.c
@@ -32,7 +32,7 @@
 /* See breakpoint.h.  */
 
 void
-print_solib_event (int is_catchpoint)
+print_solib_event (bool is_catchpoint)
 {
   bool any_deleted = !current_program_space->deleted_solibs.empty ();
   bool any_added = !current_program_space->added_solibs.empty ();
@@ -185,7 +185,7 @@ print_it_catch_solib (bpstat *bs)
   uiout->text ("\n");
   if (uiout->is_mi_like_p ())
     uiout->field_string ("disp", bpdisp_text (b->disposition));
-  print_solib_event (1);
+  print_solib_event (true);
   return PRINT_SRC_AND_LOC;
 }
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 964e557f984..da9997f18d6 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4669,7 +4669,7 @@ bpstat_print (bpstat *bs, int kind)
      OS-level shared library event, do the same thing.  */
   if (kind == TARGET_WAITKIND_LOADED)
     {
-      print_solib_event (0);
+      print_solib_event (false);
       return PRINT_NOTHING;
     }
 
@@ -11921,7 +11921,7 @@ internal_bkpt_print_it (bpstat *bs)
       /* Did we stop because the user set the stop_on_solib_events
 	 variable?  (If so, we report this as a generic, "Stopped due
 	 to shlib event" message.) */
-      print_solib_event (0);
+      print_solib_event (false);
       break;
 
     case bp_thread_event:
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 0db3d986bbe..01a6e0b7994 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1788,6 +1788,6 @@ extern void catch_exception_event (enum exception_event_kind ex_event,
    IS_CATCHPOINT is true if the event is due to a "catch load"
    catchpoint, false otherwise.  */
 
-extern void print_solib_event (int is_catchpoint);
+extern void print_solib_event (bool is_catchpoint);
 
 #endif /* !defined (BREAKPOINT_H) */
-- 
2.31.1


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

* [PATCH 03/36] Add an assertion to clone_momentary_breakpoint
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
  2022-01-18 19:39 ` [PATCH 01/36] Move "catch load" to a new file Tom Tromey
  2022-01-18 19:39 ` [PATCH 02/36] Boolify print_solib_event Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-04-25 13:25   ` Thiago Jung Bauermann
  2022-01-18 19:39 ` [PATCH 04/36] Delete some unnecessary wrapper functions Tom Tromey
                   ` (33 subsequent siblings)
  36 siblings, 1 reply; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This adds an assertion to clone_momentary_breakpoint.  This will
eventually be removed, but in the meantime is is useful for helping
convince oneself that momentary breakpoints will always use
momentary_breakpoint_ops.  This understanding will help when cleaning
up the code later.
---
 gdb/breakpoint.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index da9997f18d6..a0b8bd4e127 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7900,6 +7900,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
   if (orig == NULL)
     return NULL;
 
+  gdb_assert (orig->ops = &momentary_breakpoint_ops);
   return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
 }
 
-- 
2.31.1


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

* [PATCH 04/36] Delete some unnecessary wrapper functions
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (2 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 03/36] Add an assertion to clone_momentary_breakpoint Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-04-25 14:08   ` Thiago Jung Bauermann
  2022-01-18 19:39 ` [PATCH 05/36] Return bool from breakpoint_ops::print_one Tom Tromey
                   ` (32 subsequent siblings)
  36 siblings, 1 reply; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This patch deletes a few unnecessary wrapper functions from
breakpoint.c.
---
 gdb/breakpoint.c | 68 +++---------------------------------------------
 1 file changed, 4 insertions(+), 64 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a0b8bd4e127..06c52bb5b3a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -11828,36 +11828,6 @@ bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
   print_recreate_thread (tp, fp);
 }
 
-static void
-bkpt_create_sals_from_location (struct event_location *location,
-				struct linespec_result *canonical,
-				enum bptype type_wanted)
-{
-  create_sals_from_location_default (location, canonical, type_wanted);
-}
-
-static void
-bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
-			     struct linespec_result *canonical,
-			     gdb::unique_xmalloc_ptr<char> cond_string,
-			     gdb::unique_xmalloc_ptr<char> extra_string,
-			     enum bptype type_wanted,
-			     enum bpdisp disposition,
-			     int thread,
-			     int task, int ignore_count,
-			     const struct breakpoint_ops *ops,
-			     int from_tty, int enabled,
-			     int internal, unsigned flags)
-{
-  create_breakpoints_sal_default (gdbarch, canonical,
-				  std::move (cond_string),
-				  std::move (extra_string),
-				  type_wanted,
-				  disposition, thread, task,
-				  ignore_count, ops, from_tty,
-				  enabled, internal, flags);
-}
-
 static std::vector<symtab_and_line>
 bkpt_decode_location (struct breakpoint *b,
 		      struct event_location *location,
@@ -12140,36 +12110,6 @@ tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
     fprintf_unfiltered (fp, "  passcount %d\n", tp->pass_count);
 }
 
-static void
-tracepoint_create_sals_from_location (struct event_location *location,
-				      struct linespec_result *canonical,
-				      enum bptype type_wanted)
-{
-  create_sals_from_location_default (location, canonical, type_wanted);
-}
-
-static void
-tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
-				   struct linespec_result *canonical,
-				   gdb::unique_xmalloc_ptr<char> cond_string,
-				   gdb::unique_xmalloc_ptr<char> extra_string,
-				   enum bptype type_wanted,
-				   enum bpdisp disposition,
-				   int thread,
-				   int task, int ignore_count,
-				   const struct breakpoint_ops *ops,
-				   int from_tty, int enabled,
-				   int internal, unsigned flags)
-{
-  create_breakpoints_sal_default (gdbarch, canonical,
-				  std::move (cond_string),
-				  std::move (extra_string),
-				  type_wanted,
-				  disposition, thread, task,
-				  ignore_count, ops, from_tty,
-				  enabled, internal, flags);
-}
-
 static std::vector<symtab_and_line>
 tracepoint_decode_location (struct breakpoint *b,
 			    struct event_location *location,
@@ -14487,8 +14427,8 @@ initialize_breakpoint_ops (void)
   ops->insert_location = bkpt_insert_location;
   ops->remove_location = bkpt_remove_location;
   ops->breakpoint_hit = bkpt_breakpoint_hit;
-  ops->create_sals_from_location = bkpt_create_sals_from_location;
-  ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
+  ops->create_sals_from_location = create_sals_from_location_default;
+  ops->create_breakpoints_sal = create_breakpoints_sal_default;
   ops->decode_location = bkpt_decode_location;
 
   /* The breakpoint_ops structure to be used in regular breakpoints.  */
@@ -14570,8 +14510,8 @@ initialize_breakpoint_ops (void)
   ops->print_one_detail = tracepoint_print_one_detail;
   ops->print_mention = tracepoint_print_mention;
   ops->print_recreate = tracepoint_print_recreate;
-  ops->create_sals_from_location = tracepoint_create_sals_from_location;
-  ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
+  ops->create_sals_from_location = create_sals_from_location_default;
+  ops->create_breakpoints_sal = create_breakpoints_sal_default;
   ops->decode_location = tracepoint_decode_location;
 
   /* Probe tracepoints.  */
-- 
2.31.1


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

* [PATCH 05/36] Return bool from breakpoint_ops::print_one
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (3 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 04/36] Delete some unnecessary wrapper functions Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 06/36] Add a vtable-based breakpoint ops Tom Tromey
                   ` (31 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes breakpoint_ops::print_one to return bool, and updates all
the implementations and the caller.  The caller is changed so that a
NULL check is no longer needed -- something that will be impossible
with a real method.
---
 gdb/ada-lang.c            |  4 +++-
 gdb/break-catch-exec.c    |  4 +++-
 gdb/break-catch-fork.c    |  4 +++-
 gdb/break-catch-load.c    |  4 +++-
 gdb/break-catch-sig.c     |  4 +++-
 gdb/break-catch-syscall.c |  4 +++-
 gdb/break-catch-throw.c   |  4 +++-
 gdb/breakpoint.c          | 31 +++++++++++++++++++++----------
 gdb/breakpoint.h          |  5 +++--
 9 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 642527e068c..a2a6275fb5f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11902,7 +11902,7 @@ print_it_exception (bpstat *bs)
 /* Implement the PRINT_ONE method in the breakpoint_ops structure
    for all exception catchpoint kinds.  */
 
-static void
+static bool
 print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
 { 
   struct ui_out *uiout = current_uiout;
@@ -11953,6 +11953,8 @@ print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
 	internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
 	break;
     }
+
+  return true;
 }
 
 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
diff --git a/gdb/break-catch-exec.c b/gdb/break-catch-exec.c
index c0cf2aeb3b5..adfb506477c 100644
--- a/gdb/break-catch-exec.c
+++ b/gdb/break-catch-exec.c
@@ -94,7 +94,7 @@ print_it_catch_exec (bpstat *bs)
   return PRINT_SRC_AND_LOC;
 }
 
-static void
+static bool
 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
 {
   struct exec_catchpoint *c = (struct exec_catchpoint *) b;
@@ -119,6 +119,8 @@ print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
 
   if (uiout->is_mi_like_p ())
     uiout->field_string ("catch-type", "exec");
+
+  return true;
 }
 
 static void
diff --git a/gdb/break-catch-fork.c b/gdb/break-catch-fork.c
index af44a9fe76e..8877099e013 100644
--- a/gdb/break-catch-fork.c
+++ b/gdb/break-catch-fork.c
@@ -127,7 +127,7 @@ print_it_catch_fork (bpstat *bs)
 /* Implement the "print_one" breakpoint_ops method for fork
    catchpoints.  */
 
-static void
+static bool
 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
 {
   struct fork_catchpoint *c = (struct fork_catchpoint *) b;
@@ -153,6 +153,8 @@ print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
 
   if (uiout->is_mi_like_p ())
     uiout->field_string ("catch-type", name);
+
+  return true;
 }
 
 /* Implement the "print_mention" breakpoint_ops method for fork
diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
index 34340c260e6..bfd318fe474 100644
--- a/gdb/break-catch-load.c
+++ b/gdb/break-catch-load.c
@@ -189,7 +189,7 @@ print_it_catch_solib (bpstat *bs)
   return PRINT_SRC_AND_LOC;
 }
 
-static void
+static bool
 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
 {
   struct solib_catchpoint *self = (struct solib_catchpoint *) b;
@@ -228,6 +228,8 @@ print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
 
   if (uiout->is_mi_like_p ())
     uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
+
+  return true;
 }
 
 static void
diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
index e268a102891..f55f34c0368 100644
--- a/gdb/break-catch-sig.c
+++ b/gdb/break-catch-sig.c
@@ -201,7 +201,7 @@ signal_catchpoint_print_it (bpstat *bs)
 /* Implement the "print_one" breakpoint_ops method for signal
    catchpoints.  */
 
-static void
+static bool
 signal_catchpoint_print_one (struct breakpoint *b,
 			     struct bp_location **last_loc)
 {
@@ -248,6 +248,8 @@ signal_catchpoint_print_one (struct breakpoint *b,
 
   if (uiout->is_mi_like_p ())
     uiout->field_string ("catch-type", "signal");
+
+  return true;
 }
 
 /* Implement the "print_mention" breakpoint_ops method for signal
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 9ad8aaa06c8..7c797898940 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -226,7 +226,7 @@ print_it_catch_syscall (bpstat *bs)
 /* Implement the "print_one" breakpoint_ops method for syscall
    catchpoints.  */
 
-static void
+static bool
 print_one_catch_syscall (struct breakpoint *b,
 			 struct bp_location **last_loc)
 {
@@ -275,6 +275,8 @@ print_one_catch_syscall (struct breakpoint *b,
 
   if (uiout->is_mi_like_p ())
     uiout->field_string ("catch-type", "syscall");
+
+  return true;
 }
 
 /* Implement the "print_mention" breakpoint_ops method for syscall
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index d34e5f9ee53..a49736cfd5f 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -253,7 +253,7 @@ print_it_exception_catchpoint (bpstat *bs)
   return PRINT_SRC_AND_LOC;
 }
 
-static void
+static bool
 print_one_exception_catchpoint (struct breakpoint *b, 
 				struct bp_location **last_loc)
 {
@@ -287,6 +287,8 @@ print_one_exception_catchpoint (struct breakpoint *b,
 	uiout->field_string ("catch-type", "catch");
       break;
     }
+
+  return true;
 }
 
 /* Implement the 'print_one_detail' method.  */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 06c52bb5b3a..5b3e91c1841 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5999,9 +5999,10 @@ output_thread_groups (struct ui_out *uiout,
    instead of going via breakpoint_ops::print_one.  This makes "maint
    info breakpoints" show the software breakpoint locations of
    catchpoints, which are considered internal implementation
-   detail.  */
+   detail.  Returns true if RAW_LOC is false and if the breakpoint's
+   print_one method did something; false otherwise.  */
 
-static void
+static bool
 print_one_breakpoint_location (struct breakpoint *b,
 			       struct bp_location *loc,
 			       int loc_number,
@@ -6065,8 +6066,9 @@ print_one_breakpoint_location (struct breakpoint *b,
     uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
 
   /* 5 and 6 */
-  if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL)
-    b->ops->print_one (b, last_loc);
+  bool result = false;
+  if (!raw_loc && b->ops != NULL && b->ops->print_one (b, last_loc))
+    result = true;
   else
     {
       if (is_watchpoint (b))
@@ -6313,6 +6315,8 @@ print_one_breakpoint_location (struct breakpoint *b,
 	uiout->field_string ("original-location",
 			     event_location_to_string (b->location.get ()));
     }
+
+  return result;
 }
 
 /* See breakpoint.h. */
@@ -6330,7 +6334,8 @@ print_one_breakpoint (struct breakpoint *b,
        || fix_multi_location_breakpoint_output_globally);
 
   gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt");
-  print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false);
+  bool printed = print_one_breakpoint_location (b, NULL, 0, last_loc,
+						allflag, false);
 
   /* The mi2 broken format: the main breakpoint tuple ends here, the locations
      are outside.  */
@@ -6340,9 +6345,7 @@ print_one_breakpoint (struct breakpoint *b,
   /* If this breakpoint has custom print function,
      it's already printed.  Otherwise, print individual
      locations, if any.  */
-  if (b->ops == NULL
-      || b->ops->print_one == NULL
-      || allflag)
+  if (!printed || allflag)
     {
       /* If breakpoint has a single location that is disabled, we
 	 print it as if it had several locations, since otherwise it's
@@ -9188,7 +9191,7 @@ print_it_ranged_breakpoint (bpstat *bs)
 /* Implement the "print_one" breakpoint_ops method for
    ranged breakpoints.  */
 
-static void
+static bool
 print_one_ranged_breakpoint (struct breakpoint *b,
 			     struct bp_location **last_loc)
 {
@@ -9208,6 +9211,8 @@ print_one_ranged_breakpoint (struct breakpoint *b,
   annotate_field (5);
   print_breakpoint_location (b, bl);
   *last_loc = bl;
+
+  return true;
 }
 
 /* Implement the "print_one_detail" breakpoint_ops method for
@@ -11560,6 +11565,12 @@ base_breakpoint_print_it (bpstat *bs)
   internal_error_pure_virtual_called ();
 }
 
+static bool
+base_breakpoint_print_one (struct breakpoint *, struct bp_location **)
+{
+  return false;
+}
+
 static void
 base_breakpoint_print_one_detail (const struct breakpoint *self,
 				  struct ui_out *uiout)
@@ -11639,7 +11650,7 @@ struct breakpoint_ops base_breakpoint_ops =
   base_breakpoint_resources_needed,
   base_breakpoint_works_in_software_mode,
   base_breakpoint_print_it,
-  NULL,
+  base_breakpoint_print_one,
   base_breakpoint_print_one_detail,
   base_breakpoint_print_mention,
   base_breakpoint_print_recreate,
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 01a6e0b7994..99f81b28c30 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -608,8 +608,9 @@ struct breakpoint_ops
   enum print_stop_action (*print_it) (struct bpstat *bs);
 
   /* Display information about this breakpoint, for "info
-     breakpoints".  */
-  void (*print_one) (struct breakpoint *, struct bp_location **);
+     breakpoints".  Returns false if this method should use the
+     default behavior.  */
+  bool (*print_one) (struct breakpoint *, struct bp_location **);
 
   /* Display extra information about this breakpoint, below the normal
      breakpoint description in "info breakpoints".
-- 
2.31.1


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

* [PATCH 06/36] Add a vtable-based breakpoint ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (4 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 05/36] Return bool from breakpoint_ops::print_one Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 07/36] Convert break-catch-sig to use vtable ops Tom Tromey
                   ` (30 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This adds methods to struct breakpoint.  Each method has a similar
signature to a corresponding function in breakpoint_ops, with the
exceptions of create_sals_from_location and create_breakpoints_sal,
which can't be virtual methods on breakpoint -- they are only used
during the construction of breakpoints.

Then, this adds a new vtable_breakpoint_ops structure and populates it
with functions that simply forward a call from breakpoint_ops to the
corresponding virtual method.  These are all done with lambdas,
because they are just a stepping stone -- by the end of the series,
this structure will be deleted.
---
 gdb/breakpoint.c | 110 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/breakpoint.h | 113 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 223 insertions(+)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 5b3e91c1841..069d3a9049a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -11504,6 +11504,12 @@ base_breakpoint_allocate_location (struct breakpoint *self)
   return new bp_location (self);
 }
 
+struct bp_location *
+breakpoint::allocate_location ()
+{
+  return new bp_location (this);
+}
+
 static void
 base_breakpoint_re_set (struct breakpoint *b)
 {
@@ -11519,6 +11525,12 @@ base_breakpoint_insert_location (struct bp_location *bl)
   internal_error_pure_virtual_called ();
 }
 
+int
+breakpoint::insert_location (struct bp_location *bl)
+{
+  internal_error_pure_virtual_called ();
+}
+
 static int
 base_breakpoint_remove_location (struct bp_location *bl,
 				 enum remove_bp_reason reason)
@@ -11526,6 +11538,13 @@ base_breakpoint_remove_location (struct bp_location *bl,
   internal_error_pure_virtual_called ();
 }
 
+int
+breakpoint::remove_location (struct bp_location *bl,
+			     enum remove_bp_reason reason)
+{
+  internal_error_pure_virtual_called ();
+}
+
 static int
 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
 				const address_space *aspace,
@@ -11535,6 +11554,15 @@ base_breakpoint_breakpoint_hit (const struct bp_location *bl,
   internal_error_pure_virtual_called ();
 }
 
+int
+breakpoint::breakpoint_hit (const struct bp_location *bl,
+			    const address_space *aspace,
+			    CORE_ADDR bp_addr,
+			    const target_waitstatus &ws)
+{
+  internal_error_pure_virtual_called ();
+}
+
 static void
 base_breakpoint_check_status (bpstat *bs)
 {
@@ -11550,6 +11578,12 @@ base_breakpoint_works_in_software_mode (const struct breakpoint *b)
   internal_error_pure_virtual_called ();
 }
 
+int
+breakpoint::works_in_software_mode () const
+{
+  internal_error_pure_virtual_called ();
+}
+
 /* A "resources_needed" breakpoint_ops method that just internal
    errors.  */
 
@@ -11559,12 +11593,24 @@ base_breakpoint_resources_needed (const struct bp_location *bl)
   internal_error_pure_virtual_called ();
 }
 
+int
+breakpoint::resources_needed (const struct bp_location *bl)
+{
+  internal_error_pure_virtual_called ();
+}
+
 static enum print_stop_action
 base_breakpoint_print_it (bpstat *bs)
 {
   internal_error_pure_virtual_called ();
 }
 
+enum print_stop_action
+breakpoint::print_it (bpstat *bs)
+{
+  internal_error_pure_virtual_called ();
+}
+
 static bool
 base_breakpoint_print_one (struct breakpoint *, struct bp_location **)
 {
@@ -11584,12 +11630,24 @@ base_breakpoint_print_mention (struct breakpoint *b)
   internal_error_pure_virtual_called ();
 }
 
+void
+breakpoint::print_mention ()
+{
+  internal_error_pure_virtual_called ();
+}
+
 static void
 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
 {
   internal_error_pure_virtual_called ();
 }
 
+void
+breakpoint::print_recreate (struct ui_file *fp)
+{
+  internal_error_pure_virtual_called ();
+}
+
 static void
 base_breakpoint_create_sals_from_location
   (struct event_location *location,
@@ -11623,6 +11681,13 @@ base_breakpoint_decode_location (struct breakpoint *b,
   internal_error_pure_virtual_called ();
 }
 
+std::vector<symtab_and_line>
+breakpoint::decode_location (struct event_location *location,
+			     struct program_space *search_pspace)
+{
+  internal_error_pure_virtual_called ();
+}
+
 /* The default 'explains_signal' method.  */
 
 static int
@@ -11661,6 +11726,51 @@ struct breakpoint_ops base_breakpoint_ops =
   base_breakpoint_after_condition_true,
 };
 
+struct breakpoint_ops vtable_breakpoint_ops =
+{
+  [] (struct breakpoint *b) { return b->allocate_location (); },
+  [] (struct breakpoint *b) { b->re_set (); },
+  [] (struct bp_location *l)
+  {
+    return l->owner->insert_location (l);
+  },
+  [] (struct bp_location *l, enum remove_bp_reason reason)
+  {
+    return l->owner->remove_location (l, reason);
+  },
+  [] (const struct bp_location *bl,
+      const address_space *aspace,
+      CORE_ADDR bp_addr,
+      const target_waitstatus &ws)
+  {
+    return bl->owner->breakpoint_hit (bl, aspace, bp_addr, ws);
+  },
+  [] (struct bpstat *bs) { bs->breakpoint_at->check_status (bs); },
+  [] (const struct bp_location *bl)
+  { return bl->owner->resources_needed (bl); },
+  [] (const struct breakpoint *b)
+  { return b->works_in_software_mode (); },
+  [] (struct bpstat *bs)
+  { return bs->breakpoint_at->print_it (bs); },
+  [] (struct breakpoint *b, struct bp_location **bl)
+  { return b->print_one (bl); },
+  [] (const struct breakpoint *b, struct ui_out *out)
+  { b->print_one_detail (out); },
+  [] (struct breakpoint *b) { b->print_mention (); },
+  [] (struct breakpoint *b, struct ui_file *fp)
+  { b->print_recreate (fp); },
+  create_sals_from_location_default,
+  create_breakpoints_sal_default,
+  [] (struct breakpoint *b,
+      struct event_location *location,
+      struct program_space *search_pspace)
+  { return b->decode_location (location, search_pspace); },
+  [] (struct breakpoint *b, enum gdb_signal s)
+  { return b->explains_signal (s); },
+  [] (struct bpstat *bs)
+  { bs->breakpoint_at->after_condition_true (bs); }
+};
+
 /* Default breakpoint_ops methods.  */
 
 static void
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 99f81b28c30..83c37251e0d 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -723,6 +723,118 @@ struct breakpoint
 {
   virtual ~breakpoint () = default;
 
+  /* Allocate a location for this breakpoint.  */
+  virtual struct bp_location *allocate_location ();
+
+  /* Reevaluate a breakpoint.  This is necessary after symbols change
+     (e.g., an executable or DSO was loaded, or the inferior just
+     started).  */
+  virtual void re_set ()
+  {
+    /* Nothing to re-set.  */
+  }
+
+  /* Insert the breakpoint or watchpoint or activate the catchpoint.
+     Return 0 for success, 1 if the breakpoint, watchpoint or
+     catchpoint type is not supported, -1 for failure.  */
+  virtual int insert_location (struct bp_location *);
+
+  /* Remove the breakpoint/catchpoint that was previously inserted
+     with the "insert" method above.  Return 0 for success, 1 if the
+     breakpoint, watchpoint or catchpoint type is not supported,
+     -1 for failure.  */
+  virtual int remove_location (struct bp_location *,
+			       enum remove_bp_reason reason);
+
+  /* Return true if it the target has stopped due to hitting
+     breakpoint location BL.  This function does not check if we
+     should stop, only if BL explains the stop.  ASPACE is the address
+     space in which the event occurred, BP_ADDR is the address at
+     which the inferior stopped, and WS is the target_waitstatus
+     describing the event.  */
+  virtual int breakpoint_hit (const struct bp_location *bl,
+			      const address_space *aspace,
+			      CORE_ADDR bp_addr,
+			      const target_waitstatus &ws);
+
+  /* Check internal conditions of the breakpoint referred to by BS.
+     If we should not stop for this breakpoint, set BS->stop to 0.  */
+  virtual void check_status (struct bpstat *bs)
+  {
+    /* Always stop.  */
+  }
+
+  /* Tell how many hardware resources (debug registers) are needed
+     for this breakpoint.  If this function is not provided, then
+     the breakpoint or watchpoint needs one debug register.  */
+  virtual int resources_needed (const struct bp_location *);
+
+  /* Tell whether we can downgrade from a hardware watchpoint to a software
+     one.  If not, the user will not be able to enable the watchpoint when
+     there are not enough hardware resources available.  */
+  virtual int works_in_software_mode () const;
+
+  /* The normal print routine for this breakpoint, called when we
+     hit it.  */
+  virtual enum print_stop_action print_it (struct bpstat *bs);
+
+  /* Display information about this breakpoint, for "info
+     breakpoints".  Returns false if this method should use the
+     default behavior.  */
+  virtual bool print_one (struct bp_location **)
+  {
+    return false;
+  }
+
+  /* Display extra information about this breakpoint, below the normal
+     breakpoint description in "info breakpoints".
+
+     In the example below, the "address range" line was printed
+     by print_one_detail_ranged_breakpoint.
+
+     (gdb) info breakpoints
+     Num     Type           Disp Enb Address    What
+     2       hw breakpoint  keep y              in main at test-watch.c:70
+	     address range: [0x10000458, 0x100004c7]
+
+   */
+  virtual void print_one_detail (struct ui_out *) const
+  {
+    /* Nothing.  */
+  }
+
+  /* Display information about this breakpoint after setting it
+     (roughly speaking; this is called from "mention").  */
+  virtual void print_mention ();
+
+  /* Print to FP the CLI command that recreates this breakpoint.  */
+  virtual void print_recreate (struct ui_file *fp);
+
+  /* Given the location (second parameter), this method decodes it and
+     returns the SAL locations related to it.  For ordinary
+     breakpoints, it calls `decode_line_full'.  If SEARCH_PSPACE is
+     not NULL, symbol search is restricted to just that program space.
+
+     This function is called inside `location_to_sals'.  */
+  virtual std::vector<symtab_and_line> decode_location
+    (struct event_location *location,
+     struct program_space *search_pspace);
+
+  /* Return true if this breakpoint explains a signal.  See
+     bpstat_explains_signal.  */
+  virtual int explains_signal (enum gdb_signal)
+  {
+    return 1;
+  }
+
+  /* Called after evaluating the breakpoint's condition,
+     and only if it evaluated true.  */
+  virtual void after_condition_true (struct bpstat *bs)
+  {
+    /* Nothing to do.  */
+  }
+
+
   /* Return a range of this breakpoint's locations.  */
   bp_location_range locations ();
 
@@ -1317,6 +1429,7 @@ extern struct breakpoint_ops base_breakpoint_ops;
 extern struct breakpoint_ops bkpt_breakpoint_ops;
 extern struct breakpoint_ops tracepoint_breakpoint_ops;
 extern struct breakpoint_ops dprintf_breakpoint_ops;
+extern struct breakpoint_ops vtable_breakpoint_ops;
 
 extern void initialize_breakpoint_ops (void);
 
-- 
2.31.1


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

* [PATCH 07/36] Convert break-catch-sig to use vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (5 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 06/36] Add a vtable-based breakpoint ops Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 08/36] Convert break-catch-syscall to " Tom Tromey
                   ` (29 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts break-catch-sig.c to use vtable_breakpoint_ops.
---
 gdb/break-catch-sig.c | 150 +++++++++++++++++-------------------------
 1 file changed, 61 insertions(+), 89 deletions(-)

diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
index f55f34c0368..940f8cc4aa6 100644
--- a/gdb/break-catch-sig.c
+++ b/gdb/break-catch-sig.c
@@ -35,12 +35,24 @@
 
 #define INTERNAL_SIGNAL(x) ((x) == GDB_SIGNAL_TRAP || (x) == GDB_SIGNAL_INT)
 
-/* An instance of this type is used to represent a signal catchpoint.
-   A breakpoint is really of this type iff its ops pointer points to
-   SIGNAL_CATCHPOINT_OPS.  */
+/* An instance of this type is used to represent a signal
+   catchpoint.  */
 
 struct signal_catchpoint : public breakpoint
 {
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+  int explains_signal (enum gdb_signal) override;
+
   /* Signal numbers used for the 'catch signal' feature.  If no signal
      has been specified for filtering, it is empty.  Otherwise,
      it holds a list of all signals to be caught.  */
@@ -55,10 +67,6 @@ struct signal_catchpoint : public breakpoint
   bool catch_all;
 };
 
-/* The breakpoint_ops structure to be used in signal catchpoints.  */
-
-static struct breakpoint_ops signal_catchpoint_ops;
-
 /* Count of each signal.  */
 
 static unsigned int signal_catch_counts[GDB_SIGNAL_LAST];
@@ -81,11 +89,10 @@ signal_to_name_or_int (enum gdb_signal sig)
 
 \f
 
-/* Implement the "insert_location" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "insert_location" method for signal catchpoints.  */
 
-static int
-signal_catchpoint_insert_location (struct bp_location *bl)
+int
+signal_catchpoint::insert_location (struct bp_location *bl)
 {
   struct signal_catchpoint *c = (struct signal_catchpoint *) bl->owner;
 
@@ -108,12 +115,11 @@ signal_catchpoint_insert_location (struct bp_location *bl)
   return 0;
 }
 
-/* Implement the "remove_location" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "remove_location" method for signal catchpoints.  */
 
-static int
-signal_catchpoint_remove_location (struct bp_location *bl,
-				   enum remove_bp_reason reason)
+int
+signal_catchpoint::remove_location (struct bp_location *bl,
+				    enum remove_bp_reason reason)
 {
   struct signal_catchpoint *c = (struct signal_catchpoint *) bl->owner;
 
@@ -142,14 +148,13 @@ signal_catchpoint_remove_location (struct bp_location *bl,
   return 0;
 }
 
-/* Implement the "breakpoint_hit" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "breakpoint_hit" method for signal catchpoints.  */
 
-static int
-signal_catchpoint_breakpoint_hit (const struct bp_location *bl,
-				  const address_space *aspace,
-				  CORE_ADDR bp_addr,
-				  const target_waitstatus &ws)
+int
+signal_catchpoint::breakpoint_hit (const struct bp_location *bl,
+				   const address_space *aspace,
+				   CORE_ADDR bp_addr,
+				   const target_waitstatus &ws)
 {
   const struct signal_catchpoint *c
     = (const struct signal_catchpoint *) bl->owner;
@@ -175,13 +180,11 @@ signal_catchpoint_breakpoint_hit (const struct bp_location *bl,
     return c->catch_all || !INTERNAL_SIGNAL (signal_number);
 }
 
-/* Implement the "print_it" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "print_it" method for signal catchpoints.  */
 
-static enum print_stop_action
-signal_catchpoint_print_it (bpstat *bs)
+enum print_stop_action
+signal_catchpoint::print_it (bpstat *bs)
 {
-  struct breakpoint *b = bs->breakpoint_at;
   struct target_waitstatus last;
   const char *signal_name;
   struct ui_out *uiout = current_uiout;
@@ -190,22 +193,19 @@ signal_catchpoint_print_it (bpstat *bs)
 
   signal_name = signal_to_name_or_int (last.sig ());
 
-  annotate_catchpoint (b->number);
+  annotate_catchpoint (number);
   maybe_print_thread_hit_breakpoint (uiout);
 
-  printf_filtered (_("Catchpoint %d (signal %s), "), b->number, signal_name);
+  printf_filtered (_("Catchpoint %d (signal %s), "), number, signal_name);
 
   return PRINT_SRC_AND_LOC;
 }
 
-/* Implement the "print_one" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "print_one" method for signal catchpoints.  */
 
-static bool
-signal_catchpoint_print_one (struct breakpoint *b,
-			     struct bp_location **last_loc)
+bool
+signal_catchpoint::print_one (struct bp_location **last_loc)
 {
-  struct signal_catchpoint *c = (struct signal_catchpoint *) b;
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
@@ -218,17 +218,17 @@ signal_catchpoint_print_one (struct breakpoint *b,
     uiout->field_skip ("addr");
   annotate_field (5);
 
-  if (c->signals_to_be_caught.size () > 1)
+  if (signals_to_be_caught.size () > 1)
     uiout->text ("signals \"");
   else
     uiout->text ("signal \"");
 
-  if (!c->signals_to_be_caught.empty ())
+  if (!signals_to_be_caught.empty ())
     {
       std::string text;
 
       bool first = true;
-      for (gdb_signal iter : c->signals_to_be_caught)
+      for (gdb_signal iter : signals_to_be_caught)
 	{
 	  const char *name = signal_to_name_or_int (iter);
 
@@ -242,7 +242,7 @@ signal_catchpoint_print_one (struct breakpoint *b,
     }
   else
     uiout->field_string ("what",
-			 c->catch_all ? "<any signal>" : "<standard signals>",
+			 catch_all ? "<any signal>" : "<standard signals>",
 			 metadata_style.style ());
   uiout->text ("\" ");
 
@@ -252,22 +252,19 @@ signal_catchpoint_print_one (struct breakpoint *b,
   return true;
 }
 
-/* Implement the "print_mention" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "print_mention" method for signal catchpoints.  */
 
-static void
-signal_catchpoint_print_mention (struct breakpoint *b)
+void
+signal_catchpoint::print_mention ()
 {
-  struct signal_catchpoint *c = (struct signal_catchpoint *) b;
-
-  if (!c->signals_to_be_caught.empty ())
+  if (!signals_to_be_caught.empty ())
     {
-      if (c->signals_to_be_caught.size () > 1)
-	printf_filtered (_("Catchpoint %d (signals"), b->number);
+      if (signals_to_be_caught.size () > 1)
+	printf_filtered (_("Catchpoint %d (signals"), number);
       else
-	printf_filtered (_("Catchpoint %d (signal"), b->number);
+	printf_filtered (_("Catchpoint %d (signal"), number);
 
-      for (gdb_signal iter : c->signals_to_be_caught)
+      for (gdb_signal iter : signals_to_be_caught)
 	{
 	  const char *name = signal_to_name_or_int (iter);
 
@@ -275,37 +272,33 @@ signal_catchpoint_print_mention (struct breakpoint *b)
 	}
       printf_filtered (")");
     }
-  else if (c->catch_all)
-    printf_filtered (_("Catchpoint %d (any signal)"), b->number);
+  else if (catch_all)
+    printf_filtered (_("Catchpoint %d (any signal)"), number);
   else
-    printf_filtered (_("Catchpoint %d (standard signals)"), b->number);
+    printf_filtered (_("Catchpoint %d (standard signals)"), number);
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "print_recreate" method for signal catchpoints.  */
 
-static void
-signal_catchpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
+void
+signal_catchpoint::print_recreate (struct ui_file *fp)
 {
-  struct signal_catchpoint *c = (struct signal_catchpoint *) b;
-
   fprintf_unfiltered (fp, "catch signal");
 
-  if (!c->signals_to_be_caught.empty ())
+  if (!signals_to_be_caught.empty ())
     {
-      for (gdb_signal iter : c->signals_to_be_caught)
+      for (gdb_signal iter : signals_to_be_caught)
 	fprintf_unfiltered (fp, " %s", signal_to_name_or_int (iter));
     }
-  else if (c->catch_all)
+  else if (catch_all)
     fprintf_unfiltered (fp, " all");
   fputc_unfiltered ('\n', fp);
 }
 
-/* Implement the "explains_signal" breakpoint_ops method for signal
-   catchpoints.  */
+/* Implement the "explains_signal" method for signal catchpoints.  */
 
-static int
-signal_catchpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
+int
+signal_catchpoint::explains_signal (enum gdb_signal sig)
 {
   return 1;
 }
@@ -324,7 +317,7 @@ create_signal_catchpoint (int tempflag, std::vector<gdb_signal> &&filter,
   struct gdbarch *gdbarch = get_current_arch ();
 
   std::unique_ptr<signal_catchpoint> c (new signal_catchpoint ());
-  init_catchpoint (c.get (), gdbarch, tempflag, NULL, &signal_catchpoint_ops);
+  init_catchpoint (c.get (), gdbarch, tempflag, NULL, &vtable_breakpoint_ops);
   c->signals_to_be_caught = std::move (filter);
   c->catch_all = catch_all;
 
@@ -408,31 +401,10 @@ catch_signal_command (const char *arg, int from_tty,
   create_signal_catchpoint (tempflag, std::move (filter), catch_all);
 }
 
-static void
-initialize_signal_catchpoint_ops (void)
-{
-  struct breakpoint_ops *ops;
-
-  initialize_breakpoint_ops ();
-
-  ops = &signal_catchpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->insert_location = signal_catchpoint_insert_location;
-  ops->remove_location = signal_catchpoint_remove_location;
-  ops->breakpoint_hit = signal_catchpoint_breakpoint_hit;
-  ops->print_it = signal_catchpoint_print_it;
-  ops->print_one = signal_catchpoint_print_one;
-  ops->print_mention = signal_catchpoint_print_mention;
-  ops->print_recreate = signal_catchpoint_print_recreate;
-  ops->explains_signal = signal_catchpoint_explains_signal;
-}
-
 void _initialize_break_catch_sig ();
 void
 _initialize_break_catch_sig ()
 {
-  initialize_signal_catchpoint_ops ();
-
   add_catch_command ("signal", _("\
 Catch signals by their names and/or numbers.\n\
 Usage: catch signal [[NAME|NUMBER] [NAME|NUMBER]...|all]\n\
-- 
2.31.1


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

* [PATCH 08/36] Convert break-catch-syscall to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (6 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 07/36] Convert break-catch-sig to use vtable ops Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 09/36] Convert break-catch-exec " Tom Tromey
                   ` (28 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts break-catch-syscall.c to use vtable_breakpoint_ops.
---
 gdb/break-catch-syscall.c | 156 ++++++++++++++++----------------------
 1 file changed, 64 insertions(+), 92 deletions(-)

diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 7c797898940..1af4f6d074b 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -32,12 +32,23 @@
 #include "cli/cli-style.h"
 #include "cli/cli-decode.h"
 
-/* An instance of this type is used to represent a syscall catchpoint.
-   A breakpoint is really of this type iff its ops pointer points to
-   CATCH_SYSCALL_BREAKPOINT_OPS.  */
+/* An instance of this type is used to represent a syscall
+   catchpoint.  */
 
 struct syscall_catchpoint : public breakpoint
 {
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+
   /* Syscall numbers used for the 'catch syscall' feature.  If no
      syscall has been specified for filtering, it is empty.
      Otherwise, it holds a list of all syscalls to be caught.  */
@@ -76,23 +87,21 @@ get_catch_syscall_inferior_data (struct inferior *inf)
   return inf_data;
 }
 
-/* Implement the "insert" breakpoint_ops method for syscall
-   catchpoints.  */
+/* Implement the "insert" method for syscall catchpoints.  */
 
-static int
-insert_catch_syscall (struct bp_location *bl)
+int
+syscall_catchpoint::insert_location (struct bp_location *bl)
 {
-  struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
   struct inferior *inf = current_inferior ();
   struct catch_syscall_inferior_data *inf_data
     = get_catch_syscall_inferior_data (inf);
 
   ++inf_data->total_syscalls_count;
-  if (c->syscalls_to_be_caught.empty ())
+  if (syscalls_to_be_caught.empty ())
     ++inf_data->any_syscall_count;
   else
     {
-      for (int iter : c->syscalls_to_be_caught)
+      for (int iter : syscalls_to_be_caught)
 	{
 	  if (iter >= inf_data->syscalls_counts.size ())
 	    inf_data->syscalls_counts.resize (iter + 1);
@@ -106,23 +115,22 @@ insert_catch_syscall (struct bp_location *bl)
 					inf_data->syscalls_counts);
 }
 
-/* Implement the "remove" breakpoint_ops method for syscall
-   catchpoints.  */
+/* Implement the "remove" method for syscall catchpoints.  */
 
-static int
-remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason)
+int
+syscall_catchpoint::remove_location (struct bp_location *bl,
+				     enum remove_bp_reason reason)
 {
-  struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
   struct inferior *inf = current_inferior ();
   struct catch_syscall_inferior_data *inf_data
     = get_catch_syscall_inferior_data (inf);
 
   --inf_data->total_syscalls_count;
-  if (c->syscalls_to_be_caught.empty ())
+  if (syscalls_to_be_caught.empty ())
     --inf_data->any_syscall_count;
   else
     {
-      for (int iter : c->syscalls_to_be_caught)
+      for (int iter : syscalls_to_be_caught)
 	{
 	  if (iter >= inf_data->syscalls_counts.size ())
 	    /* Shouldn't happen.  */
@@ -137,20 +145,18 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason)
 					inf_data->syscalls_counts);
 }
 
-/* Implement the "breakpoint_hit" breakpoint_ops method for syscall
-   catchpoints.  */
+/* Implement the "breakpoint_hit" method for syscall catchpoints.  */
 
-static int
-breakpoint_hit_catch_syscall (const struct bp_location *bl,
-			      const address_space *aspace, CORE_ADDR bp_addr,
-			      const target_waitstatus &ws)
+int
+syscall_catchpoint::breakpoint_hit (const struct bp_location *bl,
+				    const address_space *aspace,
+				    CORE_ADDR bp_addr,
+				    const target_waitstatus &ws)
 {
   /* We must check if we are catching specific syscalls in this
      breakpoint.  If we are, then we must guarantee that the called
      syscall is the same syscall we are catching.  */
   int syscall_number = 0;
-  const struct syscall_catchpoint *c
-    = (const struct syscall_catchpoint *) bl->owner;
 
   if (ws.kind () != TARGET_WAITKIND_SYSCALL_ENTRY
       && ws.kind () != TARGET_WAITKIND_SYSCALL_RETURN)
@@ -159,9 +165,9 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl,
   syscall_number = ws.syscall_number ();
 
   /* Now, checking if the syscall is the same.  */
-  if (!c->syscalls_to_be_caught.empty ())
+  if (!syscalls_to_be_caught.empty ())
     {
-      for (int iter : c->syscalls_to_be_caught)
+      for (int iter : syscalls_to_be_caught)
 	if (syscall_number == iter)
 	  return 1;
 
@@ -171,11 +177,10 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl,
   return 1;
 }
 
-/* Implement the "print_it" breakpoint_ops method for syscall
-   catchpoints.  */
+/* Implement the "print_it" method for syscall catchpoints.  */
 
-static enum print_stop_action
-print_it_catch_syscall (bpstat *bs)
+enum print_stop_action
+syscall_catchpoint::print_it (bpstat *bs)
 {
   struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
@@ -223,17 +228,14 @@ print_it_catch_syscall (bpstat *bs)
   return PRINT_SRC_AND_LOC;
 }
 
-/* Implement the "print_one" breakpoint_ops method for syscall
-   catchpoints.  */
+/* Implement the "print_one" method for syscall catchpoints.  */
 
-static bool
-print_one_catch_syscall (struct breakpoint *b,
-			 struct bp_location **last_loc)
+bool
+syscall_catchpoint::print_one (struct bp_location **last_loc)
 {
-  struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
-  struct gdbarch *gdbarch = b->loc->gdbarch;
+  struct gdbarch *gdbarch = loc->gdbarch;
 
   get_user_print_options (&opts);
   /* Field 4, the address, is omitted (which makes the columns not
@@ -243,17 +245,17 @@ print_one_catch_syscall (struct breakpoint *b,
     uiout->field_skip ("addr");
   annotate_field (5);
 
-  if (c->syscalls_to_be_caught.size () > 1)
+  if (syscalls_to_be_caught.size () > 1)
     uiout->text ("syscalls \"");
   else
     uiout->text ("syscall \"");
 
-  if (!c->syscalls_to_be_caught.empty ())
+  if (!syscalls_to_be_caught.empty ())
     {
       std::string text;
 
       bool first = true;
-      for (int iter : c->syscalls_to_be_caught)
+      for (int iter : syscalls_to_be_caught)
 	{
 	  struct syscall s;
 	  get_syscall_by_number (gdbarch, iter, &s);
@@ -279,23 +281,21 @@ print_one_catch_syscall (struct breakpoint *b,
   return true;
 }
 
-/* Implement the "print_mention" breakpoint_ops method for syscall
-   catchpoints.  */
+/* Implement the "print_mention" method for syscall catchpoints.  */
 
-static void
-print_mention_catch_syscall (struct breakpoint *b)
+void
+syscall_catchpoint::print_mention ()
 {
-  struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
-  struct gdbarch *gdbarch = b->loc->gdbarch;
+  struct gdbarch *gdbarch = loc->gdbarch;
 
-  if (!c->syscalls_to_be_caught.empty ())
+  if (!syscalls_to_be_caught.empty ())
     {
-      if (c->syscalls_to_be_caught.size () > 1)
-	printf_filtered (_("Catchpoint %d (syscalls"), b->number);
+      if (syscalls_to_be_caught.size () > 1)
+	printf_filtered (_("Catchpoint %d (syscalls"), number);
       else
-	printf_filtered (_("Catchpoint %d (syscall"), b->number);
+	printf_filtered (_("Catchpoint %d (syscall"), number);
 
-      for (int iter : c->syscalls_to_be_caught)
+      for (int iter : syscalls_to_be_caught)
 	{
 	  struct syscall s;
 	  get_syscall_by_number (gdbarch, iter, &s);
@@ -309,21 +309,19 @@ print_mention_catch_syscall (struct breakpoint *b)
     }
   else
     printf_filtered (_("Catchpoint %d (any syscall)"),
-		     b->number);
+		     number);
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for syscall
-   catchpoints.  */
+/* Implement the "print_recreate" method for syscall catchpoints.  */
 
-static void
-print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
+void
+syscall_catchpoint::print_recreate (struct ui_file *fp)
 {
-  struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
-  struct gdbarch *gdbarch = b->loc->gdbarch;
+  struct gdbarch *gdbarch = loc->gdbarch;
 
   fprintf_unfiltered (fp, "catch syscall");
 
-  for (int iter : c->syscalls_to_be_caught)
+  for (int iter : syscalls_to_be_caught)
     {
       struct syscall s;
 
@@ -334,29 +332,25 @@ print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
 	fprintf_unfiltered (fp, " %d", s.number);
     }
 
-  print_recreate_thread (b, fp);
+  print_recreate_thread (this, fp);
 }
 
-/* The breakpoint_ops structure to be used in syscall catchpoints.  */
-
-static struct breakpoint_ops catch_syscall_breakpoint_ops;
-
 /* Returns non-zero if 'b' is a syscall catchpoint.  */
 
 static int
 syscall_catchpoint_p (struct breakpoint *b)
 {
-  return (b->ops == &catch_syscall_breakpoint_ops);
+  return dynamic_cast<syscall_catchpoint *> (b) != nullptr;
 }
 
 static void
-create_syscall_event_catchpoint (int tempflag, std::vector<int> &&filter,
-				 const struct breakpoint_ops *ops)
+create_syscall_event_catchpoint (int tempflag, std::vector<int> &&filter)
 {
   struct gdbarch *gdbarch = get_current_arch ();
 
   std::unique_ptr<syscall_catchpoint> c (new syscall_catchpoint ());
-  init_catchpoint (c.get (), gdbarch, tempflag, NULL, ops);
+  init_catchpoint (c.get (), gdbarch, tempflag, nullptr,
+		   &vtable_breakpoint_ops);
   c->syscalls_to_be_caught = std::move (filter);
 
   install_breakpoint (0, std::move (c), 1);
@@ -457,8 +451,7 @@ this architecture yet."));
   if (arg != NULL)
     filter = catch_syscall_split_args (arg);
 
-  create_syscall_event_catchpoint (tempflag, std::move (filter),
-				   &catch_syscall_breakpoint_ops);
+  create_syscall_event_catchpoint (tempflag, std::move (filter));
 }
 
 
@@ -579,31 +572,10 @@ clear_syscall_counts (struct inferior *inf)
   inf_data->syscalls_counts.clear ();
 }
 
-static void
-initialize_syscall_catchpoint_ops (void)
-{
-  struct breakpoint_ops *ops;
-
-  initialize_breakpoint_ops ();
-
-  /* Syscall catchpoints.  */
-  ops = &catch_syscall_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->insert_location = insert_catch_syscall;
-  ops->remove_location = remove_catch_syscall;
-  ops->breakpoint_hit = breakpoint_hit_catch_syscall;
-  ops->print_it = print_it_catch_syscall;
-  ops->print_one = print_one_catch_syscall;
-  ops->print_mention = print_mention_catch_syscall;
-  ops->print_recreate = print_recreate_catch_syscall;
-}
-
 void _initialize_break_catch_syscall ();
 void
 _initialize_break_catch_syscall ()
 {
-  initialize_syscall_catchpoint_ops ();
-
   gdb::observers::inferior_exit.attach (clear_syscall_counts,
 					"break-catch-syscall");
 
-- 
2.31.1


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

* [PATCH 09/36] Convert break-catch-exec to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (7 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 08/36] Convert break-catch-syscall to " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 10/36] Convert break-catch-fork " Tom Tromey
                   ` (27 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts break-catch-exec.c to use vtable_breakpoint_ops.
---
 gdb/break-catch-exec.c | 99 ++++++++++++++++++------------------------
 1 file changed, 42 insertions(+), 57 deletions(-)

diff --git a/gdb/break-catch-exec.c b/gdb/break-catch-exec.c
index adfb506477c..3cabe72a35f 100644
--- a/gdb/break-catch-exec.c
+++ b/gdb/break-catch-exec.c
@@ -36,68 +36,77 @@
 
 struct exec_catchpoint : public breakpoint
 {
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+
   /* Filename of a program whose exec triggered this catchpoint.
      This field is only valid immediately after this catchpoint has
      triggered.  */
   gdb::unique_xmalloc_ptr<char> exec_pathname;
 };
 
-static int
-insert_catch_exec (struct bp_location *bl)
+int
+exec_catchpoint::insert_location (struct bp_location *bl)
 {
   return target_insert_exec_catchpoint (inferior_ptid.pid ());
 }
 
-static int
-remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
+int
+exec_catchpoint::remove_location (struct bp_location *bl,
+				  enum remove_bp_reason reason)
 {
   return target_remove_exec_catchpoint (inferior_ptid.pid ());
 }
 
-static int
-breakpoint_hit_catch_exec (const struct bp_location *bl,
-			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const target_waitstatus &ws)
+int
+exec_catchpoint::breakpoint_hit (const struct bp_location *bl,
+				 const address_space *aspace,
+				 CORE_ADDR bp_addr,
+				 const target_waitstatus &ws)
 {
-  struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
-
   if (ws.kind () != TARGET_WAITKIND_EXECD)
     return 0;
 
-  c->exec_pathname = make_unique_xstrdup (ws.execd_pathname ());
+  exec_pathname = make_unique_xstrdup (ws.execd_pathname ());
   return 1;
 }
 
-static enum print_stop_action
-print_it_catch_exec (bpstat *bs)
+enum print_stop_action
+exec_catchpoint::print_it (bpstat *bs)
 {
   struct ui_out *uiout = current_uiout;
-  struct breakpoint *b = bs->breakpoint_at;
-  struct exec_catchpoint *c = (struct exec_catchpoint *) b;
 
-  annotate_catchpoint (b->number);
+  annotate_catchpoint (number);
   maybe_print_thread_hit_breakpoint (uiout);
-  if (b->disposition == disp_del)
+  if (disposition == disp_del)
     uiout->text ("Temporary catchpoint ");
   else
     uiout->text ("Catchpoint ");
   if (uiout->is_mi_like_p ())
     {
       uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC));
-      uiout->field_string ("disp", bpdisp_text (b->disposition));
+      uiout->field_string ("disp", bpdisp_text (disposition));
     }
-  uiout->field_signed ("bkptno", b->number);
+  uiout->field_signed ("bkptno", number);
   uiout->text (" (exec'd ");
-  uiout->field_string ("new-exec", c->exec_pathname.get ());
+  uiout->field_string ("new-exec", exec_pathname.get ());
   uiout->text ("), ");
 
   return PRINT_SRC_AND_LOC;
 }
 
-static bool
-print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
+bool
+exec_catchpoint::print_one (struct bp_location **last_loc)
 {
-  struct exec_catchpoint *c = (struct exec_catchpoint *) b;
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
@@ -110,10 +119,10 @@ print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
     uiout->field_skip ("addr");
   annotate_field (5);
   uiout->text ("exec");
-  if (c->exec_pathname != NULL)
+  if (exec_pathname != NULL)
     {
       uiout->text (", program \"");
-      uiout->field_string ("what", c->exec_pathname.get ());
+      uiout->field_string ("what", exec_pathname.get ());
       uiout->text ("\" ");
     }
 
@@ -123,24 +132,21 @@ print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
   return true;
 }
 
-static void
-print_mention_catch_exec (struct breakpoint *b)
+void
+exec_catchpoint::print_mention ()
 {
-  printf_filtered (_("Catchpoint %d (exec)"), b->number);
+  printf_filtered (_("Catchpoint %d (exec)"), number);
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for exec
-   catchpoints.  */
+/* Implement the "print_recreate" method for exec catchpoints.  */
 
-static void
-print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
+void
+exec_catchpoint::print_recreate (struct ui_file *fp)
 {
   fprintf_unfiltered (fp, "catch exec");
-  print_recreate_thread (b, fp);
+  print_recreate_thread (this, fp);
 }
 
-static struct breakpoint_ops catch_exec_breakpoint_ops;
-
 /* This function attempts to parse an optional "if <cond>" clause
    from the arg string.  If one is not found, it returns NULL.
 
@@ -199,37 +205,16 @@ catch_exec_command_1 (const char *arg, int from_tty,
 
   std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ());
   init_catchpoint (c.get (), gdbarch, temp, cond_string,
-		   &catch_exec_breakpoint_ops);
+		   &vtable_breakpoint_ops);
   c->exec_pathname.reset ();
 
   install_breakpoint (0, std::move (c), 1);
 }
 
-static void
-initialize_ops ()
-{
-  struct breakpoint_ops *ops;
-
-  initialize_breakpoint_ops ();
-
-  /* Exec catchpoints.  */
-  ops = &catch_exec_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->insert_location = insert_catch_exec;
-  ops->remove_location = remove_catch_exec;
-  ops->breakpoint_hit = breakpoint_hit_catch_exec;
-  ops->print_it = print_it_catch_exec;
-  ops->print_one = print_one_catch_exec;
-  ops->print_mention = print_mention_catch_exec;
-  ops->print_recreate = print_recreate_catch_exec;
-}
-
 void _initialize_break_catch_exec ();
 void
 _initialize_break_catch_exec ()
 {
-  initialize_ops ();
-
   add_catch_command ("exec", _("Catch calls to exec."),
 		     catch_exec_command_1,
 		     NULL,
-- 
2.31.1


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

* [PATCH 10/36] Convert break-catch-fork to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (8 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 09/36] Convert break-catch-exec " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 11/36] Convert break-catch-load " Tom Tromey
                   ` (26 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts break-catch-fork.c to use vtable_breakpoint_ops.
---
 gdb/break-catch-fork.c | 142 ++++++++++++++++-------------------------
 1 file changed, 56 insertions(+), 86 deletions(-)

diff --git a/gdb/break-catch-fork.c b/gdb/break-catch-fork.c
index 8877099e013..9b3721a605e 100644
--- a/gdb/break-catch-fork.c
+++ b/gdb/break-catch-fork.c
@@ -34,6 +34,18 @@
 
 struct fork_catchpoint : public breakpoint
 {
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+
   /* True if the breakpoint is for vfork, false for fork.  */
   bool is_vfork;
 
@@ -43,94 +55,82 @@ struct fork_catchpoint : public breakpoint
   ptid_t forked_inferior_pid;
 };
 
-/* Implement the "insert" breakpoint_ops method for fork
-   catchpoints.  */
+/* Implement the "insert" method for fork catchpoints.  */
 
-static int
-insert_catch_fork (struct bp_location *bl)
+int
+fork_catchpoint::insert_location (struct bp_location *bl)
 {
-  struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
-
-  if (c->is_vfork)
+  if (is_vfork)
     return target_insert_vfork_catchpoint (inferior_ptid.pid ());
   else
     return target_insert_fork_catchpoint (inferior_ptid.pid ());
 }
 
-/* Implement the "remove" breakpoint_ops method for fork
-   catchpoints.  */
+/* Implement the "remove" method for fork catchpoints.  */
 
-static int
-remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
+int
+fork_catchpoint::remove_location (struct bp_location *bl,
+				  enum remove_bp_reason reason)
 {
-  struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
-
-  if (c->is_vfork)
+  if (is_vfork)
     return target_remove_vfork_catchpoint (inferior_ptid.pid ());
   else
     return target_remove_fork_catchpoint (inferior_ptid.pid ());
 }
 
-/* Implement the "breakpoint_hit" breakpoint_ops method for fork
-   catchpoints.  */
+/* Implement the "breakpoint_hit" method for fork catchpoints.  */
 
-static int
-breakpoint_hit_catch_fork (const struct bp_location *bl,
-			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const target_waitstatus &ws)
+int
+fork_catchpoint::breakpoint_hit (const struct bp_location *bl,
+				 const address_space *aspace,
+				 CORE_ADDR bp_addr,
+				 const target_waitstatus &ws)
 {
-  struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
-
-  if (ws.kind () != (c->is_vfork
+  if (ws.kind () != (is_vfork
 		     ? TARGET_WAITKIND_VFORKED
 		     : TARGET_WAITKIND_FORKED))
     return 0;
 
-  c->forked_inferior_pid = ws.child_ptid ();
+  forked_inferior_pid = ws.child_ptid ();
   return 1;
 }
 
-/* Implement the "print_it" breakpoint_ops method for fork
-   catchpoints.  */
+/* Implement the "print_it" method for fork catchpoints.  */
 
-static enum print_stop_action
-print_it_catch_fork (bpstat *bs)
+enum print_stop_action
+fork_catchpoint::print_it (bpstat *bs)
 {
   struct ui_out *uiout = current_uiout;
-  struct breakpoint *b = bs->breakpoint_at;
-  struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
 
-  annotate_catchpoint (b->number);
+  annotate_catchpoint (number);
   maybe_print_thread_hit_breakpoint (uiout);
-  if (b->disposition == disp_del)
+  if (disposition == disp_del)
     uiout->text ("Temporary catchpoint ");
   else
     uiout->text ("Catchpoint ");
   if (uiout->is_mi_like_p ())
     {
       uiout->field_string ("reason",
-			   async_reason_lookup (c->is_vfork
+			   async_reason_lookup (is_vfork
 						? EXEC_ASYNC_VFORK
 						: EXEC_ASYNC_FORK));
-      uiout->field_string ("disp", bpdisp_text (b->disposition));
+      uiout->field_string ("disp", bpdisp_text (disposition));
     }
-  uiout->field_signed ("bkptno", b->number);
-  if (c->is_vfork)
+  uiout->field_signed ("bkptno", number);
+  if (is_vfork)
     uiout->text (" (vforked process ");
   else
     uiout->text (" (forked process ");
-  uiout->field_signed ("newpid", c->forked_inferior_pid.pid ());
+  uiout->field_signed ("newpid", forked_inferior_pid.pid ());
   uiout->text ("), ");
   return PRINT_SRC_AND_LOC;
 }
 
-/* Implement the "print_one" breakpoint_ops method for fork
-   catchpoints.  */
+/* Implement the "print_one" method for fork catchpoints.  */
 
-static bool
-print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
+bool
+fork_catchpoint::print_one (struct bp_location **last_loc)
 {
-  struct fork_catchpoint *c = (struct fork_catchpoint *) b;
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
@@ -142,12 +142,12 @@ print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
   if (opts.addressprint)
     uiout->field_skip ("addr");
   annotate_field (5);
-  const char *name = c->is_vfork ? "vfork" : "fork";
+  const char *name = is_vfork ? "vfork" : "fork";
   uiout->text (name);
-  if (c->forked_inferior_pid != null_ptid)
+  if (forked_inferior_pid != null_ptid)
     {
       uiout->text (", process ");
-      uiout->field_signed ("what", c->forked_inferior_pid.pid ());
+      uiout->field_signed ("what", forked_inferior_pid.pid ());
       uiout->spaces (1);
     }
 
@@ -157,33 +157,24 @@ print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
   return true;
 }
 
-/* Implement the "print_mention" breakpoint_ops method for fork
-   catchpoints.  */
+/* Implement the "print_mention" method for fork catchpoints.  */
 
-static void
-print_mention_catch_fork (struct breakpoint *b)
+void
+fork_catchpoint::print_mention ()
 {
-  struct fork_catchpoint *c = (struct fork_catchpoint *) b;
-  printf_filtered (_("Catchpoint %d (%s)"), c->number,
-		   c->is_vfork ? "vfork" : "fork");
+  printf_filtered (_("Catchpoint %d (%s)"), number,
+		   is_vfork ? "vfork" : "fork");
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for fork
-   catchpoints.  */
+/* Implement the "print_recreate" method for fork catchpoints.  */
 
-static void
-print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
+void
+fork_catchpoint::print_recreate (struct ui_file *fp)
 {
-  struct fork_catchpoint *c = (struct fork_catchpoint *) b;
-  fprintf_unfiltered (fp, "catch %s",
-		      c->is_vfork ? "vfork" : "fork");
-  print_recreate_thread (b, fp);
+  fprintf_unfiltered (fp, "catch %s", is_vfork ? "vfork" : "fork");
+  print_recreate_thread (this, fp);
 }
 
-/* The breakpoint_ops structure to be used in fork catchpoints.  */
-
-static struct breakpoint_ops catch_fork_breakpoint_ops;
-
 static void
 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
 				    bool temp, const char *cond_string,
@@ -192,7 +183,7 @@ create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
   std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ());
 
   init_catchpoint (c.get (), gdbarch, temp, cond_string,
-		   &catch_fork_breakpoint_ops);
+		   &vtable_breakpoint_ops);
   c->is_vfork = is_vfork;
   c->forked_inferior_pid = null_ptid;
 
@@ -250,31 +241,10 @@ catch_fork_command_1 (const char *arg, int from_tty,
     }
 }
 
-static void
-initialize_ops ()
-{
-  struct breakpoint_ops *ops;
-
-  initialize_breakpoint_ops ();
-
-  /* Fork catchpoints.  */
-  ops = &catch_fork_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->insert_location = insert_catch_fork;
-  ops->remove_location = remove_catch_fork;
-  ops->breakpoint_hit = breakpoint_hit_catch_fork;
-  ops->print_it = print_it_catch_fork;
-  ops->print_one = print_one_catch_fork;
-  ops->print_mention = print_mention_catch_fork;
-  ops->print_recreate = print_recreate_catch_fork;
-}
-
 void _initialize_break_catch_fork ();
 void
 _initialize_break_catch_fork ()
 {
-  initialize_ops ();
-
   add_catch_command ("fork", _("Catch calls to fork."),
 		     catch_fork_command_1,
 		     NULL,
-- 
2.31.1


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

* [PATCH 11/36] Convert break-catch-load to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (9 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 10/36] Convert break-catch-fork " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 12/36] Convert watchpoints " Tom Tromey
                   ` (25 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts break-catch-load.c to use vtable_breakpoint_ops.
---
 gdb/break-catch-load.c | 126 +++++++++++++++++------------------------
 1 file changed, 52 insertions(+), 74 deletions(-)

diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
index bfd318fe474..63edf8959ff 100644
--- a/gdb/break-catch-load.c
+++ b/gdb/break-catch-load.c
@@ -87,6 +87,19 @@ print_solib_event (bool is_catchpoint)
 
 struct solib_catchpoint : public breakpoint
 {
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  void check_status (struct bpstat *bs) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+
   /* True for "catch load", false for "catch unload".  */
   bool is_load;
 
@@ -96,26 +109,25 @@ struct solib_catchpoint : public breakpoint
   std::unique_ptr<compiled_regex> compiled;
 };
 
-static int
-insert_catch_solib (struct bp_location *ignore)
+int
+solib_catchpoint::insert_location (struct bp_location *ignore)
 {
   return 0;
 }
 
-static int
-remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
+int
+solib_catchpoint::remove_location (struct bp_location *ignore,
+				   enum remove_bp_reason reason)
 {
   return 0;
 }
 
-static int
-breakpoint_hit_catch_solib (const struct bp_location *bl,
-			    const address_space *aspace,
-			    CORE_ADDR bp_addr,
-			    const target_waitstatus &ws)
+int
+solib_catchpoint::breakpoint_hit (const struct bp_location *bl,
+				  const address_space *aspace,
+				  CORE_ADDR bp_addr,
+				  const target_waitstatus &ws)
 {
-  struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
-
   if (ws.kind () == TARGET_WAITKIND_LOADED)
     return 1;
 
@@ -127,7 +139,7 @@ breakpoint_hit_catch_solib (const struct bp_location *bl,
       if (other->type != bp_shlib_event)
 	continue;
 
-      if (self->pspace != NULL && other->pspace != self->pspace)
+      if (pspace != NULL && other->pspace != pspace)
 	continue;
 
       for (bp_location *other_bl : other->locations ())
@@ -140,18 +152,15 @@ breakpoint_hit_catch_solib (const struct bp_location *bl,
   return 0;
 }
 
-static void
-check_status_catch_solib (struct bpstat *bs)
+void
+solib_catchpoint::check_status (struct bpstat *bs)
 {
-  struct solib_catchpoint *self
-    = (struct solib_catchpoint *) bs->breakpoint_at;
-
-  if (self->is_load)
+  if (is_load)
     {
       for (so_list *iter : current_program_space->added_solibs)
 	{
-	  if (!self->regex
-	      || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
+	  if (!regex
+	      || compiled->exec (iter->so_name, 0, NULL, 0) == 0)
 	    return;
 	}
     }
@@ -159,8 +168,8 @@ check_status_catch_solib (struct bpstat *bs)
     {
       for (const std::string &iter : current_program_space->deleted_solibs)
 	{
-	  if (!self->regex
-	      || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0)
+	  if (!regex
+	      || compiled->exec (iter.c_str (), 0, NULL, 0) == 0)
 	    return;
 	}
     }
@@ -169,8 +178,8 @@ check_status_catch_solib (struct bpstat *bs)
   bs->print_it = print_it_noop;
 }
 
-static enum print_stop_action
-print_it_catch_solib (bpstat *bs)
+enum print_stop_action
+solib_catchpoint::print_it (bpstat *bs)
 {
   struct breakpoint *b = bs->breakpoint_at;
   struct ui_out *uiout = current_uiout;
@@ -189,10 +198,9 @@ print_it_catch_solib (bpstat *bs)
   return PRINT_SRC_AND_LOC;
 }
 
-static bool
-print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
+bool
+solib_catchpoint::print_one (struct bp_location **locs)
 {
-  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
@@ -208,54 +216,48 @@ print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
 
   std::string msg;
   annotate_field (5);
-  if (self->is_load)
+  if (is_load)
     {
-      if (self->regex)
+      if (regex)
 	msg = string_printf (_("load of library matching %s"),
-			     self->regex.get ());
+			     regex.get ());
       else
 	msg = _("load of library");
     }
   else
     {
-      if (self->regex)
+      if (regex)
 	msg = string_printf (_("unload of library matching %s"),
-			     self->regex.get ());
+			     regex.get ());
       else
 	msg = _("unload of library");
     }
   uiout->field_string ("what", msg);
 
   if (uiout->is_mi_like_p ())
-    uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
+    uiout->field_string ("catch-type", is_load ? "load" : "unload");
 
   return true;
 }
 
-static void
-print_mention_catch_solib (struct breakpoint *b)
+void
+solib_catchpoint::print_mention ()
 {
-  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
-
-  printf_filtered (_("Catchpoint %d (%s)"), b->number,
-		   self->is_load ? "load" : "unload");
+  printf_filtered (_("Catchpoint %d (%s)"), number,
+		   is_load ? "load" : "unload");
 }
 
-static void
-print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
+void
+solib_catchpoint::print_recreate (struct ui_file *fp)
 {
-  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
-
   fprintf_unfiltered (fp, "%s %s",
-		      b->disposition == disp_del ? "tcatch" : "catch",
-		      self->is_load ? "load" : "unload");
-  if (self->regex)
-    fprintf_unfiltered (fp, " %s", self->regex.get ());
+		      disposition == disp_del ? "tcatch" : "catch",
+		      is_load ? "load" : "unload");
+  if (regex)
+    fprintf_unfiltered (fp, " %s", regex.get ());
   fprintf_unfiltered (fp, "\n");
 }
 
-static struct breakpoint_ops catch_solib_breakpoint_ops;
-
 /* See breakpoint.h.  */
 
 void
@@ -277,8 +279,7 @@ add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled)
     }
 
   c->is_load = is_load;
-  init_catchpoint (c.get (), gdbarch, is_temp, NULL,
-		   &catch_solib_breakpoint_ops);
+  init_catchpoint (c.get (), gdbarch, is_temp, NULL, &vtable_breakpoint_ops);
 
   c->enable_state = enabled ? bp_enabled : bp_disabled;
 
@@ -312,33 +313,10 @@ catch_unload_command_1 (const char *arg, int from_tty,
   catch_load_or_unload (arg, from_tty, 0, command);
 }
 
-static void
-initialize_ops ()
-{
-  struct breakpoint_ops *ops;
-
-  initialize_breakpoint_ops ();
-
-  /* Solib-related catchpoints.  */
-  ops = &catch_solib_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->insert_location = insert_catch_solib;
-  ops->remove_location = remove_catch_solib;
-  ops->breakpoint_hit = breakpoint_hit_catch_solib;
-  ops->check_status = check_status_catch_solib;
-  ops->print_it = print_it_catch_solib;
-  ops->print_one = print_one_catch_solib;
-  ops->print_mention = print_mention_catch_solib;
-  ops->print_recreate = print_recreate_catch_solib;
-
-}
-
 void _initialize_break_catch_load ();
 void
 _initialize_break_catch_load ()
 {
-  initialize_ops ();
-
   add_catch_command ("load", _("Catch loads of shared libraries.\n\
 Usage: catch load [REGEX]\n\
 If REGEX is given, only stop for libraries matching the regular expression."),
-- 
2.31.1


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

* [PATCH 12/36] Convert watchpoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (10 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 11/36] Convert break-catch-load " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 13/36] Convert tracepoints " Tom Tromey
                   ` (24 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts watchpoints and masked watchpoints. to use
vtable_breakpoint_ops.  For masked watchpoints, a new subclass must be
introduced, and watch_command_1 is changed to create one.
---
 gdb/breakpoint.c | 280 ++++++++++++++++++++---------------------------
 gdb/breakpoint.h |  16 +++
 2 files changed, 132 insertions(+), 164 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 069d3a9049a..49e67d8eb9e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9418,13 +9418,11 @@ watchpoint_exp_is_const (const struct expression *exp)
   return exp->op->constant_p ();
 }
 
-/* Implement the "re_set" breakpoint_ops method for watchpoints.  */
+/* Implement the "re_set" method for watchpoints.  */
 
-static void
-re_set_watchpoint (struct breakpoint *b)
+void
+watchpoint::re_set ()
 {
-  struct watchpoint *w = (struct watchpoint *) b;
-
   /* Watchpoint can be either on expression using entirely global
      variables, or it can be on local variables.
 
@@ -9446,44 +9444,42 @@ re_set_watchpoint (struct breakpoint *b)
      I'm not sure we'll ever be called in this case.
 
      If a local watchpoint's frame id is still valid, then
-     w->exp_valid_block is likewise valid, and we can safely use it.
+     exp_valid_block is likewise valid, and we can safely use it.
 
      Don't do anything about disabled watchpoints, since they will be
      reevaluated again when enabled.  */
-  update_watchpoint (w, 1 /* reparse */);
+  update_watchpoint (this, 1 /* reparse */);
 }
 
-/* Implement the "insert" breakpoint_ops method for hardware watchpoints.  */
+/* Implement the "insert" method for hardware watchpoints.  */
 
-static int
-insert_watchpoint (struct bp_location *bl)
+int
+watchpoint::insert_location (struct bp_location *bl)
 {
-  struct watchpoint *w = (struct watchpoint *) bl->owner;
-  int length = w->exact ? 1 : bl->length;
+  int length = exact ? 1 : bl->length;
 
   return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
-				   w->cond_exp.get ());
+				   cond_exp.get ());
 }
 
-/* Implement the "remove" breakpoint_ops method for hardware watchpoints.  */
+/* Implement the "remove" method for hardware watchpoints.  */
 
-static int
-remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
+int
+watchpoint::remove_location (struct bp_location *bl,
+			     enum remove_bp_reason reason)
 {
-  struct watchpoint *w = (struct watchpoint *) bl->owner;
-  int length = w->exact ? 1 : bl->length;
+  int length = exact ? 1 : bl->length;
 
   return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
-				   w->cond_exp.get ());
+				   cond_exp.get ());
 }
 
-static int
-breakpoint_hit_watchpoint (const struct bp_location *bl,
-			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const target_waitstatus &ws)
+int
+watchpoint::breakpoint_hit (const struct bp_location *bl,
+			    const address_space *aspace, CORE_ADDR bp_addr,
+			    const target_waitstatus &ws)
 {
   struct breakpoint *b = bl->owner;
-  struct watchpoint *w = (struct watchpoint *) b;
 
   /* Continuable hardware watchpoints are treated as non-existent if the
      reason we stopped wasn't a hardware watchpoint (we didn't stop on
@@ -9492,54 +9488,51 @@ breakpoint_hit_watchpoint (const struct bp_location *bl,
      been defined.  Also skip watchpoints which we know did not trigger
      (did not match the data address).  */
   if (is_hardware_watchpoint (b)
-      && w->watchpoint_triggered == watch_triggered_no)
+      && watchpoint_triggered == watch_triggered_no)
     return 0;
 
   return 1;
 }
 
-static void
-check_status_watchpoint (bpstat *bs)
+void
+watchpoint::check_status (bpstat *bs)
 {
   gdb_assert (is_watchpoint (bs->breakpoint_at));
 
   bpstat_check_watchpoint (bs);
 }
 
-/* Implement the "resources_needed" breakpoint_ops method for
-   hardware watchpoints.  */
+/* Implement the "resources_needed" method for hardware
+   watchpoints.  */
 
-static int
-resources_needed_watchpoint (const struct bp_location *bl)
+int
+watchpoint::resources_needed (const struct bp_location *bl)
 {
-  struct watchpoint *w = (struct watchpoint *) bl->owner;
-  int length = w->exact? 1 : bl->length;
+  int length = exact? 1 : bl->length;
 
   return target_region_ok_for_hw_watchpoint (bl->address, length);
 }
 
-/* Implement the "works_in_software_mode" breakpoint_ops method for
-   hardware watchpoints.  */
+/* Implement the "works_in_software_mode" method for hardware
+   watchpoints.  */
 
-static int
-works_in_software_mode_watchpoint (const struct breakpoint *b)
+int
+watchpoint::works_in_software_mode () const
 {
   /* Read and access watchpoints only work with hardware support.  */
-  return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
+  return type == bp_watchpoint || type == bp_hardware_watchpoint;
 }
 
-static enum print_stop_action
-print_it_watchpoint (bpstat *bs)
+enum print_stop_action
+watchpoint::print_it (bpstat *bs)
 {
   struct breakpoint *b;
   enum print_stop_action result;
-  struct watchpoint *w;
   struct ui_out *uiout = current_uiout;
 
   gdb_assert (bs->bp_location_at != NULL);
 
   b = bs->breakpoint_at;
-  w = (struct watchpoint *) b;
 
   annotate_watchpoint (b->number);
   maybe_print_thread_hit_breakpoint (uiout);
@@ -9560,7 +9553,7 @@ print_it_watchpoint (bpstat *bs)
       watchpoint_value_print (bs->old_val.get (), &stb);
       uiout->field_stream ("old", stb);
       uiout->text ("\nNew value = ");
-      watchpoint_value_print (w->val.get (), &stb);
+      watchpoint_value_print (val.get (), &stb);
       uiout->field_stream ("new", stb);
       uiout->text ("\n");
       /* More than one watchpoint may have been triggered.  */
@@ -9574,7 +9567,7 @@ print_it_watchpoint (bpstat *bs)
       mention (b);
       tuple_emitter.emplace (uiout, "value");
       uiout->text ("\nValue = ");
-      watchpoint_value_print (w->val.get (), &stb);
+      watchpoint_value_print (val.get (), &stb);
       uiout->field_stream ("value", stb);
       uiout->text ("\n");
       result = PRINT_UNKNOWN;
@@ -9604,7 +9597,7 @@ print_it_watchpoint (bpstat *bs)
 	  tuple_emitter.emplace (uiout, "value");
 	  uiout->text ("\nValue = ");
 	}
-      watchpoint_value_print (w->val.get (), &stb);
+      watchpoint_value_print (val.get (), &stb);
       uiout->field_stream ("new", stb);
       uiout->text ("\n");
       result = PRINT_UNKNOWN;
@@ -9616,17 +9609,15 @@ print_it_watchpoint (bpstat *bs)
   return result;
 }
 
-/* Implement the "print_mention" breakpoint_ops method for hardware
-   watchpoints.  */
+/* Implement the "print_mention" method for hardware watchpoints.  */
 
-static void
-print_mention_watchpoint (struct breakpoint *b)
+void
+watchpoint::print_mention ()
 {
-  struct watchpoint *w = (struct watchpoint *) b;
   struct ui_out *uiout = current_uiout;
   const char *tuple_name;
 
-  switch (b->type)
+  switch (type)
     {
     case bp_watchpoint:
       uiout->text ("Watchpoint ");
@@ -9650,20 +9641,17 @@ print_mention_watchpoint (struct breakpoint *b)
     }
 
   ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
-  uiout->field_signed ("number", b->number);
+  uiout->field_signed ("number", number);
   uiout->text (": ");
-  uiout->field_string ("exp", w->exp_string.get ());
+  uiout->field_string ("exp", exp_string.get ());
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for
-   watchpoints.  */
+/* Implement the "print_recreate" method for watchpoints.  */
 
-static void
-print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
+void
+watchpoint::print_recreate (struct ui_file *fp)
 {
-  struct watchpoint *w = (struct watchpoint *) b;
-
-  switch (b->type)
+  switch (type)
     {
     case bp_watchpoint:
     case bp_hardware_watchpoint:
@@ -9680,77 +9668,78 @@ print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
 		      _("Invalid watchpoint type."));
     }
 
-  fprintf_unfiltered (fp, " %s", w->exp_string.get ());
-  print_recreate_thread (b, fp);
+  fprintf_unfiltered (fp, " %s", exp_string.get ());
+  print_recreate_thread (this, fp);
 }
 
-/* Implement the "explains_signal" breakpoint_ops method for
-   watchpoints.  */
+/* Implement the "explains_signal" method for watchpoints.  */
 
-static int
-explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
+int
+watchpoint::explains_signal (enum gdb_signal sig)
 {
   /* A software watchpoint cannot cause a signal other than
      GDB_SIGNAL_TRAP.  */
-  if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
+  if (type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
     return 0;
 
   return 1;
 }
 
-/* The breakpoint_ops structure to be used in hardware watchpoints.  */
-
-static struct breakpoint_ops watchpoint_breakpoint_ops;
+struct masked_watchpoint : public watchpoint
+{
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int resources_needed (const struct bp_location *) override;
+  int works_in_software_mode () const override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  void print_one_detail (struct ui_out *) const override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+};
 
-/* Implement the "insert" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "insert" method for masked hardware watchpoints.  */
 
-static int
-insert_masked_watchpoint (struct bp_location *bl)
+int
+masked_watchpoint::insert_location (struct bp_location *bl)
 {
-  struct watchpoint *w = (struct watchpoint *) bl->owner;
-
-  return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
+  return target_insert_mask_watchpoint (bl->address, hw_wp_mask,
 					bl->watchpoint_type);
 }
 
-/* Implement the "remove" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "remove" method for masked hardware watchpoints.  */
 
-static int
-remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
+int
+masked_watchpoint::remove_location (struct bp_location *bl,
+				    enum remove_bp_reason reason)
 {
-  struct watchpoint *w = (struct watchpoint *) bl->owner;
-
-  return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
+  return target_remove_mask_watchpoint (bl->address, hw_wp_mask,
 					bl->watchpoint_type);
 }
 
-/* Implement the "resources_needed" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "resources_needed" method for masked hardware
+   watchpoints.  */
 
-static int
-resources_needed_masked_watchpoint (const struct bp_location *bl)
+int
+masked_watchpoint::resources_needed (const struct bp_location *bl)
 {
-  struct watchpoint *w = (struct watchpoint *) bl->owner;
-
-  return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
+  return target_masked_watch_num_registers (bl->address, hw_wp_mask);
 }
 
-/* Implement the "works_in_software_mode" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "works_in_software_mode" method for masked hardware
+   watchpoints.  */
 
-static int
-works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
+int
+masked_watchpoint::works_in_software_mode () const
 {
   return 0;
 }
 
-/* Implement the "print_it" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "print_it" method for masked hardware
+   watchpoints.  */
 
-static enum print_stop_action
-print_it_masked_watchpoint (bpstat *bs)
+enum print_stop_action
+masked_watchpoint::print_it (bpstat *bs)
 {
   struct breakpoint *b = bs->breakpoint_at;
   struct ui_out *uiout = current_uiout;
@@ -9796,34 +9785,30 @@ address and value which triggered this watchpoint.\n"));
   return PRINT_UNKNOWN;
 }
 
-/* Implement the "print_one_detail" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "print_one_detail" method for masked hardware
+   watchpoints.  */
 
-static void
-print_one_detail_masked_watchpoint (const struct breakpoint *b,
-				    struct ui_out *uiout)
+void
+masked_watchpoint::print_one_detail (struct ui_out *uiout) const
 {
-  struct watchpoint *w = (struct watchpoint *) b;
-
   /* Masked watchpoints have only one location.  */
-  gdb_assert (b->loc && b->loc->next == NULL);
+  gdb_assert (loc && loc->next == NULL);
 
   uiout->text ("\tmask ");
-  uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask);
+  uiout->field_core_addr ("mask", loc->gdbarch, hw_wp_mask);
   uiout->text ("\n");
 }
 
-/* Implement the "print_mention" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "print_mention" method for masked hardware
+   watchpoints.  */
 
-static void
-print_mention_masked_watchpoint (struct breakpoint *b)
+void
+masked_watchpoint::print_mention ()
 {
-  struct watchpoint *w = (struct watchpoint *) b;
   struct ui_out *uiout = current_uiout;
   const char *tuple_name;
 
-  switch (b->type)
+  switch (type)
     {
     case bp_hardware_watchpoint:
       uiout->text ("Masked hardware watchpoint ");
@@ -9843,20 +9828,18 @@ print_mention_masked_watchpoint (struct breakpoint *b)
     }
 
   ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
-  uiout->field_signed ("number", b->number);
+  uiout->field_signed ("number", number);
   uiout->text (": ");
-  uiout->field_string ("exp", w->exp_string.get ());
+  uiout->field_string ("exp", exp_string.get ());
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for
-   masked hardware watchpoints.  */
+/* Implement the "print_recreate" method for masked hardware
+   watchpoints.  */
 
-static void
-print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
+void
+masked_watchpoint::print_recreate (struct ui_file *fp)
 {
-  struct watchpoint *w = (struct watchpoint *) b;
-
-  switch (b->type)
+  switch (type)
     {
     case bp_hardware_watchpoint:
       fprintf_unfiltered (fp, "watch");
@@ -9872,21 +9855,17 @@ print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
 		      _("Invalid hardware watchpoint type."));
     }
 
-  fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string.get (),
-		      phex (w->hw_wp_mask, sizeof (CORE_ADDR)));
-  print_recreate_thread (b, fp);
+  fprintf_unfiltered (fp, " %s mask 0x%s", exp_string.get (),
+		      phex (hw_wp_mask, sizeof (CORE_ADDR)));
+  print_recreate_thread (this, fp);
 }
 
-/* The breakpoint_ops structure to be used in masked hardware watchpoints.  */
-
-static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
-
 /* Tell whether the given watchpoint is a masked hardware watchpoint.  */
 
 static bool
 is_masked_watchpoint (const struct breakpoint *b)
 {
-  return b->ops == &masked_watchpoint_breakpoint_ops;
+  return dynamic_cast<const masked_watchpoint *> (b) != nullptr;
 }
 
 /* accessflag:  hw_write:  watch write, 
@@ -10142,14 +10121,14 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
   else
     bp_type = bp_hardware_watchpoint;
 
-  std::unique_ptr<watchpoint> w (new watchpoint ());
-
+  std::unique_ptr<watchpoint> w;
   if (use_mask)
-    init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
-					  &masked_watchpoint_breakpoint_ops);
+    w.reset (new masked_watchpoint ());
   else
-    init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
-					  &watchpoint_breakpoint_ops);
+    w.reset (new watchpoint ());
+  init_raw_breakpoint_without_location (w.get (), nullptr, bp_type,
+					&vtable_breakpoint_ops);
+
   w->thread = thread;
   w->task = task;
   w->disposition = disp_donttouch;
@@ -14596,33 +14575,6 @@ initialize_breakpoint_ops (void)
   ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
   ops->decode_location = bkpt_probe_decode_location;
 
-  /* Watchpoints.  */
-  ops = &watchpoint_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->re_set = re_set_watchpoint;
-  ops->insert_location = insert_watchpoint;
-  ops->remove_location = remove_watchpoint;
-  ops->breakpoint_hit = breakpoint_hit_watchpoint;
-  ops->check_status = check_status_watchpoint;
-  ops->resources_needed = resources_needed_watchpoint;
-  ops->works_in_software_mode = works_in_software_mode_watchpoint;
-  ops->print_it = print_it_watchpoint;
-  ops->print_mention = print_mention_watchpoint;
-  ops->print_recreate = print_recreate_watchpoint;
-  ops->explains_signal = explains_signal_watchpoint;
-
-  /* Masked watchpoints.  */
-  ops = &masked_watchpoint_breakpoint_ops;
-  *ops = watchpoint_breakpoint_ops;
-  ops->insert_location = insert_masked_watchpoint;
-  ops->remove_location = remove_masked_watchpoint;
-  ops->resources_needed = resources_needed_masked_watchpoint;
-  ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
-  ops->print_it = print_it_masked_watchpoint;
-  ops->print_one_detail = print_one_detail_masked_watchpoint;
-  ops->print_mention = print_mention_masked_watchpoint;
-  ops->print_recreate = print_recreate_masked_watchpoint;
-
   /* Tracepoints.  */
   ops = &tracepoint_breakpoint_ops;
   *ops = base_breakpoint_ops;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 83c37251e0d..3546a114d9f 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -944,6 +944,22 @@ struct breakpoint
 
 struct watchpoint : public breakpoint
 {
+  void re_set () override;
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  void check_status (struct bpstat *bs) override;
+  int resources_needed (const struct bp_location *) override;
+  int works_in_software_mode () const override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+  int explains_signal (enum gdb_signal) override;
+
   /* String form of exp to use for displaying to the user (malloc'd),
      or NULL if none.  */
   gdb::unique_xmalloc_ptr<char> exp_string;
-- 
2.31.1


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

* [PATCH 13/36] Convert tracepoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (11 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 12/36] Convert watchpoints " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 14/36] Add some new subclasses of breakpoint Tom Tromey
                   ` (23 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts tracepoints to use vtable_breakpoint_ops.
---
 gdb/breakpoint.c      | 101 +++++++++++++++++-------------------------
 gdb/breakpoint.h      |  15 ++++++-
 gdb/mi/mi-cmd-break.c |   4 +-
 3 files changed, 56 insertions(+), 64 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 49e67d8eb9e..fd4cd28ed73 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8686,7 +8686,7 @@ breakpoint_ops_for_event_location_type (enum event_location_type location_type,
       if (location_type == PROBE_LOCATION)
 	return &tracepoint_probe_breakpoint_ops;
       else
-	return &tracepoint_breakpoint_ops;
+	return &vtable_breakpoint_ops;
     }
   else
     {
@@ -8706,7 +8706,7 @@ breakpoint_ops_for_event_location (const struct event_location *location,
   if (location != nullptr)
     return breakpoint_ops_for_event_location_type
       (event_location_type (location), is_tracepoint);
-  return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops;
+  return is_tracepoint ? &vtable_breakpoint_ops : &bkpt_breakpoint_ops;
 }
 
 /* See breakpoint.h.  */
@@ -12128,98 +12128,91 @@ bkpt_probe_decode_location (struct breakpoint *b,
 
 /* The breakpoint_ops structure to be used in tracepoints.  */
 
-static void
-tracepoint_re_set (struct breakpoint *b)
+void
+tracepoint::re_set ()
 {
-  breakpoint_re_set_default (b);
+  breakpoint_re_set_default (this);
 }
 
-static int
-tracepoint_breakpoint_hit (const struct bp_location *bl,
-			   const address_space *aspace, CORE_ADDR bp_addr,
-			   const target_waitstatus &ws)
+int
+tracepoint::breakpoint_hit (const struct bp_location *bl,
+			    const address_space *aspace, CORE_ADDR bp_addr,
+			    const target_waitstatus &ws)
 {
   /* By definition, the inferior does not report stops at
      tracepoints.  */
   return 0;
 }
 
-static void
-tracepoint_print_one_detail (const struct breakpoint *self,
-			     struct ui_out *uiout)
+void
+tracepoint::print_one_detail (struct ui_out *uiout) const
 {
-  struct tracepoint *tp = (struct tracepoint *) self;
-  if (!tp->static_trace_marker_id.empty ())
+  if (!static_trace_marker_id.empty ())
     {
-      gdb_assert (self->type == bp_static_tracepoint);
+      gdb_assert (type == bp_static_tracepoint);
 
       uiout->message ("\tmarker id is %pF\n",
 		      string_field ("static-tracepoint-marker-string-id",
-				    tp->static_trace_marker_id.c_str ()));
+				    static_trace_marker_id.c_str ()));
     }
 }
 
-static void
-tracepoint_print_mention (struct breakpoint *b)
+void
+tracepoint::print_mention ()
 {
   if (current_uiout->is_mi_like_p ())
     return;
 
-  switch (b->type)
+  switch (type)
     {
     case bp_tracepoint:
       printf_filtered (_("Tracepoint"));
-      printf_filtered (_(" %d"), b->number);
+      printf_filtered (_(" %d"), number);
       break;
     case bp_fast_tracepoint:
       printf_filtered (_("Fast tracepoint"));
-      printf_filtered (_(" %d"), b->number);
+      printf_filtered (_(" %d"), number);
       break;
     case bp_static_tracepoint:
       printf_filtered (_("Static tracepoint"));
-      printf_filtered (_(" %d"), b->number);
+      printf_filtered (_(" %d"), number);
       break;
     default:
       internal_error (__FILE__, __LINE__,
-		      _("unhandled tracepoint type %d"), (int) b->type);
+		      _("unhandled tracepoint type %d"), (int) type);
     }
 
-  say_where (b);
+  say_where (this);
 }
 
-static void
-tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
+void
+tracepoint::print_recreate (struct ui_file *fp)
 {
-  struct tracepoint *tp = (struct tracepoint *) self;
-
-  if (self->type == bp_fast_tracepoint)
+  if (type == bp_fast_tracepoint)
     fprintf_unfiltered (fp, "ftrace");
-  else if (self->type == bp_static_tracepoint)
+  else if (type == bp_static_tracepoint)
     fprintf_unfiltered (fp, "strace");
-  else if (self->type == bp_tracepoint)
+  else if (type == bp_tracepoint)
     fprintf_unfiltered (fp, "trace");
   else
     internal_error (__FILE__, __LINE__,
-		    _("unhandled tracepoint type %d"), (int) self->type);
+		    _("unhandled tracepoint type %d"), (int) type);
 
   fprintf_unfiltered (fp, " %s",
-		      event_location_to_string (self->location.get ()));
-  print_recreate_thread (self, fp);
+		      event_location_to_string (location.get ()));
+  print_recreate_thread (this, fp);
 
-  if (tp->pass_count)
-    fprintf_unfiltered (fp, "  passcount %d\n", tp->pass_count);
+  if (pass_count)
+    fprintf_unfiltered (fp, "  passcount %d\n", pass_count);
 }
 
-static std::vector<symtab_and_line>
-tracepoint_decode_location (struct breakpoint *b,
-			    struct event_location *location,
-			    struct program_space *search_pspace)
+std::vector<symtab_and_line>
+tracepoint::decode_location (struct event_location *location,
+			     struct program_space *search_pspace)
 {
-  return decode_location_default (b, location, search_pspace);
+  return decode_location_default (this, location, search_pspace);
 }
 
-struct breakpoint_ops tracepoint_breakpoint_ops;
-
 /* Virtual table for tracepoints on static probes.  */
 
 static void
@@ -13868,7 +13861,7 @@ ftrace_command (const char *arg, int from_tty)
 		     bp_fast_tracepoint /* type_wanted */,
 		     0 /* Ignore count */,
 		     pending_break_support,
-		     &tracepoint_breakpoint_ops,
+		     &vtable_breakpoint_ops,
 		     from_tty,
 		     1 /* enabled */,
 		     0 /* internal */, 0);
@@ -13891,7 +13884,7 @@ strace_command (const char *arg, int from_tty)
     }
   else
     {
-      ops = &tracepoint_breakpoint_ops;
+      ops = &vtable_breakpoint_ops;
       location = string_to_event_location (&arg, current_language);
     }
 
@@ -13973,7 +13966,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
 			  utp->type /* type_wanted */,
 			  0 /* Ignore count */,
 			  pending_break_support,
-			  &tracepoint_breakpoint_ops,
+			  &vtable_breakpoint_ops,
 			  0 /* from_tty */,
 			  utp->enabled /* enabled */,
 			  0 /* internal */,
@@ -14575,27 +14568,15 @@ initialize_breakpoint_ops (void)
   ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
   ops->decode_location = bkpt_probe_decode_location;
 
-  /* Tracepoints.  */
-  ops = &tracepoint_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->re_set = tracepoint_re_set;
-  ops->breakpoint_hit = tracepoint_breakpoint_hit;
-  ops->print_one_detail = tracepoint_print_one_detail;
-  ops->print_mention = tracepoint_print_mention;
-  ops->print_recreate = tracepoint_print_recreate;
-  ops->create_sals_from_location = create_sals_from_location_default;
-  ops->create_breakpoints_sal = create_breakpoints_sal_default;
-  ops->decode_location = tracepoint_decode_location;
-
   /* Probe tracepoints.  */
   ops = &tracepoint_probe_breakpoint_ops;
-  *ops = tracepoint_breakpoint_ops;
+  *ops = vtable_breakpoint_ops;
   ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
   ops->decode_location = tracepoint_probe_decode_location;
 
   /* Static tracepoints with marker (`-m').  */
   ops = &strace_marker_breakpoint_ops;
-  *ops = tracepoint_breakpoint_ops;
+  *ops = vtable_breakpoint_ops;
   ops->create_sals_from_location = strace_marker_create_sals_from_location;
   ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
   ops->decode_location = strace_marker_decode_location;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 3546a114d9f..a26ad6bc927 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1032,6 +1032,18 @@ extern bool is_exception_catchpoint (breakpoint *bp);
 
 struct tracepoint : public breakpoint
 {
+  void re_set () override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace, CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  void print_one_detail (struct ui_out *uiout) const override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+  std::vector<symtab_and_line> decode_location
+       (struct event_location *location,
+	struct program_space *search_pspace) override;
+
+
   /* Number of times this tracepoint should single-step and collect
      additional data.  */
   long step_count;
@@ -1443,7 +1455,6 @@ extern void tbreak_command (const char *, int);
 
 extern struct breakpoint_ops base_breakpoint_ops;
 extern struct breakpoint_ops bkpt_breakpoint_ops;
-extern struct breakpoint_ops tracepoint_breakpoint_ops;
 extern struct breakpoint_ops dprintf_breakpoint_ops;
 extern struct breakpoint_ops vtable_breakpoint_ops;
 
@@ -1498,7 +1509,7 @@ extern void install_breakpoint (int internal, std::unique_ptr<breakpoint> &&b,
 /* Returns the breakpoint ops appropriate for use with with LOCATION and
    according to IS_TRACEPOINT.  Use this to ensure, for example, that you pass
    the correct ops to create_breakpoint for probe locations.  If LOCATION is
-   NULL, returns bkpt_breakpoint_ops (or tracepoint_breakpoint_ops, if
+   NULL, returns bkpt_breakpoint_ops (or vtable_breakpoint_ops, if
    IS_TRACEPOINT is true).  */
 
 extern const struct breakpoint_ops *breakpoint_ops_for_event_location
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index 05eac3553ae..a5c78529dd1 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -180,7 +180,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
   symbol_name_match_type match_type = symbol_name_match_type::WILD;
   enum bptype type_wanted;
   event_location_up location;
-  struct breakpoint_ops *ops;
+  const struct breakpoint_ops *ops;
   int is_explicit = 0;
   struct explicit_location explicit_loc;
   std::string extra_string;
@@ -322,7 +322,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
 	 A simulator or an emulator could conceivably implement fast
 	 regular non-jump based tracepoints.  */
       type_wanted = hardware ? bp_fast_tracepoint : bp_tracepoint;
-      ops = &tracepoint_breakpoint_ops;
+      ops = breakpoint_ops_for_event_location (nullptr, true);
     }
   else if (dprintf)
     {
-- 
2.31.1


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

* [PATCH 14/36] Add some new subclasses of breakpoint
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (12 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 13/36] Convert tracepoints " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 15/36] Convert base breakpoints to vtable ops Tom Tromey
                   ` (22 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This adds a few new subclasses of breakpoint.  The inheritance
hierarchy is chosen to reflect what's already present in
initialize_breakpoint_ops -- it mirrors the way that the _ops
structures are filled in.

This patch also changes new_breakpoint_from_type to create the correct
sublcass based on bptype.  This is important due to the somewhat
inverted way in which create_breakpoint works; and in particular later
patches will change some of these entries.
---
 gdb/breakpoint.c | 83 ++++++++++++++++++++++++++++++++++++++++--------
 gdb/breakpoint.h |  7 ++++
 2 files changed, 77 insertions(+), 13 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index fd4cd28ed73..a4ea44995b7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -253,6 +253,26 @@ static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
 /* Dynamic printf class type.  */
 struct breakpoint_ops dprintf_breakpoint_ops;
 
+/* The structure to be used in regular breakpoints.  */
+struct ordinary_breakpoint : public base_breakpoint
+{
+};
+
+/* Internal breakpoints.  */
+struct internal_breakpoint : public base_breakpoint
+{
+};
+
+/* Momentary breakpoints.  */
+struct momentary_breakpoint : public base_breakpoint
+{
+};
+
+/* DPrintf breakpoints.  */
+struct dprintf_breakpoint : public base_breakpoint
+{
+};
+
 /* The style in which to perform a dynamic printf.  This is a user
    option because different output options have different tradeoffs;
    if GDB does the printing, there is better error handling if there
@@ -1127,7 +1147,7 @@ check_no_tracepoint_commands (struct command_line *commands)
     }
 }
 
-struct longjmp_breakpoint : public breakpoint
+struct longjmp_breakpoint : public momentary_breakpoint
 {
   ~longjmp_breakpoint () override;
 };
@@ -1142,12 +1162,6 @@ is_tracepoint_type (bptype type)
 	  || type == bp_static_tracepoint);
 }
 
-static bool
-is_longjmp_type (bptype type)
-{
-  return type == bp_longjmp || type == bp_exception;
-}
-
 /* See breakpoint.h.  */
 
 bool
@@ -1164,12 +1178,55 @@ new_breakpoint_from_type (bptype type)
 {
   breakpoint *b;
 
-  if (is_tracepoint_type (type))
-    b = new tracepoint ();
-  else if (is_longjmp_type (type))
-    b = new longjmp_breakpoint ();
-  else
-    b = new breakpoint ();
+  switch (type)
+    {
+    case bp_breakpoint:
+    case bp_hardware_breakpoint:
+      b = new ordinary_breakpoint ();
+      break;
+
+    case bp_fast_tracepoint:
+    case bp_static_tracepoint:
+    case bp_tracepoint:
+      b = new tracepoint ();
+      break;
+
+    case bp_dprintf:
+      b = new dprintf_breakpoint ();
+      break;
+
+    case bp_overlay_event:
+    case bp_longjmp_master:
+    case bp_std_terminate_master:
+    case bp_exception_master:
+    case bp_thread_event:
+    case bp_jit_event:
+    case bp_shlib_event:
+      b = new internal_breakpoint ();
+      break;
+
+    case bp_longjmp:
+    case bp_exception:
+      b = new longjmp_breakpoint ();
+      break;
+
+    case bp_watchpoint_scope:
+    case bp_finish:
+    case bp_gnu_ifunc_resolver_return:
+    case bp_step_resume:
+    case bp_hp_step_resume:
+    case bp_longjmp_resume:
+    case bp_longjmp_call_dummy:
+    case bp_exception_resume:
+    case bp_call_dummy:
+    case bp_until:
+    case bp_std_terminate:
+      b = new momentary_breakpoint ();
+      break;
+
+    default:
+      gdb_assert_not_reached ("invalid type");
+    }
 
   return std::unique_ptr<breakpoint> (b);
 }
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index a26ad6bc927..a5365bf1808 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -940,6 +940,13 @@ struct breakpoint
   gdbscm_breakpoint_object *scm_bp_object = NULL;
 };
 
+/* The structure to be inherit by all kinds of breakpoints (real
+   breakpoints, i.e., user "break" breakpoints, internal and momentary
+   breakpoints, etc.).  */
+struct base_breakpoint : public breakpoint
+{
+};
+
 /* An instance of this type is used to represent a watchpoint.  */
 
 struct watchpoint : public breakpoint
-- 
2.31.1


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

* [PATCH 15/36] Convert base breakpoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (13 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 14/36] Add some new subclasses of breakpoint Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-05-02 10:27   ` Tom de Vries
  2022-01-18 19:39 ` [PATCH 16/36] Convert break-catch-throw " Tom Tromey
                   ` (21 subsequent siblings)
  36 siblings, 1 reply; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts base breakpoints to use vtable_breakpoint_ops.
---
 gdb/break-catch-throw.c |  2 +-
 gdb/breakpoint.c        | 55 ++++++++++++++++++-----------------------
 gdb/breakpoint.h        | 11 +++++++++
 3 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index a49736cfd5f..86a8fe4ffc6 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -67,7 +67,7 @@ static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
 
 /* The type of an exception catchpoint.  */
 
-struct exception_catchpoint : public breakpoint
+struct exception_catchpoint : public base_breakpoint
 {
   /* The kind of exception catchpoint.  */
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a4ea44995b7..e9b6a801646 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7873,7 +7873,7 @@ enable_breakpoints_after_startup (void)
 static struct breakpoint *
 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
 {
-  std::unique_ptr<breakpoint> b (new breakpoint ());
+  std::unique_ptr<breakpoint> b (new momentary_breakpoint ());
 
   init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
 					&momentary_breakpoint_ops);
@@ -11809,22 +11809,22 @@ struct breakpoint_ops vtable_breakpoint_ops =
 
 /* Default breakpoint_ops methods.  */
 
-static void
-bkpt_re_set (struct breakpoint *b)
+void
+base_breakpoint::re_set ()
 {
   /* FIXME: is this still reachable?  */
-  if (breakpoint_event_location_empty_p (b))
+  if (breakpoint_event_location_empty_p (this))
     {
       /* Anything without a location can't be re-set.  */
-      delete_breakpoint (b);
+      delete_breakpoint (this);
       return;
     }
 
-  breakpoint_re_set_default (b);
+  breakpoint_re_set_default (this);
 }
 
-static int
-bkpt_insert_location (struct bp_location *bl)
+int
+base_breakpoint::insert_location (struct bp_location *bl)
 {
   CORE_ADDR addr = bl->target_info.reqstd_address;
 
@@ -11837,8 +11837,9 @@ bkpt_insert_location (struct bp_location *bl)
     return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
 }
 
-static int
-bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
+int
+base_breakpoint::remove_location (struct bp_location *bl,
+				  enum remove_bp_reason reason)
 {
   if (bl->loc_type == bp_loc_hardware_breakpoint)
     return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
@@ -11846,10 +11847,11 @@ bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
     return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
 }
 
-static int
-bkpt_breakpoint_hit (const struct bp_location *bl,
-		     const address_space *aspace, CORE_ADDR bp_addr,
-		     const target_waitstatus &ws)
+int
+base_breakpoint::breakpoint_hit (const struct bp_location *bl,
+				 const address_space *aspace,
+				 CORE_ADDR bp_addr,
+				 const target_waitstatus &ws)
 {
   if (ws.kind () != TARGET_WAITKIND_STOPPED
       || ws.sig () != GDB_SIGNAL_TRAP)
@@ -11881,7 +11883,7 @@ dprintf_breakpoint_hit (const struct bp_location *bl,
       return 0;
     }
 
-  return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
+  return bl->owner->breakpoint_hit (bl, aspace, bp_addr, ws);
 }
 
 static int
@@ -11985,12 +11987,11 @@ bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
   print_recreate_thread (tp, fp);
 }
 
-static std::vector<symtab_and_line>
-bkpt_decode_location (struct breakpoint *b,
-		      struct event_location *location,
-		      struct program_space *search_pspace)
+std::vector<symtab_and_line>
+base_breakpoint::decode_location (struct event_location *location,
+				  struct program_space *search_pspace)
 {
-  return decode_location_default (b, location, search_pspace);
+  return decode_location_default (this, location, search_pspace);
 }
 
 /* Virtual table for internal breakpoints.  */
@@ -12137,7 +12138,7 @@ longjmp_breakpoint::~longjmp_breakpoint ()
 static int
 bkpt_probe_insert_location (struct bp_location *bl)
 {
-  int v = bkpt_insert_location (bl);
+  int v = bl->owner->insert_location (bl);
 
   if (v == 0)
     {
@@ -12156,7 +12157,7 @@ bkpt_probe_remove_location (struct bp_location *bl,
   /* Let's clear the semaphore before removing the location.  */
   bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
 
-  return bkpt_remove_location (bl, reason);
+  return bl->owner->remove_location (bl, reason);
 }
 
 static void
@@ -14572,19 +14573,11 @@ initialize_breakpoint_ops (void)
      breakpoints (real breakpoints, i.e., user "break" breakpoints,
      internal and momentary breakpoints, etc.).  */
   ops = &bkpt_base_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->re_set = bkpt_re_set;
-  ops->insert_location = bkpt_insert_location;
-  ops->remove_location = bkpt_remove_location;
-  ops->breakpoint_hit = bkpt_breakpoint_hit;
-  ops->create_sals_from_location = create_sals_from_location_default;
-  ops->create_breakpoints_sal = create_breakpoints_sal_default;
-  ops->decode_location = bkpt_decode_location;
+  *ops = vtable_breakpoint_ops;
 
   /* The breakpoint_ops structure to be used in regular breakpoints.  */
   ops = &bkpt_breakpoint_ops;
   *ops = bkpt_base_breakpoint_ops;
-  ops->re_set = bkpt_re_set;
   ops->resources_needed = bkpt_resources_needed;
   ops->print_it = bkpt_print_it;
   ops->print_mention = bkpt_print_mention;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index a5365bf1808..11b65ab8318 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -945,6 +945,17 @@ struct breakpoint
    breakpoints, etc.).  */
 struct base_breakpoint : public breakpoint
 {
+  void re_set () override;
+  int insert_location (struct bp_location *) override;
+  int remove_location (struct bp_location *,
+		       enum remove_bp_reason reason) override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  std::vector<symtab_and_line> decode_location
+       (struct event_location *location,
+	struct program_space *search_pspace) override;
 };
 
 /* An instance of this type is used to represent a watchpoint.  */
-- 
2.31.1


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

* [PATCH 16/36] Convert break-catch-throw to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (14 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 15/36] Convert base breakpoints to vtable ops Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 17/36] Convert internal breakpoints " Tom Tromey
                   ` (20 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts break-catch-throw.c to use vtable_breakpoint_ops.
---
 gdb/break-catch-throw.c | 138 +++++++++++++++-------------------------
 1 file changed, 53 insertions(+), 85 deletions(-)

diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index 86a8fe4ffc6..f41a8090e0c 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -63,12 +63,26 @@ static const struct exception_names exception_functions[] =
   { "-probe-stap libstdcxx:catch", "__cxa_begin_catch" }
 };
 
-static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
-
 /* The type of an exception catchpoint.  */
 
 struct exception_catchpoint : public base_breakpoint
 {
+  void re_set () override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+  void print_one_detail (struct ui_out *) const override;
+  void check_status (struct bpstat *bs) override;
+  struct bp_location *allocate_location () override;
+
+  /* FIXME this is temporary - until ordinary breakpoints have been
+     converted.  */
+  int resources_needed (const struct bp_location *) override
+  {
+    return 1;
+  }
+
   /* The kind of exception catchpoint.  */
 
   enum exception_event_kind kind;
@@ -89,7 +103,7 @@ struct exception_catchpoint : public base_breakpoint
 bool
 is_exception_catchpoint (breakpoint *bp)
 {
-  return bp->ops == &gnu_v3_exception_catchpoint_ops;
+  return dynamic_cast<exception_catchpoint *> (bp) != nullptr;
 }
 
 \f
@@ -130,27 +144,16 @@ fetch_probe_arguments (struct value **arg0, struct value **arg1)
 
 \f
 
-/* A helper function that returns a value indicating the kind of the
-   exception catchpoint B.  */
-
-static enum exception_event_kind
-classify_exception_breakpoint (struct breakpoint *b)
-{
-  struct exception_catchpoint *cp = (struct exception_catchpoint *) b;
-
-  return cp->kind;
-}
-
 /* Implement the 'check_status' method.  */
 
-static void
-check_status_exception_catchpoint (struct bpstat *bs)
+void
+exception_catchpoint::check_status (struct bpstat *bs)
 {
   struct exception_catchpoint *self
     = (struct exception_catchpoint *) bs->breakpoint_at;
   std::string type_name;
 
-  bkpt_breakpoint_ops.check_status (bs);
+  this->breakpoint::check_status (bs);
   if (bs->stop == 0)
     return;
 
@@ -185,11 +188,10 @@ check_status_exception_catchpoint (struct bpstat *bs)
 
 /* Implement the 're_set' method.  */
 
-static void
-re_set_exception_catchpoint (struct breakpoint *self)
+void
+exception_catchpoint::re_set ()
 {
   std::vector<symtab_and_line> sals;
-  enum exception_event_kind kind = classify_exception_breakpoint (self);
   struct program_space *filter_pspace = current_program_space;
 
   /* We first try to use the probe interface.  */
@@ -211,8 +213,7 @@ re_set_exception_catchpoint (struct breakpoint *self)
 	  explicit_loc.function_name
 	    = ASTRDUP (exception_functions[kind].function);
 	  event_location_up location = new_explicit_location (&explicit_loc);
-	  sals = self->ops->decode_location (self, location.get (),
-					     filter_pspace);
+	  sals = this->decode_location (location.get (), filter_pspace);
 	}
       catch (const gdb_exception_error &ex)
 	{
@@ -223,24 +224,22 @@ re_set_exception_catchpoint (struct breakpoint *self)
 	}
     }
 
-  update_breakpoint_locations (self, filter_pspace, sals, {});
+  update_breakpoint_locations (this, filter_pspace, sals, {});
 }
 
-static enum print_stop_action
-print_it_exception_catchpoint (bpstat *bs)
+enum print_stop_action
+exception_catchpoint::print_it (bpstat *bs)
 {
   struct ui_out *uiout = current_uiout;
-  struct breakpoint *b = bs->breakpoint_at;
   int bp_temp;
-  enum exception_event_kind kind = classify_exception_breakpoint (b);
 
-  annotate_catchpoint (b->number);
+  annotate_catchpoint (number);
   maybe_print_thread_hit_breakpoint (uiout);
 
-  bp_temp = b->disposition == disp_del;
+  bp_temp = disposition == disp_del;
   uiout->text (bp_temp ? "Temporary catchpoint "
 		       : "Catchpoint ");
-  uiout->field_signed ("bkptno", b->number);
+  uiout->field_signed ("bkptno", number);
   uiout->text ((kind == EX_EVENT_THROW ? " (exception thrown), "
 		: (kind == EX_EVENT_CATCH ? " (exception caught), "
 		   : " (exception rethrown), ")));
@@ -248,18 +247,16 @@ print_it_exception_catchpoint (bpstat *bs)
     {
       uiout->field_string ("reason",
 			   async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
-      uiout->field_string ("disp", bpdisp_text (b->disposition));
+      uiout->field_string ("disp", bpdisp_text (disposition));
     }
   return PRINT_SRC_AND_LOC;
 }
 
-static bool
-print_one_exception_catchpoint (struct breakpoint *b, 
-				struct bp_location **last_loc)
+bool
+exception_catchpoint::print_one (struct bp_location **last_loc)
 {
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
-  enum exception_event_kind kind = classify_exception_breakpoint (b);
 
   get_user_print_options (&opts);
 
@@ -293,48 +290,41 @@ print_one_exception_catchpoint (struct breakpoint *b,
 
 /* Implement the 'print_one_detail' method.  */
 
-static void
-print_one_detail_exception_catchpoint (const struct breakpoint *b,
-				       struct ui_out *uiout)
+void
+exception_catchpoint::print_one_detail (struct ui_out *uiout) const
 {
-  const struct exception_catchpoint *cp
-    = (const struct exception_catchpoint *) b;
-
-  if (!cp->exception_rx.empty ())
+  if (!exception_rx.empty ())
     {
       uiout->text (_("\tmatching: "));
-      uiout->field_string ("regexp", cp->exception_rx);
+      uiout->field_string ("regexp", exception_rx);
       uiout->text ("\n");
     }
 }
 
-static void
-print_mention_exception_catchpoint (struct breakpoint *b)
+void
+exception_catchpoint::print_mention ()
 {
   struct ui_out *uiout = current_uiout;
   int bp_temp;
-  enum exception_event_kind kind = classify_exception_breakpoint (b);
 
-  bp_temp = b->disposition == disp_del;
+  bp_temp = disposition == disp_del;
   uiout->message ("%s %d %s",
 		  (bp_temp ? _("Temporary catchpoint ") : _("Catchpoint")),
-		  b->number,
+		  number,
 		  (kind == EX_EVENT_THROW
 		   ? _("(throw)") : (kind == EX_EVENT_CATCH
 				     ? _("(catch)") : _("(rethrow)"))));
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for throw and
-   catch catchpoints.  */
+/* Implement the "print_recreate" method for throw and catch
+   catchpoints.  */
 
-static void
-print_recreate_exception_catchpoint (struct breakpoint *b, 
-				     struct ui_file *fp)
+void
+exception_catchpoint::print_recreate (struct ui_file *fp)
 {
   int bp_temp;
-  enum exception_event_kind kind = classify_exception_breakpoint (b);
 
-  bp_temp = b->disposition == disp_del;
+  bp_temp = disposition == disp_del;
   fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
   switch (kind)
     {
@@ -348,16 +338,16 @@ print_recreate_exception_catchpoint (struct breakpoint *b,
       fprintf_unfiltered (fp, "rethrow");
       break;
     }
-  print_recreate_thread (b, fp);
+  print_recreate_thread (this, fp);
 }
 
-/* Implement the "allocate_location" breakpoint_ops method for throw
-   and catch catchpoints.  */
+/* Implement the "allocate_location" method for throw and catch
+   catchpoints.  */
 
-static bp_location *
-allocate_location_exception_catchpoint (breakpoint *self)
+bp_location *
+exception_catchpoint::allocate_location ()
 {
-  return new bp_location (self, bp_loc_software_breakpoint);
+  return new bp_location (this, bp_loc_software_breakpoint);
 }
 
 static void
@@ -376,12 +366,12 @@ handle_gnu_v3_exceptions (int tempflag, std::string &&except_rx,
   std::unique_ptr<exception_catchpoint> cp (new exception_catchpoint ());
 
   init_catchpoint (cp.get (), get_current_arch (), tempflag, cond_string,
-		   &gnu_v3_exception_catchpoint_ops);
+		   &vtable_breakpoint_ops);
   cp->kind = ex_event;
   cp->exception_rx = std::move (except_rx);
   cp->pattern = std::move (pattern);
 
-  re_set_exception_catchpoint (cp.get ());
+  cp->re_set ();
 
   install_breakpoint (0, std::move (cp), 1);
 }
@@ -517,32 +507,10 @@ static const struct internalvar_funcs exception_funcs =
 
 \f
 
-static void
-initialize_throw_catchpoint_ops (void)
-{
-  struct breakpoint_ops *ops;
-
-  initialize_breakpoint_ops ();
-
-  /* GNU v3 exception catchpoints.  */
-  ops = &gnu_v3_exception_catchpoint_ops;
-  *ops = bkpt_breakpoint_ops;
-  ops->re_set = re_set_exception_catchpoint;
-  ops->print_it = print_it_exception_catchpoint;
-  ops->print_one = print_one_exception_catchpoint;
-  ops->print_mention = print_mention_exception_catchpoint;
-  ops->print_recreate = print_recreate_exception_catchpoint;
-  ops->print_one_detail = print_one_detail_exception_catchpoint;
-  ops->check_status = check_status_exception_catchpoint;
-  ops->allocate_location = allocate_location_exception_catchpoint;
-}
-
 void _initialize_break_catch_throw ();
 void
 _initialize_break_catch_throw ()
 {
-  initialize_throw_catchpoint_ops ();
-
   /* Add catch and tcatch sub-commands.  */
   add_catch_command ("catch", _("\
 Catch an exception, when caught."),
-- 
2.31.1


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

* [PATCH 17/36] Convert internal breakpoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (15 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 16/36] Convert break-catch-throw " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 18/36] Convert momentary " Tom Tromey
                   ` (19 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts internal breakpoints to use vtable_breakpoint_ops.
---
 gdb/breakpoint.c | 61 ++++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 36 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e9b6a801646..8cd5fe00940 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -234,9 +234,6 @@ static int strace_marker_p (struct breakpoint *b);
    (user breakpoints, internal and momentary breakpoints, etc.).  */
 static struct breakpoint_ops bkpt_base_breakpoint_ops;
 
-/* Internal breakpoints class type.  */
-static struct breakpoint_ops internal_breakpoint_ops;
-
 /* Momentary breakpoints class type.  */
 static struct breakpoint_ops momentary_breakpoint_ops;
 
@@ -261,6 +258,10 @@ struct ordinary_breakpoint : public base_breakpoint
 /* Internal breakpoints.  */
 struct internal_breakpoint : public base_breakpoint
 {
+  void re_set () override;
+  void check_status (struct bpstat *bs) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  void print_mention () override;
 };
 
 /* Momentary breakpoints.  */
@@ -3316,7 +3317,7 @@ create_overlay_event_breakpoint (void)
       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
       b = create_internal_breakpoint (objfile->arch (), addr,
 				      bp_overlay_event,
-				      &internal_breakpoint_ops);
+				      &vtable_breakpoint_ops);
       initialize_explicit_location (&explicit_loc);
       explicit_loc.function_name = ASTRDUP (func_name);
       b->location = new_explicit_location (&explicit_loc);
@@ -3376,7 +3377,7 @@ create_longjmp_master_breakpoint_probe (objfile *objfile)
       b = create_internal_breakpoint (gdbarch,
 				      p->get_relocated_address (objfile),
 				      bp_longjmp_master,
-				      &internal_breakpoint_ops);
+				      &vtable_breakpoint_ops);
       b->location = new_probe_location ("-probe-stap libc:longjmp");
       b->enable_state = bp_disabled;
     }
@@ -3425,7 +3426,7 @@ create_longjmp_master_breakpoint_names (objfile *objfile)
 
       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
       b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
-				      &internal_breakpoint_ops);
+				      &vtable_breakpoint_ops);
       initialize_explicit_location (&explicit_loc);
       explicit_loc.function_name = ASTRDUP (func_name);
       b->location = new_explicit_location (&explicit_loc);
@@ -3509,7 +3510,7 @@ create_std_terminate_master_breakpoint (void)
 	  addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
 	  b = create_internal_breakpoint (objfile->arch (), addr,
 					  bp_std_terminate_master,
-					  &internal_breakpoint_ops);
+					  &vtable_breakpoint_ops);
 	  initialize_explicit_location (&explicit_loc);
 	  explicit_loc.function_name = ASTRDUP (func_name);
 	  b->location = new_explicit_location (&explicit_loc);
@@ -3562,7 +3563,7 @@ create_exception_master_breakpoint_probe (objfile *objfile)
       b = create_internal_breakpoint (gdbarch,
 				      p->get_relocated_address (objfile),
 				      bp_exception_master,
-				      &internal_breakpoint_ops);
+				      &vtable_breakpoint_ops);
       b->location = new_probe_location ("-probe-stap libgcc:unwind");
       b->enable_state = bp_disabled;
     }
@@ -3608,7 +3609,7 @@ create_exception_master_breakpoint_hook (objfile *objfile)
   addr = gdbarch_convert_from_func_ptr_addr
     (gdbarch, addr, current_inferior ()->top_target ());
   b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
-				  &internal_breakpoint_ops);
+				  &vtable_breakpoint_ops);
   initialize_explicit_location (&explicit_loc);
   explicit_loc.function_name = ASTRDUP (func_name);
   b->location = new_explicit_location (&explicit_loc);
@@ -7488,7 +7489,7 @@ create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
   struct breakpoint *b;
 
   b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
-				  &internal_breakpoint_ops);
+				  &vtable_breakpoint_ops);
 
   b->enable_state = bp_enabled;
   /* location has to be used or breakpoint_re_set will delete me.  */
@@ -7511,7 +7512,7 @@ struct breakpoint *
 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
 {
   return create_internal_breakpoint (gdbarch, address, bp_jit_event,
-				     &internal_breakpoint_ops);
+				     &vtable_breakpoint_ops);
 }
 
 /* Remove JIT code registration and unregistration breakpoint(s).  */
@@ -7556,7 +7557,7 @@ create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
   struct breakpoint *b;
 
   b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
-				  &internal_breakpoint_ops);
+				  &vtable_breakpoint_ops);
   update_global_location_list_nothrow (insert_mode);
   return b;
 }
@@ -11996,10 +11997,10 @@ base_breakpoint::decode_location (struct event_location *location,
 
 /* Virtual table for internal breakpoints.  */
 
-static void
-internal_bkpt_re_set (struct breakpoint *b)
+void
+internal_breakpoint::re_set ()
 {
-  switch (b->type)
+  switch (type)
     {
       /* Delete overlay event and longjmp master breakpoints; they
 	 will be reset later by breakpoint_re_set.  */
@@ -12007,7 +12008,7 @@ internal_bkpt_re_set (struct breakpoint *b)
     case bp_longjmp_master:
     case bp_std_terminate_master:
     case bp_exception_master:
-      delete_breakpoint (b);
+      delete_breakpoint (this);
       break;
 
       /* This breakpoint is special, it's set up when the inferior
@@ -12021,10 +12022,10 @@ internal_bkpt_re_set (struct breakpoint *b)
     }
 }
 
-static void
-internal_bkpt_check_status (bpstat *bs)
+void
+internal_breakpoint::check_status (bpstat *bs)
 {
-  if (bs->breakpoint_at->type == bp_shlib_event)
+  if (type == bp_shlib_event)
     {
       /* If requested, stop when the dynamic linker notifies GDB of
 	 events.  This allows the user to get control and place
@@ -12037,14 +12038,10 @@ internal_bkpt_check_status (bpstat *bs)
     bs->stop = 0;
 }
 
-static enum print_stop_action
-internal_bkpt_print_it (bpstat *bs)
+enum print_stop_action
+internal_breakpoint::print_it (bpstat *bs)
 {
-  struct breakpoint *b;
-
-  b = bs->breakpoint_at;
-
-  switch (b->type)
+  switch (type)
     {
     case bp_shlib_event:
       /* Did we stop because the user set the stop_on_solib_events
@@ -12085,8 +12082,8 @@ internal_bkpt_print_it (bpstat *bs)
   return PRINT_NOTHING;
 }
 
-static void
-internal_bkpt_print_mention (struct breakpoint *b)
+void
+internal_breakpoint::print_mention ()
 {
   /* Nothing to mention.  These breakpoints are internal.  */
 }
@@ -14594,14 +14591,6 @@ initialize_breakpoint_ops (void)
   ops->print_mention = print_mention_ranged_breakpoint;
   ops->print_recreate = print_recreate_ranged_breakpoint;
 
-  /* Internal breakpoints.  */
-  ops = &internal_breakpoint_ops;
-  *ops = bkpt_base_breakpoint_ops;
-  ops->re_set = internal_bkpt_re_set;
-  ops->check_status = internal_bkpt_check_status;
-  ops->print_it = internal_bkpt_print_it;
-  ops->print_mention = internal_bkpt_print_mention;
-
   /* Momentary breakpoints.  */
   ops = &momentary_breakpoint_ops;
   *ops = bkpt_base_breakpoint_ops;
-- 
2.31.1


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

* [PATCH 18/36] Convert momentary breakpoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (16 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 17/36] Convert internal breakpoints " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 19/36] Change inheritance of dprintf Tom Tromey
                   ` (18 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts momentary breakpoints to use vtable_breakpoint_ops.
---
 gdb/breakpoint.c | 45 +++++++++++++++++++--------------------------
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 8cd5fe00940..2c438c5daf4 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -234,9 +234,6 @@ static int strace_marker_p (struct breakpoint *b);
    (user breakpoints, internal and momentary breakpoints, etc.).  */
 static struct breakpoint_ops bkpt_base_breakpoint_ops;
 
-/* Momentary breakpoints class type.  */
-static struct breakpoint_ops momentary_breakpoint_ops;
-
 /* The breakpoint_ops structure to be used in regular user created
    breakpoints.  */
 struct breakpoint_ops bkpt_breakpoint_ops;
@@ -267,6 +264,10 @@ struct internal_breakpoint : public base_breakpoint
 /* Momentary breakpoints.  */
 struct momentary_breakpoint : public base_breakpoint
 {
+  void re_set () override;
+  void check_status (struct bpstat *bs) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  void print_mention () override;
 };
 
 /* DPrintf breakpoints.  */
@@ -7292,7 +7293,7 @@ set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
 	/* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
 	   after their removal.  */
 	clone = momentary_breakpoint_from_master (b, type,
-						  &momentary_breakpoint_ops, 1);
+						  &vtable_breakpoint_ops, 1);
 	clone->thread = thread;
       }
 
@@ -7338,7 +7339,7 @@ set_longjmp_breakpoint_for_call_dummy (void)
 	struct breakpoint *new_b;
 
 	new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
-						  &momentary_breakpoint_ops,
+						  &vtable_breakpoint_ops,
 						  1);
 	new_b->thread = inferior_thread ()->global_num;
 
@@ -7470,7 +7471,7 @@ set_std_terminate_breakpoint (void)
 	&& b->type == bp_std_terminate_master)
       {
 	momentary_breakpoint_from_master (b, bp_std_terminate,
-					  &momentary_breakpoint_ops, 1);
+					  &vtable_breakpoint_ops, 1);
       }
 }
 
@@ -7877,7 +7878,7 @@ new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
   std::unique_ptr<breakpoint> b (new momentary_breakpoint ());
 
   init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
-					&momentary_breakpoint_ops);
+					&vtable_breakpoint_ops);
 
   b->disposition = disp_donttouch;
   b->frame_id = null_frame_id;
@@ -7902,7 +7903,7 @@ set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
      tail-called one.  */
   gdb_assert (!frame_id_artificial_p (frame_id));
 
-  b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
+  b = set_raw_breakpoint (gdbarch, sal, type, &vtable_breakpoint_ops);
   b->enable_state = bp_enabled;
   b->disposition = disp_donttouch;
   b->frame_id = frame_id;
@@ -7961,7 +7962,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
   if (orig == NULL)
     return NULL;
 
-  gdb_assert (orig->ops = &momentary_breakpoint_ops);
+  gdb_assert (orig->ops = &vtable_breakpoint_ops);
   return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
 }
 
@@ -10144,7 +10145,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
 	  scope_breakpoint
 	    = create_internal_breakpoint (caller_arch, caller_pc,
 					  bp_watchpoint_scope,
-					  &momentary_breakpoint_ops);
+					  &vtable_breakpoint_ops);
 
 	  /* create_internal_breakpoint could invalidate WP_FRAME.  */
 	  wp_frame = NULL;
@@ -12090,8 +12091,8 @@ internal_breakpoint::print_mention ()
 
 /* Virtual table for momentary breakpoints  */
 
-static void
-momentary_bkpt_re_set (struct breakpoint *b)
+void
+momentary_breakpoint::re_set ()
 {
   /* Keep temporary breakpoints, which can be encountered when we step
      over a dlopen call and solib_add is resetting the breakpoints.
@@ -12099,20 +12100,20 @@ momentary_bkpt_re_set (struct breakpoint *b)
      or by breakpoint_init_inferior when we rerun the executable.  */
 }
 
-static void
-momentary_bkpt_check_status (bpstat *bs)
+void
+momentary_breakpoint::check_status (bpstat *bs)
 {
   /* Nothing.  The point of these breakpoints is causing a stop.  */
 }
 
-static enum print_stop_action
-momentary_bkpt_print_it (bpstat *bs)
+enum print_stop_action
+momentary_breakpoint::print_it (bpstat *bs)
 {
   return PRINT_UNKNOWN;
 }
 
-static void
-momentary_bkpt_print_mention (struct breakpoint *b)
+void
+momentary_breakpoint::print_mention ()
 {
   /* Nothing to mention.  These breakpoints are internal.  */
 }
@@ -14591,14 +14592,6 @@ initialize_breakpoint_ops (void)
   ops->print_mention = print_mention_ranged_breakpoint;
   ops->print_recreate = print_recreate_ranged_breakpoint;
 
-  /* Momentary breakpoints.  */
-  ops = &momentary_breakpoint_ops;
-  *ops = bkpt_base_breakpoint_ops;
-  ops->re_set = momentary_bkpt_re_set;
-  ops->check_status = momentary_bkpt_check_status;
-  ops->print_it = momentary_bkpt_print_it;
-  ops->print_mention = momentary_bkpt_print_mention;
-
   /* Probe breakpoints.  */
   ops = &bkpt_probe_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-- 
2.31.1


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

* [PATCH 19/36] Change inheritance of dprintf
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (17 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 18/36] Convert momentary " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 20/36] Convert ordinary breakpoints to vtable ops Tom Tromey
                   ` (17 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The dprintf breakpoint ops is mostly a copy of bpkt_breakpoint_ops,
except it's written out explicitly -- and, importantly, there's
nothing that bpkt_breakpoint_ops overrides that dprintf does not.
This changes dprintf to simply inherit directly, and updates struct
dprintf_breakpoint to reflect the change as well.
---
 gdb/breakpoint.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 2c438c5daf4..d96d0163785 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -271,7 +271,7 @@ struct momentary_breakpoint : public base_breakpoint
 };
 
 /* DPrintf breakpoints.  */
-struct dprintf_breakpoint : public base_breakpoint
+struct dprintf_breakpoint : public ordinary_breakpoint
 {
 };
 
@@ -14614,11 +14614,8 @@ initialize_breakpoint_ops (void)
   ops->decode_location = strace_marker_decode_location;
 
   ops = &dprintf_breakpoint_ops;
-  *ops = bkpt_base_breakpoint_ops;
+  *ops = bkpt_breakpoint_ops;
   ops->re_set = dprintf_re_set;
-  ops->resources_needed = bkpt_resources_needed;
-  ops->print_it = bkpt_print_it;
-  ops->print_mention = bkpt_print_mention;
   ops->print_recreate = dprintf_print_recreate;
   ops->after_condition_true = dprintf_after_condition_true;
   ops->breakpoint_hit = dprintf_breakpoint_hit;
-- 
2.31.1


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

* [PATCH 20/36] Convert ordinary breakpoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (18 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 19/36] Change inheritance of dprintf Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 21/36] Convert Ada catchpoints " Tom Tromey
                   ` (16 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts "ordinary" breakpoint to use vtable_breakpoint_ops.
Recall that an ordinary breakpoint is both the kind normally created
by users, and also a base class used by other classes.
---
 gdb/ada-lang.c                   |  4 +-
 gdb/breakpoint.c                 | 94 ++++++++++++++------------------
 gdb/breakpoint.h                 |  1 -
 gdb/mi/mi-cmd-break.c            |  2 +-
 gdb/python/py-finishbreakpoint.c |  2 +-
 5 files changed, 45 insertions(+), 58 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index a2a6275fb5f..6df770d27cd 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11728,7 +11728,7 @@ re_set_exception (struct breakpoint *b)
 
   /* Call the base class's method.  This updates the catchpoint's
      locations.  */
-  bkpt_breakpoint_ops.re_set (b);
+  b->re_set ();
 
   /* Reparse the exception conditional expressions.  One for each
      location.  */
@@ -13407,7 +13407,7 @@ initialize_ada_catchpoint_ops (void)
   initialize_breakpoint_ops ();
 
   ops = &catch_exception_breakpoint_ops;
-  *ops = bkpt_breakpoint_ops;
+  *ops = vtable_breakpoint_ops;
   ops->allocate_location = allocate_location_exception;
   ops->re_set = re_set_exception;
   ops->check_status = check_status_exception;
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d96d0163785..4b2f97d1173 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -234,10 +234,6 @@ static int strace_marker_p (struct breakpoint *b);
    (user breakpoints, internal and momentary breakpoints, etc.).  */
 static struct breakpoint_ops bkpt_base_breakpoint_ops;
 
-/* The breakpoint_ops structure to be used in regular user created
-   breakpoints.  */
-struct breakpoint_ops bkpt_breakpoint_ops;
-
 /* Breakpoints set on probes.  */
 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
 
@@ -250,6 +246,10 @@ struct breakpoint_ops dprintf_breakpoint_ops;
 /* The structure to be used in regular breakpoints.  */
 struct ordinary_breakpoint : public base_breakpoint
 {
+  int resources_needed (const struct bp_location *) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
 };
 
 /* Internal breakpoints.  */
@@ -8752,7 +8752,7 @@ breakpoint_ops_for_event_location_type (enum event_location_type location_type,
       if (location_type == PROBE_LOCATION)
 	return &bkpt_probe_breakpoint_ops;
       else
-	return &bkpt_breakpoint_ops;
+	return &vtable_breakpoint_ops;
     }
 }
 
@@ -8765,7 +8765,7 @@ breakpoint_ops_for_event_location (const struct event_location *location,
   if (location != nullptr)
     return breakpoint_ops_for_event_location_type
       (event_location_type (location), is_tracepoint);
-  return is_tracepoint ? &vtable_breakpoint_ops : &bkpt_breakpoint_ops;
+  return &vtable_breakpoint_ops;
 }
 
 /* See breakpoint.h.  */
@@ -11888,105 +11888,101 @@ dprintf_breakpoint_hit (const struct bp_location *bl,
   return bl->owner->breakpoint_hit (bl, aspace, bp_addr, ws);
 }
 
-static int
-bkpt_resources_needed (const struct bp_location *bl)
+int
+ordinary_breakpoint::resources_needed (const struct bp_location *bl)
 {
-  gdb_assert (bl->owner->type == bp_hardware_breakpoint);
+  gdb_assert (type == bp_hardware_breakpoint);
 
   return 1;
 }
 
-static enum print_stop_action
-bkpt_print_it (bpstat *bs)
+enum print_stop_action
+ordinary_breakpoint::print_it (bpstat *bs)
 {
-  struct breakpoint *b;
   const struct bp_location *bl;
   int bp_temp;
   struct ui_out *uiout = current_uiout;
 
-  gdb_assert (bs->bp_location_at != NULL);
-
   bl = bs->bp_location_at.get ();
-  b = bs->breakpoint_at;
 
-  bp_temp = b->disposition == disp_del;
+  bp_temp = disposition == disp_del;
   if (bl->address != bl->requested_address)
     breakpoint_adjustment_warning (bl->requested_address,
 				   bl->address,
-				   b->number, 1);
-  annotate_breakpoint (b->number);
+				   number, 1);
+  annotate_breakpoint (number);
   maybe_print_thread_hit_breakpoint (uiout);
 
   if (uiout->is_mi_like_p ())
     {
       uiout->field_string ("reason",
 			   async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
-      uiout->field_string ("disp", bpdisp_text (b->disposition));
+      uiout->field_string ("disp", bpdisp_text (disposition));
     }
   if (bp_temp)
     uiout->message ("Temporary breakpoint %pF, ",
-		    signed_field ("bkptno", b->number));
+		    signed_field ("bkptno", number));
   else
     uiout->message ("Breakpoint %pF, ",
-		    signed_field ("bkptno", b->number));
+		    signed_field ("bkptno", number));
 
   return PRINT_SRC_AND_LOC;
 }
 
-static void
-bkpt_print_mention (struct breakpoint *b)
+void
+ordinary_breakpoint::print_mention ()
 {
   if (current_uiout->is_mi_like_p ())
     return;
 
-  switch (b->type)
+  switch (type)
     {
     case bp_breakpoint:
     case bp_gnu_ifunc_resolver:
-      if (b->disposition == disp_del)
+      if (disposition == disp_del)
 	printf_filtered (_("Temporary breakpoint"));
       else
 	printf_filtered (_("Breakpoint"));
-      printf_filtered (_(" %d"), b->number);
-      if (b->type == bp_gnu_ifunc_resolver)
+      printf_filtered (_(" %d"), number);
+      if (type == bp_gnu_ifunc_resolver)
 	printf_filtered (_(" at gnu-indirect-function resolver"));
       break;
     case bp_hardware_breakpoint:
-      printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
+      printf_filtered (_("Hardware assisted breakpoint %d"), number);
       break;
     case bp_dprintf:
-      printf_filtered (_("Dprintf %d"), b->number);
+      printf_filtered (_("Dprintf %d"), number);
       break;
     }
 
-  say_where (b);
+  say_where (this);
 }
 
-static void
-bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
+void
+ordinary_breakpoint::print_recreate (struct ui_file *fp)
 {
-  if (tp->type == bp_breakpoint && tp->disposition == disp_del)
+  if (type == bp_breakpoint && disposition == disp_del)
     fprintf_unfiltered (fp, "tbreak");
-  else if (tp->type == bp_breakpoint)
+  else if (type == bp_breakpoint)
     fprintf_unfiltered (fp, "break");
-  else if (tp->type == bp_hardware_breakpoint
-	   && tp->disposition == disp_del)
+  else if (type == bp_hardware_breakpoint
+	   && disposition == disp_del)
     fprintf_unfiltered (fp, "thbreak");
-  else if (tp->type == bp_hardware_breakpoint)
+  else if (type == bp_hardware_breakpoint)
     fprintf_unfiltered (fp, "hbreak");
   else
     internal_error (__FILE__, __LINE__,
-		    _("unhandled breakpoint type %d"), (int) tp->type);
+		    _("unhandled breakpoint type %d"), (int) type);
 
   fprintf_unfiltered (fp, " %s",
-		      event_location_to_string (tp->location.get ()));
+		      event_location_to_string (location.get ()));
 
   /* Print out extra_string if this breakpoint is pending.  It might
      contain, for example, conditions that were set by the user.  */
-  if (tp->loc == NULL && tp->extra_string != NULL)
-    fprintf_unfiltered (fp, " %s", tp->extra_string.get ());
+  if (loc == NULL && extra_string != NULL)
+    fprintf_unfiltered (fp, " %s", extra_string.get ());
 
-  print_recreate_thread (tp, fp);
+  print_recreate_thread (this, fp);
 }
 
 std::vector<symtab_and_line>
@@ -14573,17 +14569,9 @@ initialize_breakpoint_ops (void)
   ops = &bkpt_base_breakpoint_ops;
   *ops = vtable_breakpoint_ops;
 
-  /* The breakpoint_ops structure to be used in regular breakpoints.  */
-  ops = &bkpt_breakpoint_ops;
-  *ops = bkpt_base_breakpoint_ops;
-  ops->resources_needed = bkpt_resources_needed;
-  ops->print_it = bkpt_print_it;
-  ops->print_mention = bkpt_print_mention;
-  ops->print_recreate = bkpt_print_recreate;
-
   /* Ranged breakpoints.  */
   ops = &ranged_breakpoint_ops;
-  *ops = bkpt_breakpoint_ops;
+  *ops = vtable_breakpoint_ops;
   ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
   ops->resources_needed = resources_needed_ranged_breakpoint;
   ops->print_it = print_it_ranged_breakpoint;
@@ -14594,7 +14582,7 @@ initialize_breakpoint_ops (void)
 
   /* Probe breakpoints.  */
   ops = &bkpt_probe_breakpoint_ops;
-  *ops = bkpt_breakpoint_ops;
+  *ops = vtable_breakpoint_ops;
   ops->insert_location = bkpt_probe_insert_location;
   ops->remove_location = bkpt_probe_remove_location;
   ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
@@ -14614,7 +14602,7 @@ initialize_breakpoint_ops (void)
   ops->decode_location = strace_marker_decode_location;
 
   ops = &dprintf_breakpoint_ops;
-  *ops = bkpt_breakpoint_ops;
+  *ops = vtable_breakpoint_ops;
   ops->re_set = dprintf_re_set;
   ops->print_recreate = dprintf_print_recreate;
   ops->after_condition_true = dprintf_after_condition_true;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 11b65ab8318..1ba78ecbb70 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1472,7 +1472,6 @@ extern void rwatch_command_wrapper (const char *, int, bool);
 extern void tbreak_command (const char *, int);
 
 extern struct breakpoint_ops base_breakpoint_ops;
-extern struct breakpoint_ops bkpt_breakpoint_ops;
 extern struct breakpoint_ops dprintf_breakpoint_ops;
 extern struct breakpoint_ops vtable_breakpoint_ops;
 
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index a5c78529dd1..0b8ae5d5910 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -332,7 +332,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
   else
     {
       type_wanted = hardware ? bp_hardware_breakpoint : bp_breakpoint;
-      ops = &bkpt_breakpoint_ops;
+      ops = &vtable_breakpoint_ops;
     }
 
   if (is_explicit)
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 8d5eb42efc0..00129b09240 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -300,7 +300,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 			 bp_breakpoint,
 			 0,
 			 AUTO_BOOLEAN_TRUE,
-			 &bkpt_breakpoint_ops,
+			 &vtable_breakpoint_ops,
 			 0, 1, internal_bp, 0);
     }
   catch (const gdb_exception &except)
-- 
2.31.1


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

* [PATCH 21/36] Convert Ada catchpoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (19 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 20/36] Convert ordinary breakpoints to vtable ops Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 22/36] Convert dprintf " Tom Tromey
                   ` (15 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts Ada catchpoints to use vtable_breakpoint_ops.
---
 gdb/ada-lang.c | 156 +++++++++++++++++++++----------------------------
 1 file changed, 65 insertions(+), 91 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6df770d27cd..40e369a4626 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11651,6 +11651,14 @@ struct ada_catchpoint : public breakpoint
   {
   }
 
+  struct bp_location *allocate_location () override;
+  void re_set () override;
+  void check_status (struct bpstat *bs) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+
   /* The name of the specific exception the user specified.  */
   std::string excep_string;
 
@@ -11709,30 +11717,28 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
     }
 }
 
-/* Implement the ALLOCATE_LOCATION method in the breakpoint_ops
-   structure for all exception catchpoint kinds.  */
+/* Implement the ALLOCATE_LOCATION method in the structure for all
+   exception catchpoint kinds.  */
 
-static struct bp_location *
-allocate_location_exception (struct breakpoint *self)
+struct bp_location *
+ada_catchpoint::allocate_location ()
 {
-  return new ada_catchpoint_location (self);
+  return new ada_catchpoint_location (this);
 }
 
-/* Implement the RE_SET method in the breakpoint_ops structure for all
-   exception catchpoint kinds.  */
+/* Implement the RE_SET method in the structure for all exception
+   catchpoint kinds.  */
 
-static void
-re_set_exception (struct breakpoint *b)
+void
+ada_catchpoint::re_set ()
 {
-  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
-
   /* Call the base class's method.  This updates the catchpoint's
      locations.  */
-  b->re_set ();
+  this->breakpoint::re_set ();
 
   /* Reparse the exception conditional expressions.  One for each
      location.  */
-  create_excep_cond_exprs (c, c->m_kind);
+  create_excep_cond_exprs (this, m_kind);
 }
 
 /* Returns true if we should stop for this breakpoint hit.  If the
@@ -11800,36 +11806,35 @@ should_stop_exception (const struct bp_location *bl)
   return stop;
 }
 
-/* Implement the CHECK_STATUS method in the breakpoint_ops structure
-   for all exception catchpoint kinds.  */
+/* Implement the CHECK_STATUS method in the structure for all
+   exception catchpoint kinds.  */
 
-static void
-check_status_exception (bpstat *bs)
+void
+ada_catchpoint::check_status (bpstat *bs)
 {
   bs->stop = should_stop_exception (bs->bp_location_at.get ());
 }
 
-/* Implement the PRINT_IT method in the breakpoint_ops structure
-   for all exception catchpoint kinds.  */
+/* Implement the PRINT_IT method in the structure for all exception
+   catchpoint kinds.  */
 
-static enum print_stop_action
-print_it_exception (bpstat *bs)
+enum print_stop_action
+ada_catchpoint::print_it (bpstat *bs)
 {
   struct ui_out *uiout = current_uiout;
-  struct breakpoint *b = bs->breakpoint_at;
 
-  annotate_catchpoint (b->number);
+  annotate_catchpoint (number);
 
   if (uiout->is_mi_like_p ())
     {
       uiout->field_string ("reason",
 			   async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
-      uiout->field_string ("disp", bpdisp_text (b->disposition));
+      uiout->field_string ("disp", bpdisp_text (disposition));
     }
 
-  uiout->text (b->disposition == disp_del
+  uiout->text (disposition == disp_del
 	       ? "\nTemporary catchpoint " : "\nCatchpoint ");
-  uiout->field_signed ("bkptno", b->number);
+  uiout->field_signed ("bkptno", number);
   uiout->text (", ");
 
   /* ada_exception_name_addr relies on the selected frame being the
@@ -11839,14 +11844,13 @@ print_it_exception (bpstat *bs)
      ada_find_printable_frame).  */
   select_frame (get_current_frame ());
 
-  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
-  switch (c->m_kind)
+  switch (m_kind)
     {
       case ada_catch_exception:
       case ada_catch_exception_unhandled:
       case ada_catch_handlers:
 	{
-	  const CORE_ADDR addr = ada_exception_name_addr (c->m_kind, b);
+	  const CORE_ADDR addr = ada_exception_name_addr (m_kind, this);
 	  char exception_name[256];
 
 	  if (addr != 0)
@@ -11870,7 +11874,7 @@ print_it_exception (bpstat *bs)
 	     it clearer to the user which kind of catchpoint just got
 	     hit.  We used ui_out_text to make sure that this extra
 	     info does not pollute the exception name in the MI case.  */
-	  if (c->m_kind == ada_catch_exception_unhandled)
+	  if (m_kind == ada_catch_exception_unhandled)
 	    uiout->text ("unhandled ");
 	  uiout->field_string ("exception-name", exception_name);
 	}
@@ -11899,14 +11903,13 @@ print_it_exception (bpstat *bs)
   return PRINT_SRC_AND_LOC;
 }
 
-/* Implement the PRINT_ONE method in the breakpoint_ops structure
-   for all exception catchpoint kinds.  */
+/* Implement the PRINT_ONE method in the structure for all exception
+   catchpoint kinds.  */
 
-static bool
-print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
+bool
+ada_catchpoint::print_one (struct bp_location **last_loc)
 { 
   struct ui_out *uiout = current_uiout;
-  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
   struct value_print_options opts;
 
   get_user_print_options (&opts);
@@ -11915,13 +11918,13 @@ print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
     uiout->field_skip ("addr");
 
   annotate_field (5);
-  switch (c->m_kind)
+  switch (m_kind)
     {
       case ada_catch_exception:
-	if (!c->excep_string.empty ())
+	if (!excep_string.empty ())
 	  {
 	    std::string msg = string_printf (_("`%s' Ada exception"),
-					     c->excep_string.c_str ());
+					     excep_string.c_str ());
 
 	    uiout->field_string ("what", msg);
 	  }
@@ -11935,11 +11938,11 @@ print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
 	break;
       
       case ada_catch_handlers:
-	if (!c->excep_string.empty ())
+	if (!excep_string.empty ())
 	  {
 	    uiout->field_fmt ("what",
 			      _("`%s' Ada exception handlers"),
-			      c->excep_string.c_str ());
+			      excep_string.c_str ());
 	  }
 	else
 	  uiout->field_string ("what", "all Ada exceptions handlers");
@@ -11960,24 +11963,23 @@ print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
    for all exception catchpoint kinds.  */
 
-static void
-print_mention_exception (struct breakpoint *b)
+void
+ada_catchpoint::print_mention ()
 {
-  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
   struct ui_out *uiout = current_uiout;
 
-  uiout->text (b->disposition == disp_del ? _("Temporary catchpoint ")
+  uiout->text (disposition == disp_del ? _("Temporary catchpoint ")
 						 : _("Catchpoint "));
-  uiout->field_signed ("bkptno", b->number);
+  uiout->field_signed ("bkptno", number);
   uiout->text (": ");
 
-  switch (c->m_kind)
+  switch (m_kind)
     {
       case ada_catch_exception:
-	if (!c->excep_string.empty ())
+	if (!excep_string.empty ())
 	  {
 	    std::string info = string_printf (_("`%s' Ada exception"),
-					      c->excep_string.c_str ());
+					      excep_string.c_str ());
 	    uiout->text (info);
 	  }
 	else
@@ -11989,11 +11991,11 @@ print_mention_exception (struct breakpoint *b)
 	break;
 
       case ada_catch_handlers:
-	if (!c->excep_string.empty ())
+	if (!excep_string.empty ())
 	  {
 	    std::string info
 	      = string_printf (_("`%s' Ada exception handlers"),
-			       c->excep_string.c_str ());
+			       excep_string.c_str ());
 	    uiout->text (info);
 	  }
 	else
@@ -12010,20 +12012,18 @@ print_mention_exception (struct breakpoint *b)
     }
 }
 
-/* Implement the PRINT_RECREATE method in the breakpoint_ops structure
-   for all exception catchpoint kinds.  */
+/* Implement the PRINT_RECREATE method in the structure for all
+   exception catchpoint kinds.  */
 
-static void
-print_recreate_exception (struct breakpoint *b, struct ui_file *fp)
+void
+ada_catchpoint::print_recreate (struct ui_file *fp)
 {
-  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
-
-  switch (c->m_kind)
+  switch (m_kind)
     {
       case ada_catch_exception:
 	fprintf_filtered (fp, "catch exception");
-	if (!c->excep_string.empty ())
-	  fprintf_filtered (fp, " %s", c->excep_string.c_str ());
+	if (!excep_string.empty ())
+	  fprintf_filtered (fp, " %s", excep_string.c_str ());
 	break;
 
       case ada_catch_exception_unhandled:
@@ -12041,18 +12041,15 @@ print_recreate_exception (struct breakpoint *b, struct ui_file *fp)
       default:
 	internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
     }
-  print_recreate_thread (b, fp);
+  print_recreate_thread (this, fp);
 }
 
-/* Virtual table for breakpoint type.  */
-static struct breakpoint_ops catch_exception_breakpoint_ops;
-
 /* See ada-lang.h.  */
 
 bool
 is_ada_exception_catchpoint (breakpoint *bp)
 {
-  return bp->ops == &catch_exception_breakpoint_ops;
+  return dynamic_cast<ada_catchpoint *> (bp) != nullptr;
 }
 
 /* Split the arguments specified in a "catch exception" command.  
@@ -12232,7 +12229,7 @@ ada_exception_catchpoint_cond_string (const char *excep_string,
 
 static struct symtab_and_line
 ada_exception_sal (enum ada_exception_catchpoint_kind ex,
-		   std::string *addr_string, const struct breakpoint_ops **ops)
+		   std::string *addr_string)
 {
   const char *sym_name;
   struct symbol *sym;
@@ -12254,9 +12251,6 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex,
   /* Set ADDR_STRING.  */
   *addr_string = sym_name;
 
-  /* Set OPS.  */
-  *ops = &catch_exception_breakpoint_ops;
-
   return find_function_start_sal (sym, 1);
 }
 
@@ -12285,12 +12279,12 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
 				 int from_tty)
 {
   std::string addr_string;
-  const struct breakpoint_ops *ops = NULL;
-  struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string, &ops);
+  struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string);
 
   std::unique_ptr<ada_catchpoint> c (new ada_catchpoint (ex_kind));
   init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string.c_str (),
-				 ops, tempflag, disabled, from_tty);
+				 &vtable_breakpoint_ops,
+				 tempflag, disabled, from_tty);
   c->excep_string = excep_string;
   create_excep_cond_exprs (c.get (), ex_kind);
   if (!cond_string.empty ())
@@ -13399,24 +13393,6 @@ static ada_language ada_language_defn;
 static struct cmd_list_element *set_ada_list;
 static struct cmd_list_element *show_ada_list;
 
-static void
-initialize_ada_catchpoint_ops (void)
-{
-  struct breakpoint_ops *ops;
-
-  initialize_breakpoint_ops ();
-
-  ops = &catch_exception_breakpoint_ops;
-  *ops = vtable_breakpoint_ops;
-  ops->allocate_location = allocate_location_exception;
-  ops->re_set = re_set_exception;
-  ops->check_status = check_status_exception;
-  ops->print_it = print_it_exception;
-  ops->print_one = print_one_exception;
-  ops->print_mention = print_mention_exception;
-  ops->print_recreate = print_recreate_exception;
-}
-
 /* This module's 'new_objfile' observer.  */
 
 static void
@@ -13437,8 +13413,6 @@ void _initialize_ada_language ();
 void
 _initialize_ada_language ()
 {
-  initialize_ada_catchpoint_ops ();
-
   add_setshow_prefix_cmd
     ("ada", no_class,
      _("Prefix command for changing Ada-specific settings."),
-- 
2.31.1


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

* [PATCH 22/36] Convert dprintf to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (20 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 21/36] Convert Ada catchpoints " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 23/36] Convert ranged breakpoints " Tom Tromey
                   ` (14 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts dprintf to use vtable_breakpoint_ops.
---
 gdb/breakpoint.c      | 63 ++++++++++++++++++++-----------------------
 gdb/breakpoint.h      |  1 -
 gdb/mi/mi-cmd-break.c |  2 +-
 3 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4b2f97d1173..6d7fb42f30d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -240,9 +240,6 @@ static struct breakpoint_ops bkpt_probe_breakpoint_ops;
 /* Tracepoints set on probes.  */
 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
 
-/* Dynamic printf class type.  */
-struct breakpoint_ops dprintf_breakpoint_ops;
-
 /* The structure to be used in regular breakpoints.  */
 struct ordinary_breakpoint : public base_breakpoint
 {
@@ -273,6 +270,13 @@ struct momentary_breakpoint : public base_breakpoint
 /* DPrintf breakpoints.  */
 struct dprintf_breakpoint : public ordinary_breakpoint
 {
+  void re_set () override;
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  void print_recreate (struct ui_file *fp) override;
+  void after_condition_true (struct bpstat *bs) override;
 };
 
 /* The style in which to perform a dynamic printf.  This is a user
@@ -9173,7 +9177,7 @@ dprintf_command (const char *arg, int from_tty)
 		     0, bp_dprintf,
 		     0 /* Ignore count */,
 		     pending_break_support,
-		     &dprintf_breakpoint_ops,
+		     &vtable_breakpoint_ops,
 		     from_tty,
 		     1 /* enabled */,
 		     0 /* internal */,
@@ -11871,10 +11875,11 @@ base_breakpoint::breakpoint_hit (const struct bp_location *bl,
   return 1;
 }
 
-static int
-dprintf_breakpoint_hit (const struct bp_location *bl,
-			const address_space *aspace, CORE_ADDR bp_addr,
-			const target_waitstatus &ws)
+int
+dprintf_breakpoint::breakpoint_hit (const struct bp_location *bl,
+				    const address_space *aspace,
+				    CORE_ADDR bp_addr,
+				    const target_waitstatus &ws)
 {
   if (dprintf_style == dprintf_style_agent
       && target_can_run_breakpoint_commands ())
@@ -11885,7 +11890,7 @@ dprintf_breakpoint_hit (const struct bp_location *bl,
       return 0;
     }
 
-  return bl->owner->breakpoint_hit (bl, aspace, bp_addr, ws);
+  return this->ordinary_breakpoint::breakpoint_hit (bl, aspace, bp_addr, ws);
 }
 
 int
@@ -12286,15 +12291,13 @@ tracepoint_probe_decode_location (struct breakpoint *b,
   return bkpt_probe_decode_location (b, location, search_pspace);
 }
 
-/* Dprintf breakpoint_ops methods.  */
-
-static void
-dprintf_re_set (struct breakpoint *b)
+void
+dprintf_breakpoint::re_set ()
 {
-  breakpoint_re_set_default (b);
+  breakpoint_re_set_default (this);
 
   /* extra_string should never be non-NULL for dprintf.  */
-  gdb_assert (b->extra_string != NULL);
+  gdb_assert (extra_string != NULL);
 
   /* 1 - connect to target 1, that can run breakpoint commands.
      2 - create a dprintf, which resolves fine.
@@ -12306,23 +12309,22 @@ dprintf_re_set (struct breakpoint *b)
      answers for target_can_run_breakpoint_commands().
      Given absence of finer grained resetting, we get to do
      it all the time.  */
-  if (b->extra_string != NULL)
-    update_dprintf_command_list (b);
+  if (extra_string != NULL)
+    update_dprintf_command_list (this);
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for dprintf.  */
+/* Implement the "print_recreate" method for dprintf.  */
 
-static void
-dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
+void
+dprintf_breakpoint::print_recreate (struct ui_file *fp)
 {
   fprintf_unfiltered (fp, "dprintf %s,%s",
-		      event_location_to_string (tp->location.get ()),
-		      tp->extra_string.get ());
-  print_recreate_thread (tp, fp);
+		      event_location_to_string (location.get ()),
+		      extra_string.get ());
+  print_recreate_thread (this, fp);
 }
 
-/* Implement the "after_condition_true" breakpoint_ops method for
-   dprintf.
+/* Implement the "after_condition_true" method for dprintf.
 
    dprintf's are implemented with regular commands in their command
    list, but we run the commands here instead of before presenting the
@@ -12330,8 +12332,8 @@ dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
    also makes it so that the commands of multiple dprintfs at the same
    address are all handled.  */
 
-static void
-dprintf_after_condition_true (struct bpstat *bs)
+void
+dprintf_breakpoint::after_condition_true (struct bpstat *bs)
 {
   /* dprintf's never cause a stop.  This wasn't set in the
      check_status hook instead because that would make the dprintf's
@@ -14600,13 +14602,6 @@ initialize_breakpoint_ops (void)
   ops->create_sals_from_location = strace_marker_create_sals_from_location;
   ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
   ops->decode_location = strace_marker_decode_location;
-
-  ops = &dprintf_breakpoint_ops;
-  *ops = vtable_breakpoint_ops;
-  ops->re_set = dprintf_re_set;
-  ops->print_recreate = dprintf_print_recreate;
-  ops->after_condition_true = dprintf_after_condition_true;
-  ops->breakpoint_hit = dprintf_breakpoint_hit;
 }
 
 /* Chain containing all defined "enable breakpoint" subcommands.  */
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 1ba78ecbb70..4bbfb27f733 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1472,7 +1472,6 @@ extern void rwatch_command_wrapper (const char *, int, bool);
 extern void tbreak_command (const char *, int);
 
 extern struct breakpoint_ops base_breakpoint_ops;
-extern struct breakpoint_ops dprintf_breakpoint_ops;
 extern struct breakpoint_ops vtable_breakpoint_ops;
 
 extern void initialize_breakpoint_ops (void);
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index 0b8ae5d5910..fb034317a6e 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -327,7 +327,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
   else if (dprintf)
     {
       type_wanted = bp_dprintf;
-      ops = &dprintf_breakpoint_ops;
+      ops = &vtable_breakpoint_ops;
     }
   else
     {
-- 
2.31.1


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

* [PATCH 23/36] Convert ranged breakpoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (21 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 22/36] Convert dprintf " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 24/36] Add bp_static_marker_tracepoint Tom Tromey
                   ` (13 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts ranged breakpoints to use vtable_breakpoint_ops.  This
requires introducing a new ranged_breakpoint type, but this is
relatively simple because ranged breakpoints can only be created by
break_range_command.
---
 gdb/breakpoint.c | 126 ++++++++++++++++++++++-------------------------
 1 file changed, 60 insertions(+), 66 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 6d7fb42f30d..eacaee1b349 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -279,6 +279,21 @@ struct dprintf_breakpoint : public ordinary_breakpoint
   void after_condition_true (struct bpstat *bs) override;
 };
 
+/* Ranged breakpoints.  */
+struct ranged_breakpoint : public ordinary_breakpoint
+{
+  int breakpoint_hit (const struct bp_location *bl,
+		      const address_space *aspace,
+		      CORE_ADDR bp_addr,
+		      const target_waitstatus &ws) override;
+  int resources_needed (const struct bp_location *) override;
+  enum print_stop_action print_it (struct bpstat *bs) override;
+  bool print_one (struct bp_location **) override;
+  void print_one_detail (struct ui_out *) const override;
+  void print_mention () override;
+  void print_recreate (struct ui_file *fp) override;
+};
+
 /* The style in which to perform a dynamic printf.  This is a user
    option because different output options have different tradeoffs;
    if GDB does the printing, there is better error handling if there
@@ -9190,14 +9205,13 @@ agent_printf_command (const char *arg, int from_tty)
   error (_("May only run agent-printf on the target"));
 }
 
-/* Implement the "breakpoint_hit" breakpoint_ops method for
-   ranged breakpoints.  */
+/* Implement the "breakpoint_hit" method for ranged breakpoints.  */
 
-static int
-breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
-				  const address_space *aspace,
-				  CORE_ADDR bp_addr,
-				  const target_waitstatus &ws)
+int
+ranged_breakpoint::breakpoint_hit (const struct bp_location *bl,
+				   const address_space *aspace,
+				   CORE_ADDR bp_addr,
+				   const target_waitstatus &ws)
 {
   if (ws.kind () != TARGET_WAITKIND_STOPPED
       || ws.sig () != GDB_SIGNAL_TRAP)
@@ -9207,35 +9221,32 @@ breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
 					 bl->length, aspace, bp_addr);
 }
 
-/* Implement the "resources_needed" breakpoint_ops method for
-   ranged breakpoints.  */
+/* Implement the "resources_needed" method for ranged breakpoints.  */
 
-static int
-resources_needed_ranged_breakpoint (const struct bp_location *bl)
+int
+ranged_breakpoint::resources_needed (const struct bp_location *bl)
 {
   return target_ranged_break_num_registers ();
 }
 
-/* Implement the "print_it" breakpoint_ops method for
-   ranged breakpoints.  */
+/* Implement the "print_it" method for ranged breakpoints.  */
 
-static enum print_stop_action
-print_it_ranged_breakpoint (bpstat *bs)
+enum print_stop_action
+ranged_breakpoint::print_it (bpstat *bs)
 {
-  struct breakpoint *b = bs->breakpoint_at;
-  struct bp_location *bl = b->loc;
+  struct bp_location *bl = loc;
   struct ui_out *uiout = current_uiout;
 
-  gdb_assert (b->type == bp_hardware_breakpoint);
+  gdb_assert (type == bp_hardware_breakpoint);
 
   /* Ranged breakpoints have only one location.  */
   gdb_assert (bl && bl->next == NULL);
 
-  annotate_breakpoint (b->number);
+  annotate_breakpoint (number);
 
   maybe_print_thread_hit_breakpoint (uiout);
 
-  if (b->disposition == disp_del)
+  if (disposition == disp_del)
     uiout->text ("Temporary ranged breakpoint ");
   else
     uiout->text ("Ranged breakpoint ");
@@ -9243,22 +9254,20 @@ print_it_ranged_breakpoint (bpstat *bs)
     {
       uiout->field_string ("reason",
 		      async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
-      uiout->field_string ("disp", bpdisp_text (b->disposition));
+      uiout->field_string ("disp", bpdisp_text (disposition));
     }
-  uiout->field_signed ("bkptno", b->number);
+  uiout->field_signed ("bkptno", number);
   uiout->text (", ");
 
   return PRINT_SRC_AND_LOC;
 }
 
-/* Implement the "print_one" breakpoint_ops method for
-   ranged breakpoints.  */
+/* Implement the "print_one" method for ranged breakpoints.  */
 
-static bool
-print_one_ranged_breakpoint (struct breakpoint *b,
-			     struct bp_location **last_loc)
+bool
+ranged_breakpoint::print_one (struct bp_location **last_loc)
 {
-  struct bp_location *bl = b->loc;
+  struct bp_location *bl = loc;
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
@@ -9272,21 +9281,19 @@ print_one_ranged_breakpoint (struct breakpoint *b,
        by print_one_detail_ranged_breakpoint.  */
     uiout->field_skip ("addr");
   annotate_field (5);
-  print_breakpoint_location (b, bl);
+  print_breakpoint_location (this, bl);
   *last_loc = bl;
 
   return true;
 }
 
-/* Implement the "print_one_detail" breakpoint_ops method for
-   ranged breakpoints.  */
+/* Implement the "print_one_detail" method for ranged breakpoints.  */
 
-static void
-print_one_detail_ranged_breakpoint (const struct breakpoint *b,
-				    struct ui_out *uiout)
+void
+ranged_breakpoint::print_one_detail (struct ui_out *uiout) const
 {
   CORE_ADDR address_start, address_end;
-  struct bp_location *bl = b->loc;
+  struct bp_location *bl = loc;
   string_file stb;
 
   gdb_assert (bl);
@@ -9302,39 +9309,33 @@ print_one_detail_ranged_breakpoint (const struct breakpoint *b,
   uiout->text ("\n");
 }
 
-/* Implement the "print_mention" breakpoint_ops method for
-   ranged breakpoints.  */
+/* Implement the "print_mention" method for ranged breakpoints.  */
 
-static void
-print_mention_ranged_breakpoint (struct breakpoint *b)
+void
+ranged_breakpoint::print_mention ()
 {
-  struct bp_location *bl = b->loc;
+  struct bp_location *bl = loc;
   struct ui_out *uiout = current_uiout;
 
   gdb_assert (bl);
-  gdb_assert (b->type == bp_hardware_breakpoint);
+  gdb_assert (type == bp_hardware_breakpoint);
 
   uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
-		  b->number, paddress (bl->gdbarch, bl->address),
+		  number, paddress (bl->gdbarch, bl->address),
 		  paddress (bl->gdbarch, bl->address + bl->length - 1));
 }
 
-/* Implement the "print_recreate" breakpoint_ops method for
-   ranged breakpoints.  */
+/* Implement the "print_recreate" method for ranged breakpoints.  */
 
-static void
-print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
+void
+ranged_breakpoint::print_recreate (struct ui_file *fp)
 {
   fprintf_unfiltered (fp, "break-range %s, %s",
-		      event_location_to_string (b->location.get ()),
-		      event_location_to_string (b->location_range_end.get ()));
-  print_recreate_thread (b, fp);
+		      event_location_to_string (location.get ()),
+		      event_location_to_string (location_range_end.get ()));
+  print_recreate_thread (this, fp);
 }
 
-/* The breakpoint_ops structure to be used in ranged breakpoints.  */
-
-static struct breakpoint_ops ranged_breakpoint_ops;
-
 /* Find the address where the end of the breakpoint range should be
    placed, given the SAL of the end of the range.  This is so that if
    the user provides a line number, the end of the range is set to the
@@ -9456,8 +9457,12 @@ break_range_command (const char *arg, int from_tty)
     }
 
   /* Now set up the breakpoint.  */
-  b = set_raw_breakpoint (get_current_arch (), sal_start,
-			  bp_hardware_breakpoint, &ranged_breakpoint_ops);
+  std::unique_ptr<breakpoint> br (new ranged_breakpoint ());
+  init_raw_breakpoint (br.get (), get_current_arch (),
+		       sal_start, bp_hardware_breakpoint,
+		       &vtable_breakpoint_ops);
+  b = add_to_breakpoint_chain (std::move (br));
+
   set_breakpoint_count (breakpoint_count + 1);
   b->number = breakpoint_count;
   b->disposition = disp_donttouch;
@@ -14571,17 +14576,6 @@ initialize_breakpoint_ops (void)
   ops = &bkpt_base_breakpoint_ops;
   *ops = vtable_breakpoint_ops;
 
-  /* Ranged breakpoints.  */
-  ops = &ranged_breakpoint_ops;
-  *ops = vtable_breakpoint_ops;
-  ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
-  ops->resources_needed = resources_needed_ranged_breakpoint;
-  ops->print_it = print_it_ranged_breakpoint;
-  ops->print_one = print_one_ranged_breakpoint;
-  ops->print_one_detail = print_one_detail_ranged_breakpoint;
-  ops->print_mention = print_mention_ranged_breakpoint;
-  ops->print_recreate = print_recreate_ranged_breakpoint;
-
   /* Probe breakpoints.  */
   ops = &bkpt_probe_breakpoint_ops;
   *ops = vtable_breakpoint_ops;
-- 
2.31.1


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

* [PATCH 24/36] Add bp_static_marker_tracepoint
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (22 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 23/36] Convert ranged breakpoints " Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 25/36] Convert static marker tracepoints to vtable ops Tom Tromey
                   ` (12 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Because the actual construction of a breakpoint is buried deep in
create_breakpoint, at present it's necessary to have a new bp_
enumerator constant any time a new subclass is needed.  Static marker
tracepoints are one such case, so this patch introduces
bp_static_marker_tracepoint and updates various spots to recognize it.
---
 gdb/breakpoint.c | 32 +++++++++++++++++++++++---------
 gdb/breakpoint.h |  2 ++
 gdb/remote.c     |  3 ++-
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index eacaee1b349..e1c6efafc25 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1180,7 +1180,8 @@ is_tracepoint_type (bptype type)
 {
   return (type == bp_tracepoint
 	  || type == bp_fast_tracepoint
-	  || type == bp_static_tracepoint);
+	  || type == bp_static_tracepoint
+	  || type == bp_static_marker_tracepoint);
 }
 
 /* See breakpoint.h.  */
@@ -1208,6 +1209,7 @@ new_breakpoint_from_type (bptype type)
 
     case bp_fast_tracepoint:
     case bp_static_tracepoint:
+    case bp_static_marker_tracepoint:
     case bp_tracepoint:
       b = new tracepoint ();
       break;
@@ -1288,7 +1290,8 @@ validate_commands_for_breakpoint (struct breakpoint *b,
 	      if (b->type == bp_fast_tracepoint)
 		error (_("The 'while-stepping' command "
 			 "cannot be used for fast tracepoint"));
-	      else if (b->type == bp_static_tracepoint)
+	      else if (b->type == bp_static_tracepoint
+		       || b->type == bp_static_marker_tracepoint)
 		error (_("The 'while-stepping' command "
 			 "cannot be used for static tracepoint"));
 
@@ -1329,7 +1332,8 @@ static_tracepoints_here (CORE_ADDR addr)
   std::vector<breakpoint *> found;
 
   for (breakpoint *b : all_breakpoints ())
-    if (b->type == bp_static_tracepoint)
+    if (b->type == bp_static_tracepoint
+	|| b->type == bp_static_marker_tracepoint)
       {
 	for (bp_location *loc : b->locations ())
 	  if (loc->address == addr)
@@ -5728,6 +5732,7 @@ bpstat_what (bpstat *bs_head)
 	case bp_tracepoint:
 	case bp_fast_tracepoint:
 	case bp_static_tracepoint:
+	case bp_static_marker_tracepoint:
 	  /* Tracepoint hits should not be reported back to GDB, and
 	     if one got through somehow, it should have been filtered
 	     out already.  */
@@ -6019,6 +6024,7 @@ bptype_string (enum bptype type)
     {bp_tracepoint, "tracepoint"},
     {bp_fast_tracepoint, "fast tracepoint"},
     {bp_static_tracepoint, "static tracepoint"},
+    {bp_static_marker_tracepoint, "static marker tracepoint"},
     {bp_dprintf, "dprintf"},
     {bp_jit_event, "jit events"},
     {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
@@ -7080,6 +7086,7 @@ bp_location_from_bp_type (bptype type)
     case bp_tracepoint:
     case bp_fast_tracepoint:
     case bp_static_tracepoint:
+    case bp_static_marker_tracepoint:
       return bp_loc_other;
     default:
       internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
@@ -8292,7 +8299,8 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
 	  if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
 	    b->loc->inserted = 1;
 
-	  if (type == bp_static_tracepoint)
+	  if (type == bp_static_tracepoint
+	      || type == bp_static_marker_tracepoint)
 	    {
 	      struct tracepoint *t = (struct tracepoint *) b;
 	      struct static_tracepoint_marker marker;
@@ -12211,7 +12219,8 @@ tracepoint::print_one_detail (struct ui_out *uiout) const
 {
   if (!static_trace_marker_id.empty ())
     {
-      gdb_assert (type == bp_static_tracepoint);
+      gdb_assert (type == bp_static_tracepoint
+		  || type == bp_static_marker_tracepoint);
 
       uiout->message ("\tmarker id is %pF\n",
 		      string_field ("static-tracepoint-marker-string-id",
@@ -12236,6 +12245,7 @@ tracepoint::print_mention ()
       printf_filtered (_(" %d"), number);
       break;
     case bp_static_tracepoint:
+    case bp_static_marker_tracepoint:
       printf_filtered (_("Static tracepoint"));
       printf_filtered (_(" %d"), number);
       break;
@@ -12252,7 +12262,8 @@ tracepoint::print_recreate (struct ui_file *fp)
 {
   if (type == bp_fast_tracepoint)
     fprintf_unfiltered (fp, "ftrace");
-  else if (type == bp_static_tracepoint)
+  else if (type == bp_static_tracepoint
+	   || type == bp_static_marker_tracepoint)
     fprintf_unfiltered (fp, "strace");
   else if (type == bp_tracepoint)
     fprintf_unfiltered (fp, "trace");
@@ -12451,7 +12462,7 @@ static struct breakpoint_ops strace_marker_breakpoint_ops;
 static int
 strace_marker_p (struct breakpoint *b)
 {
-  return b->ops == &strace_marker_breakpoint_ops;
+  return b->type == bp_static_marker_tracepoint;
 }
 
 /* Delete a breakpoint and clean up all traces of it in the data
@@ -13056,7 +13067,7 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
 	  b->condition_not_parsed = 0;
 	}
 
-      if (b->type == bp_static_tracepoint && !strace_marker_p (b))
+      if (b->type == bp_static_tracepoint)
 	sals[0] = update_static_tracepoint (b, sals[0]);
 
       *found = 1;
@@ -13933,6 +13944,7 @@ strace_command (const char *arg, int from_tty)
 {
   struct breakpoint_ops *ops;
   event_location_up location;
+  enum bptype type;
 
   /* Decide if we are dealing with a static tracepoint marker (`-m'),
      or with a normal static tracepoint.  */
@@ -13940,18 +13952,20 @@ strace_command (const char *arg, int from_tty)
     {
       ops = &strace_marker_breakpoint_ops;
       location = new_linespec_location (&arg, symbol_name_match_type::FULL);
+      type = bp_static_marker_tracepoint;
     }
   else
     {
       ops = &vtable_breakpoint_ops;
       location = string_to_event_location (&arg, current_language);
+      type = bp_static_tracepoint;
     }
 
   create_breakpoint (get_current_arch (),
 		     location.get (),
 		     NULL, 0, arg, false, 1 /* parse arg */,
 		     0 /* tempflag */,
-		     bp_static_tracepoint /* type_wanted */,
+		     type /* type_wanted */,
 		     0 /* Ignore count */,
 		     pending_break_support,
 		     ops,
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 4bbfb27f733..e362cd454ec 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -183,6 +183,8 @@ enum bptype
     bp_tracepoint,
     bp_fast_tracepoint,
     bp_static_tracepoint,
+    /* Like bp_static_tracepoint but for static markers.  */
+    bp_static_marker_tracepoint,
 
     /* A dynamic printf stops at the given location, does a formatted
        print, then automatically continues.  (Although this is sort of
diff --git a/gdb/remote.c b/gdb/remote.c
index b093ad86675..e739a8f4ceb 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13236,7 +13236,8 @@ remote_target::download_tracepoint (struct bp_location *loc)
 	warning (_("Target does not support fast tracepoints, "
 		   "downloading %d as regular tracepoint"), b->number);
     }
-  else if (b->type == bp_static_tracepoint)
+  else if (b->type == bp_static_tracepoint
+	   || b->type == bp_static_marker_tracepoint)
     {
       /* Only test for support at download time; we may not know
 	 target capabilities at definition time.  */
-- 
2.31.1


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

* [PATCH 25/36] Convert static marker tracepoints to vtable ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (23 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 24/36] Add bp_static_marker_tracepoint Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 26/36] Remove bkpt_base_breakpoint_ops Tom Tromey
                   ` (11 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This converts static marker tracepoints to use vtable_breakpoint_ops.
---
 gdb/breakpoint.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e1c6efafc25..98829b8f9f0 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -294,6 +294,14 @@ struct ranged_breakpoint : public ordinary_breakpoint
   void print_recreate (struct ui_file *fp) override;
 };
 
+/* Static tracepoints with marker (`-m').  */
+struct static_marker_tracepoint : public tracepoint
+{
+  std::vector<symtab_and_line> decode_location
+       (struct event_location *location,
+	struct program_space *search_pspace) override;
+};
+
 /* The style in which to perform a dynamic printf.  This is a user
    option because different output options have different tradeoffs;
    if GDB does the printing, there is better error handling if there
@@ -1209,11 +1217,14 @@ new_breakpoint_from_type (bptype type)
 
     case bp_fast_tracepoint:
     case bp_static_tracepoint:
-    case bp_static_marker_tracepoint:
     case bp_tracepoint:
       b = new tracepoint ();
       break;
 
+    case bp_static_marker_tracepoint:
+      b = new static_marker_tracepoint ();
+      break;
+
     case bp_dprintf:
       b = new dprintf_breakpoint ();
       break;
@@ -12438,23 +12449,21 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
     }
 }
 
-static std::vector<symtab_and_line>
-strace_marker_decode_location (struct breakpoint *b,
-			       struct event_location *location,
-			       struct program_space *search_pspace)
+std::vector<symtab_and_line>
+static_marker_tracepoint::decode_location (struct event_location *location,
+					   struct program_space *search_pspace)
 {
-  struct tracepoint *tp = (struct tracepoint *) b;
   const char *s = get_linespec_location (location)->spec_string;
 
   std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
-  if (sals.size () > tp->static_trace_marker_id_idx)
+  if (sals.size () > static_trace_marker_id_idx)
     {
-      sals[0] = sals[tp->static_trace_marker_id_idx];
+      sals[0] = sals[static_trace_marker_id_idx];
       sals.resize (1);
       return sals;
     }
   else
-    error (_("marker %s not found"), tp->static_trace_marker_id.c_str ());
+    error (_("marker %s not found"), static_trace_marker_id.c_str ());
 }
 
 static struct breakpoint_ops strace_marker_breakpoint_ops;
@@ -14609,7 +14618,6 @@ initialize_breakpoint_ops (void)
   *ops = vtable_breakpoint_ops;
   ops->create_sals_from_location = strace_marker_create_sals_from_location;
   ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
-  ops->decode_location = strace_marker_decode_location;
 }
 
 /* Chain containing all defined "enable breakpoint" subcommands.  */
-- 
2.31.1


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

* [PATCH 26/36] Remove bkpt_base_breakpoint_ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (24 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 25/36] Convert static marker tracepoints to vtable ops Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 27/36] Merge probe and ordinary breakpoints Tom Tromey
                   ` (10 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

An earlier patch removed the last use of bkpt_base_breakpoint_ops, so
remove the object entirely.
---
 gdb/breakpoint.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 98829b8f9f0..d71ef98b217 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -229,11 +229,6 @@ static bool is_masked_watchpoint (const struct breakpoint *b);
 
 static int strace_marker_p (struct breakpoint *b);
 
-/* The breakpoint_ops structure to be inherited by all breakpoint_ops
-   that are implemented on top of software or hardware breakpoints
-   (user breakpoints, internal and momentary breakpoints, etc.).  */
-static struct breakpoint_ops bkpt_base_breakpoint_ops;
-
 /* Breakpoints set on probes.  */
 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
 
@@ -14593,12 +14588,6 @@ initialize_breakpoint_ops (void)
     return;
   initialized = 1;
 
-  /* The breakpoint_ops structure to be inherit by all kinds of
-     breakpoints (real breakpoints, i.e., user "break" breakpoints,
-     internal and momentary breakpoints, etc.).  */
-  ops = &bkpt_base_breakpoint_ops;
-  *ops = vtable_breakpoint_ops;
-
   /* Probe breakpoints.  */
   ops = &bkpt_probe_breakpoint_ops;
   *ops = vtable_breakpoint_ops;
-- 
2.31.1


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

* [PATCH 27/36] Merge probe and ordinary breakpoints
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (25 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 26/36] Remove bkpt_base_breakpoint_ops Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:39 ` [PATCH 28/36] Merge probe and ordinary tracepoints Tom Tromey
                   ` (9 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Right now, probe breakpoints are handled by a separate ops object.
However, they differ only in a small way from ordinary breakpoints,
and furthermore can be distinguished by their "probe" object.

This patch merges the two cases.  This avoids having to introduce a
new bp_ constant (which can be quite subtle to do correctly) and a new
subclass.
---
 gdb/breakpoint.c | 58 ++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d71ef98b217..d0bdf63f851 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -177,6 +177,11 @@ static void decref_bp_location (struct bp_location **loc);
 
 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
 
+static std::vector<symtab_and_line> bkpt_probe_decode_location
+     (struct breakpoint *b,
+      struct event_location *location,
+      struct program_space *search_pspace);
+
 /* update_global_location_list's modes of operation wrt to whether to
    insert locations now.  */
 enum ugll_insert_mode
@@ -11856,16 +11861,32 @@ base_breakpoint::insert_location (struct bp_location *bl)
   bl->target_info.kind = breakpoint_kind (bl, &addr);
   bl->target_info.placed_address = addr;
 
+  int result;
   if (bl->loc_type == bp_loc_hardware_breakpoint)
-    return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
+    result = target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
   else
-    return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
+    result = target_insert_breakpoint (bl->gdbarch, &bl->target_info);
+
+  if (result == 0 && bl->probe.prob != nullptr)
+    {
+      /* The insertion was successful, now let's set the probe's semaphore
+	 if needed.  */
+      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
+    }
+
+  return result;
 }
 
 int
 base_breakpoint::remove_location (struct bp_location *bl,
 				  enum remove_bp_reason reason)
 {
+  if (bl->probe.prob != nullptr)
+    {
+      /* Let's clear the semaphore before removing the location.  */
+      bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
+    }
+
   if (bl->loc_type == bp_loc_hardware_breakpoint)
     return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
   else
@@ -12013,6 +12034,9 @@ std::vector<symtab_and_line>
 base_breakpoint::decode_location (struct event_location *location,
 				  struct program_space *search_pspace)
 {
+  if (event_location_type (location) == PROBE_LOCATION)
+    return bkpt_probe_decode_location (this, location, search_pspace);
+
   return decode_location_default (this, location, search_pspace);
 }
 
@@ -12151,33 +12175,6 @@ longjmp_breakpoint::~longjmp_breakpoint ()
     tp->initiating_frame = null_frame_id;
 }
 
-/* Specific methods for probe breakpoints.  */
-
-static int
-bkpt_probe_insert_location (struct bp_location *bl)
-{
-  int v = bl->owner->insert_location (bl);
-
-  if (v == 0)
-    {
-      /* The insertion was successful, now let's set the probe's semaphore
-	 if needed.  */
-      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
-    }
-
-  return v;
-}
-
-static int
-bkpt_probe_remove_location (struct bp_location *bl,
-			    enum remove_bp_reason reason)
-{
-  /* Let's clear the semaphore before removing the location.  */
-  bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
-
-  return bl->owner->remove_location (bl, reason);
-}
-
 static void
 bkpt_probe_create_sals_from_location (struct event_location *location,
 				      struct linespec_result *canonical,
@@ -14591,10 +14588,7 @@ initialize_breakpoint_ops (void)
   /* Probe breakpoints.  */
   ops = &bkpt_probe_breakpoint_ops;
   *ops = vtable_breakpoint_ops;
-  ops->insert_location = bkpt_probe_insert_location;
-  ops->remove_location = bkpt_probe_remove_location;
   ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
-  ops->decode_location = bkpt_probe_decode_location;
 
   /* Probe tracepoints.  */
   ops = &tracepoint_probe_breakpoint_ops;
-- 
2.31.1


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

* [PATCH 28/36] Merge probe and ordinary tracepoints
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (26 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 27/36] Merge probe and ordinary breakpoints Tom Tromey
@ 2022-01-18 19:39 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 29/36] Remove breakpoint_ops from init_ada_exception_breakpoint Tom Tromey
                   ` (8 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Right now, probe tracepoints are handled by a separate ops object.
However, they differ only in a small way from ordinary tracepoints,
and furthermore can be distinguished by their event location.

This patch merges the two cases, just as was done for breakpoints.
---
 gdb/breakpoint.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d0bdf63f851..117599e2ecc 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -12286,6 +12286,9 @@ std::vector<symtab_and_line>
 tracepoint::decode_location (struct event_location *location,
 			     struct program_space *search_pspace)
 {
+  if (event_location_type (location) == PROBE_LOCATION)
+    return bkpt_probe_decode_location (this, location, search_pspace);
+
   return decode_location_default (this, location, search_pspace);
 }
 
@@ -12301,15 +12304,6 @@ tracepoint_probe_create_sals_from_location
   bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
 }
 
-static std::vector<symtab_and_line>
-tracepoint_probe_decode_location (struct breakpoint *b,
-				  struct event_location *location,
-				  struct program_space *search_pspace)
-{
-  /* We use the same method for breakpoint on probes.  */
-  return bkpt_probe_decode_location (b, location, search_pspace);
-}
-
 void
 dprintf_breakpoint::re_set ()
 {
@@ -14594,7 +14588,6 @@ initialize_breakpoint_ops (void)
   ops = &tracepoint_probe_breakpoint_ops;
   *ops = vtable_breakpoint_ops;
   ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
-  ops->decode_location = tracepoint_probe_decode_location;
 
   /* Static tracepoints with marker (`-m').  */
   ops = &strace_marker_breakpoint_ops;
-- 
2.31.1


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

* [PATCH 29/36] Remove breakpoint_ops from init_ada_exception_breakpoint
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (27 preceding siblings ...)
  2022-01-18 19:39 ` [PATCH 28/36] Merge probe and ordinary tracepoints Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 30/36] Remove breakpoint_ops from init_catchpoint Tom Tromey
                   ` (7 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

init_ada_exception_breakpoint is only ever passed a single
breakpoint_ops structure, so remove the parameter.
---
 gdb/ada-lang.c   | 1 -
 gdb/breakpoint.c | 4 ++--
 gdb/breakpoint.h | 1 -
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 40e369a4626..5b98d824bb4 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12283,7 +12283,6 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
 
   std::unique_ptr<ada_catchpoint> c (new ada_catchpoint (ex_kind));
   init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string.c_str (),
-				 &vtable_breakpoint_ops,
 				 tempflag, disabled, from_tty);
   c->excep_string = excep_string;
   create_excep_cond_exprs (c.get (), ex_kind);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 117599e2ecc..4885c72d8c0 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -10643,7 +10643,6 @@ init_ada_exception_breakpoint (struct breakpoint *b,
 			       struct gdbarch *gdbarch,
 			       struct symtab_and_line sal,
 			       const char *addr_string,
-			       const struct breakpoint_ops *ops,
 			       int tempflag,
 			       int enabled,
 			       int from_tty)
@@ -10666,7 +10665,8 @@ init_ada_exception_breakpoint (struct breakpoint *b,
 	 enough for now, though.  */
     }
 
-  init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
+  init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint,
+		       &vtable_breakpoint_ops);
 
   b->enable_state = enabled ? bp_enabled : bp_disabled;
   b->disposition = tempflag ? disp_del : disp_donttouch;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index e362cd454ec..a17d0080603 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1500,7 +1500,6 @@ extern void
 				 struct gdbarch *gdbarch,
 				 struct symtab_and_line sal,
 				 const char *addr_string,
-				 const struct breakpoint_ops *ops,
 				 int tempflag,
 				 int enabled,
 				 int from_tty);
-- 
2.31.1


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

* [PATCH 30/36] Remove breakpoint_ops from init_catchpoint
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (28 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 29/36] Remove breakpoint_ops from init_ada_exception_breakpoint Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 31/36] Remove most fields from breakpoint_ops Tom Tromey
                   ` (6 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

init_catchpoint is only ever passed a single breakpoint_ops pointer,
so remove the parameter.
---
 gdb/break-catch-exec.c    | 3 +--
 gdb/break-catch-fork.c    | 3 +--
 gdb/break-catch-load.c    | 2 +-
 gdb/break-catch-sig.c     | 2 +-
 gdb/break-catch-syscall.c | 3 +--
 gdb/break-catch-throw.c   | 3 +--
 gdb/breakpoint.c          | 6 +++---
 gdb/breakpoint.h          | 6 ++----
 8 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/gdb/break-catch-exec.c b/gdb/break-catch-exec.c
index 3cabe72a35f..47765a6c01f 100644
--- a/gdb/break-catch-exec.c
+++ b/gdb/break-catch-exec.c
@@ -204,8 +204,7 @@ catch_exec_command_1 (const char *arg, int from_tty,
     error (_("Junk at end of arguments."));
 
   std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ());
-  init_catchpoint (c.get (), gdbarch, temp, cond_string,
-		   &vtable_breakpoint_ops);
+  init_catchpoint (c.get (), gdbarch, temp, cond_string);
   c->exec_pathname.reset ();
 
   install_breakpoint (0, std::move (c), 1);
diff --git a/gdb/break-catch-fork.c b/gdb/break-catch-fork.c
index 9b3721a605e..bff61c165ba 100644
--- a/gdb/break-catch-fork.c
+++ b/gdb/break-catch-fork.c
@@ -182,8 +182,7 @@ create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
 {
   std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ());
 
-  init_catchpoint (c.get (), gdbarch, temp, cond_string,
-		   &vtable_breakpoint_ops);
+  init_catchpoint (c.get (), gdbarch, temp, cond_string);
   c->is_vfork = is_vfork;
   c->forked_inferior_pid = null_ptid;
 
diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
index 63edf8959ff..0e76ad288e8 100644
--- a/gdb/break-catch-load.c
+++ b/gdb/break-catch-load.c
@@ -279,7 +279,7 @@ add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled)
     }
 
   c->is_load = is_load;
-  init_catchpoint (c.get (), gdbarch, is_temp, NULL, &vtable_breakpoint_ops);
+  init_catchpoint (c.get (), gdbarch, is_temp, NULL);
 
   c->enable_state = enabled ? bp_enabled : bp_disabled;
 
diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
index 940f8cc4aa6..2723f36b55c 100644
--- a/gdb/break-catch-sig.c
+++ b/gdb/break-catch-sig.c
@@ -317,7 +317,7 @@ create_signal_catchpoint (int tempflag, std::vector<gdb_signal> &&filter,
   struct gdbarch *gdbarch = get_current_arch ();
 
   std::unique_ptr<signal_catchpoint> c (new signal_catchpoint ());
-  init_catchpoint (c.get (), gdbarch, tempflag, NULL, &vtable_breakpoint_ops);
+  init_catchpoint (c.get (), gdbarch, tempflag, nullptr);
   c->signals_to_be_caught = std::move (filter);
   c->catch_all = catch_all;
 
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 1af4f6d074b..36bfe125d03 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -349,8 +349,7 @@ create_syscall_event_catchpoint (int tempflag, std::vector<int> &&filter)
   struct gdbarch *gdbarch = get_current_arch ();
 
   std::unique_ptr<syscall_catchpoint> c (new syscall_catchpoint ());
-  init_catchpoint (c.get (), gdbarch, tempflag, nullptr,
-		   &vtable_breakpoint_ops);
+  init_catchpoint (c.get (), gdbarch, tempflag, nullptr);
   c->syscalls_to_be_caught = std::move (filter);
 
   install_breakpoint (0, std::move (c), 1);
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index f41a8090e0c..14c1d19d2a3 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -365,8 +365,7 @@ handle_gnu_v3_exceptions (int tempflag, std::string &&except_rx,
 
   std::unique_ptr<exception_catchpoint> cp (new exception_catchpoint ());
 
-  init_catchpoint (cp.get (), get_current_arch (), tempflag, cond_string,
-		   &vtable_breakpoint_ops);
+  init_catchpoint (cp.get (), get_current_arch (), tempflag, cond_string);
   cp->kind = ex_event;
   cp->exception_rx = std::move (except_rx);
   cp->pattern = std::move (pattern);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4885c72d8c0..e0008e1b4ca 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7774,13 +7774,13 @@ disable_breakpoints_in_freed_objfile (struct objfile *objfile)
 void
 init_catchpoint (struct breakpoint *b,
 		 struct gdbarch *gdbarch, bool temp,
-		 const char *cond_string,
-		 const struct breakpoint_ops *ops)
+		 const char *cond_string)
 {
   symtab_and_line sal;
   sal.pspace = current_program_space;
 
-  init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
+  init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint,
+		       &vtable_breakpoint_ops);
 
   if (cond_string == nullptr)
     b->cond_string.reset ();
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index a17d0080603..7caa3d9392d 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1506,13 +1506,11 @@ extern void
 
 /* Initialize a new breakpoint of the bp_catchpoint kind.  If TEMP
    is true, then make the breakpoint temporary.  If COND_STRING is
-   not NULL, then store it in the breakpoint.  OPS, if not NULL, is
-   the breakpoint_ops structure associated to the catchpoint.  */
+   not NULL, then store it in the breakpoint.  */
 
 extern void init_catchpoint (struct breakpoint *b,
 			     struct gdbarch *gdbarch, bool temp,
-			     const char *cond_string,
-			     const struct breakpoint_ops *ops);
+			     const char *cond_string);
 
 /* Add breakpoint B on the breakpoint list, and notify the user, the
    target and breakpoint_created observers of its existence.  If
-- 
2.31.1


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

* [PATCH 31/36] Remove most fields from breakpoint_ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (29 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 30/36] Remove breakpoint_ops from init_catchpoint Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 32/36] Remove vtable_breakpoint_ops Tom Tromey
                   ` (5 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

At this point, all implementations of breakpoints use the vtable.  So,
we can now remove most function pointers from breakpoint_ops and
switch to using methods directly in the callers.  Only the two "static
virtual" methods remain in breakpoint_ops.
---
 gdb/break-catch-load.c |   2 +-
 gdb/breakpoint.c       | 239 +++++------------------------------------
 gdb/breakpoint.h       |  93 ----------------
 3 files changed, 30 insertions(+), 304 deletions(-)

diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
index 0e76ad288e8..a7735b8d4f0 100644
--- a/gdb/break-catch-load.c
+++ b/gdb/break-catch-load.c
@@ -144,7 +144,7 @@ solib_catchpoint::breakpoint_hit (const struct bp_location *bl,
 
       for (bp_location *other_bl : other->locations ())
 	{
-	  if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
+	  if (other->breakpoint_hit (other_bl, aspace, bp_addr, ws))
 	    return 1;
 	}
     }
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e0008e1b4ca..c97a55f488a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1970,7 +1970,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
 	 the target gains execution, through breakpoint_re_set.  */
       if (!can_use_hw_watchpoints)
 	{
-	  if (b->ops->works_in_software_mode (b))
+	  if (b->works_in_software_mode ())
 	    b->type = bp_watchpoint;
 	  else
 	    error (_("Can't set read/access watchpoint when "
@@ -2129,7 +2129,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
 		= target_can_use_hardware_watchpoint (type, i, other_type_used);
 	      if (target_resources_ok <= 0)
 		{
-		  int sw_mode = b->ops->works_in_software_mode (b);
+		  int sw_mode = b->works_in_software_mode ();
 
 		  if (target_resources_ok == 0 && !sw_mode)
 		    error (_("Target does not support this type of "
@@ -2150,7 +2150,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
 		  b->type = type;
 		}
 	    }
-	  else if (!b->ops->works_in_software_mode (b))
+	  else if (!b->works_in_software_mode ())
 	    {
 	      if (!can_use_hw_watchpoints)
 		error (_("Can't set read/access watchpoint when "
@@ -2694,7 +2694,7 @@ insert_bp_location (struct bp_location *bl,
 	    {
 	      int val;
 
-	      val = bl->owner->ops->insert_location (bl);
+	      val = bl->owner->insert_location (bl);
 	      if (val)
 		bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 	    }
@@ -2757,7 +2757,7 @@ insert_bp_location (struct bp_location *bl,
 		{
 		  int val;
 
-		  val = bl->owner->ops->insert_location (bl);
+		  val = bl->owner->insert_location (bl);
 		  if (val)
 		    bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 		}
@@ -2871,10 +2871,7 @@ insert_bp_location (struct bp_location *bl,
     {
       int val;
 
-      gdb_assert (bl->owner->ops != NULL
-		  && bl->owner->ops->insert_location != NULL);
-
-      val = bl->owner->ops->insert_location (bl);
+      val = bl->owner->insert_location (bl);
 
       /* If trying to set a read-watchpoint, and it turns out it's not
 	 supported, try emulating one with an access watchpoint.  */
@@ -2899,7 +2896,7 @@ insert_bp_location (struct bp_location *bl,
 	  if (val == 1)
 	    {
 	      bl->watchpoint_type = hw_access;
-	      val = bl->owner->ops->insert_location (bl);
+	      val = bl->owner->insert_location (bl);
 
 	      if (val)
 		/* Back to the original value.  */
@@ -2914,10 +2911,7 @@ insert_bp_location (struct bp_location *bl,
     {
       int val;
 
-      gdb_assert (bl->owner->ops != NULL
-		  && bl->owner->ops->insert_location != NULL);
-
-      val = bl->owner->ops->insert_location (bl);
+      val = bl->owner->insert_location (bl);
       if (val)
 	{
 	  bl->owner->enable_state = bp_disabled;
@@ -3891,7 +3885,7 @@ remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
 	      && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
 	    val = 0;
 	  else
-	    val = bl->owner->ops->remove_location (bl, reason);
+	    val = bl->owner->remove_location (bl, reason);
 	}
       else
 	{
@@ -3926,7 +3920,7 @@ remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
 		 wrong code with the saved shadow contents.  */
 	      if (bl->loc_type == bp_loc_hardware_breakpoint
 		  || section_is_mapped (bl->section))
-		val = bl->owner->ops->remove_location (bl, reason);
+		val = bl->owner->remove_location (bl, reason);
 	      else
 		val = 0;
 	    }
@@ -3960,11 +3954,8 @@ remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
     }
   else if (bl->loc_type == bp_loc_hardware_watchpoint)
     {
-      gdb_assert (bl->owner->ops != NULL
-		  && bl->owner->ops->remove_location != NULL);
-
       bl->inserted = (reason == DETACH_BREAKPOINT);
-      bl->owner->ops->remove_location (bl, reason);
+      bl->owner->remove_location (bl, reason);
 
       /* Failure to remove any of the hardware watchpoints comes here.  */
       if (reason == REMOVE_BREAKPOINT && bl->inserted)
@@ -3975,10 +3966,7 @@ remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
 	   && breakpoint_enabled (bl->owner)
 	   && !bl->duplicate)
     {
-      gdb_assert (bl->owner->ops != NULL
-		  && bl->owner->ops->remove_location != NULL);
-
-      val = bl->owner->ops->remove_location (bl, reason);
+      val = bl->owner->remove_location (bl, reason);
       if (val)
 	return val;
 
@@ -4418,8 +4406,7 @@ bpstat_explains_signal (bpstat *bsp, enum gdb_signal sig)
 	}
       else
 	{
-	  if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
-							sig))
+	  if (bsp->breakpoint_at->explains_signal (sig))
 	    return true;
 	}
     }
@@ -4707,7 +4694,7 @@ print_bp_stop_message (bpstat *bs)
 	  return PRINT_UNKNOWN;
 
 	/* Normal case.  Call the breakpoint's print_it method.  */
-	return b->ops->print_it (bs);
+	return b->print_it (bs);
       }
       break;
 
@@ -5022,8 +5009,8 @@ watchpoint_check (bpstat *bs)
 	 watch after that (since the garbage may or may not equal
 	 the first value assigned).  */
       /* We print all the stop information in
-	 breakpoint_ops->print_it, but in this case, by the time we
-	 call breakpoint_ops->print_it this bp will be deleted
+	 breakpointprint_it, but in this case, by the time we
+	 call breakpoint->print_it this bp will be deleted
 	 already.  So we have no choice but print the information
 	 here.  */
 
@@ -5062,7 +5049,7 @@ bpstat_check_location (const struct bp_location *bl,
   /* BL is from an existing breakpoint.  */
   gdb_assert (b != NULL);
 
-  return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
+  return b->breakpoint_hit (bl, aspace, bp_addr, ws);
 }
 
 /* Determine if the watched values have actually changed, and we
@@ -5510,7 +5497,7 @@ bpstat_stop_status (const address_space *aspace,
 	continue;
 
       b = bs->breakpoint_at;
-      b->ops->check_status (bs);
+      b->check_status (bs);
       if (bs->stop)
 	{
 	  bpstat_check_breakpoint_conditions (bs, thread);
@@ -5535,7 +5522,7 @@ bpstat_stop_status (const address_space *aspace,
 					  ? bs->commands.get () : NULL))
 		bs->print = 0;
 
-	      b->ops->after_condition_true (bs);
+	      b->after_condition_true (bs);
 	    }
 
 	}
@@ -6162,7 +6149,7 @@ print_one_breakpoint_location (struct breakpoint *b,
 
   /* 5 and 6 */
   bool result = false;
-  if (!raw_loc && b->ops != NULL && b->ops->print_one (b, last_loc))
+  if (!raw_loc && b->print_one (last_loc))
     result = true;
   else
     {
@@ -6245,7 +6232,7 @@ print_one_breakpoint_location (struct breakpoint *b,
   uiout->text ("\n");
 
   if (!part_of_multiple)
-    b->ops->print_one_detail (b, uiout);
+    b->print_one_detail (uiout);
 
   if (part_of_multiple && frame_id_p (b->frame_id))
     {
@@ -7132,7 +7119,7 @@ bp_location::bp_location (breakpoint *owner)
 static struct bp_location *
 allocate_bp_location (struct breakpoint *bpt)
 {
-  return bpt->ops->allocate_location (bpt);
+  return bpt->allocate_location ();
 }
 
 /* Decrement reference count.  If the reference count reaches 0,
@@ -7815,7 +7802,7 @@ hw_breakpoint_used_count (void)
 	{
 	  /* Special types of hardware breakpoints may use more than
 	     one register.  */
-	  i += b->ops->resources_needed (bl);
+	  i += b->resources_needed (bl);
 	}
 
   return i;
@@ -7836,7 +7823,7 @@ hw_watchpoint_use_count (struct breakpoint *b)
     {
       /* Special types of hardware watchpoints may use more than
 	 one register.  */
-      i += b->ops->resources_needed (bl);
+      i += b->resources_needed (bl);
     }
 
   return i;
@@ -8023,7 +8010,7 @@ set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
 static void
 mention (struct breakpoint *b)
 {
-  b->ops->print_mention (b);
+  b->print_mention ();
   current_uiout->text ("\n");
 }
 \f
@@ -11483,7 +11470,7 @@ bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
   return 0;
 }
 
-/* Helper for breakpoint and tracepoint breakpoint_ops->mention
+/* Helper for breakpoint and tracepoint breakpoint->mention
    callbacks.  */
 
 static void
@@ -11564,46 +11551,21 @@ bp_location_range breakpoint::locations ()
   return bp_location_range (this->loc);
 }
 
-static struct bp_location *
-base_breakpoint_allocate_location (struct breakpoint *self)
-{
-  return new bp_location (self);
-}
-
 struct bp_location *
 breakpoint::allocate_location ()
 {
   return new bp_location (this);
 }
 
-static void
-base_breakpoint_re_set (struct breakpoint *b)
-{
-  /* Nothing to re-set. */
-}
-
 #define internal_error_pure_virtual_called() \
   gdb_assert_not_reached ("pure virtual function called")
 
-static int
-base_breakpoint_insert_location (struct bp_location *bl)
-{
-  internal_error_pure_virtual_called ();
-}
-
 int
 breakpoint::insert_location (struct bp_location *bl)
 {
   internal_error_pure_virtual_called ();
 }
 
-static int
-base_breakpoint_remove_location (struct bp_location *bl,
-				 enum remove_bp_reason reason)
-{
-  internal_error_pure_virtual_called ();
-}
-
 int
 breakpoint::remove_location (struct bp_location *bl,
 			     enum remove_bp_reason reason)
@@ -11611,15 +11573,6 @@ breakpoint::remove_location (struct bp_location *bl,
   internal_error_pure_virtual_called ();
 }
 
-static int
-base_breakpoint_breakpoint_hit (const struct bp_location *bl,
-				const address_space *aspace,
-				CORE_ADDR bp_addr,
-				const target_waitstatus &ws)
-{
-  internal_error_pure_virtual_called ();
-}
-
 int
 breakpoint::breakpoint_hit (const struct bp_location *bl,
 			    const address_space *aspace,
@@ -11629,85 +11582,30 @@ breakpoint::breakpoint_hit (const struct bp_location *bl,
   internal_error_pure_virtual_called ();
 }
 
-static void
-base_breakpoint_check_status (bpstat *bs)
-{
-  /* Always stop.   */
-}
-
-/* A "works_in_software_mode" breakpoint_ops method that just internal
-   errors.  */
-
-static int
-base_breakpoint_works_in_software_mode (const struct breakpoint *b)
-{
-  internal_error_pure_virtual_called ();
-}
-
 int
 breakpoint::works_in_software_mode () const
 {
   internal_error_pure_virtual_called ();
 }
 
-/* A "resources_needed" breakpoint_ops method that just internal
-   errors.  */
-
-static int
-base_breakpoint_resources_needed (const struct bp_location *bl)
-{
-  internal_error_pure_virtual_called ();
-}
-
 int
 breakpoint::resources_needed (const struct bp_location *bl)
 {
   internal_error_pure_virtual_called ();
 }
 
-static enum print_stop_action
-base_breakpoint_print_it (bpstat *bs)
-{
-  internal_error_pure_virtual_called ();
-}
-
 enum print_stop_action
 breakpoint::print_it (bpstat *bs)
 {
   internal_error_pure_virtual_called ();
 }
 
-static bool
-base_breakpoint_print_one (struct breakpoint *, struct bp_location **)
-{
-  return false;
-}
-
-static void
-base_breakpoint_print_one_detail (const struct breakpoint *self,
-				  struct ui_out *uiout)
-{
-  /* nothing */
-}
-
-static void
-base_breakpoint_print_mention (struct breakpoint *b)
-{
-  internal_error_pure_virtual_called ();
-}
-
 void
 breakpoint::print_mention ()
 {
   internal_error_pure_virtual_called ();
 }
 
-static void
-base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
-{
-  internal_error_pure_virtual_called ();
-}
-
 void
 breakpoint::print_recreate (struct ui_file *fp)
 {
@@ -11739,14 +11637,6 @@ base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
   internal_error_pure_virtual_called ();
 }
 
-static std::vector<symtab_and_line>
-base_breakpoint_decode_location (struct breakpoint *b,
-				 struct event_location *location,
-				 struct program_space *search_pspace)
-{
-  internal_error_pure_virtual_called ();
-}
-
 std::vector<symtab_and_line>
 breakpoint::decode_location (struct event_location *location,
 			     struct program_space *search_pspace)
@@ -11754,87 +11644,16 @@ breakpoint::decode_location (struct event_location *location,
   internal_error_pure_virtual_called ();
 }
 
-/* The default 'explains_signal' method.  */
-
-static int
-base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
-{
-  return 1;
-}
-
-/* The default "after_condition_true" method.  */
-
-static void
-base_breakpoint_after_condition_true (struct bpstat *bs)
-{
-  /* Nothing to do.   */
-}
-
 struct breakpoint_ops base_breakpoint_ops =
 {
-  base_breakpoint_allocate_location,
-  base_breakpoint_re_set,
-  base_breakpoint_insert_location,
-  base_breakpoint_remove_location,
-  base_breakpoint_breakpoint_hit,
-  base_breakpoint_check_status,
-  base_breakpoint_resources_needed,
-  base_breakpoint_works_in_software_mode,
-  base_breakpoint_print_it,
-  base_breakpoint_print_one,
-  base_breakpoint_print_one_detail,
-  base_breakpoint_print_mention,
-  base_breakpoint_print_recreate,
   base_breakpoint_create_sals_from_location,
   base_breakpoint_create_breakpoints_sal,
-  base_breakpoint_decode_location,
-  base_breakpoint_explains_signal,
-  base_breakpoint_after_condition_true,
 };
 
 struct breakpoint_ops vtable_breakpoint_ops =
 {
-  [] (struct breakpoint *b) { return b->allocate_location (); },
-  [] (struct breakpoint *b) { b->re_set (); },
-  [] (struct bp_location *l)
-  {
-    return l->owner->insert_location (l);
-  },
-  [] (struct bp_location *l, enum remove_bp_reason reason)
-  {
-    return l->owner->remove_location (l, reason);
-  },
-  [] (const struct bp_location *bl,
-      const address_space *aspace,
-      CORE_ADDR bp_addr,
-      const target_waitstatus &ws)
-  {
-    return bl->owner->breakpoint_hit (bl, aspace, bp_addr, ws);
-  },
-  [] (struct bpstat *bs) { bs->breakpoint_at->check_status (bs); },
-  [] (const struct bp_location *bl)
-  { return bl->owner->resources_needed (bl); },
-  [] (const struct breakpoint *b)
-  { return b->works_in_software_mode (); },
-  [] (struct bpstat *bs)
-  { return bs->breakpoint_at->print_it (bs); },
-  [] (struct breakpoint *b, struct bp_location **bl)
-  { return b->print_one (bl); },
-  [] (const struct breakpoint *b, struct ui_out *out)
-  { b->print_one_detail (out); },
-  [] (struct breakpoint *b) { b->print_mention (); },
-  [] (struct breakpoint *b, struct ui_file *fp)
-  { b->print_recreate (fp); },
   create_sals_from_location_default,
   create_breakpoints_sal_default,
-  [] (struct breakpoint *b,
-      struct event_location *location,
-      struct program_space *search_pspace)
-  { return b->decode_location (location, search_pspace); },
-  [] (struct breakpoint *b, enum gdb_signal s)
-  { return b->explains_signal (s); },
-  [] (struct bpstat *bs)
-  { bs->breakpoint_at->after_condition_true (bs); }
 };
 
 /* Default breakpoint_ops methods.  */
@@ -13002,7 +12821,7 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
 
   try
     {
-      sals = b->ops->decode_location (b, location, search_pspace);
+      sals = b->decode_location (location, search_pspace);
     }
   catch (gdb_exception_error &e)
     {
@@ -13170,7 +12989,7 @@ breakpoint_re_set_one (breakpoint *b)
   input_radix = b->input_radix;
   set_language (b->language);
 
-  b->ops->re_set (b);
+  b->re_set ();
 }
 
 /* Re-set breakpoint locations for the current program space.
@@ -14362,7 +14181,7 @@ save_breakpoints (const char *filename, int from_tty,
       if (filter && !filter (tp))
 	continue;
 
-      tp->ops->print_recreate (tp, &fp);
+      tp->print_recreate (&fp);
 
       /* Note, we can't rely on tp->number for anything, as we can't
 	 assume the recreated breakpoint numbers will match.  Use $bpnum
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 7caa3d9392d..86f7a9d9665 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -561,80 +561,6 @@ enum print_stop_action
 
 struct breakpoint_ops
 {
-  /* Allocate a location for this breakpoint.  */
-  struct bp_location * (*allocate_location) (struct breakpoint *);
-
-  /* Reevaluate a breakpoint.  This is necessary after symbols change
-     (e.g., an executable or DSO was loaded, or the inferior just
-     started).  */
-  void (*re_set) (struct breakpoint *self);
-
-  /* Insert the breakpoint or watchpoint or activate the catchpoint.
-     Return 0 for success, 1 if the breakpoint, watchpoint or
-     catchpoint type is not supported, -1 for failure.  */
-  int (*insert_location) (struct bp_location *);
-
-  /* Remove the breakpoint/catchpoint that was previously inserted
-     with the "insert" method above.  Return 0 for success, 1 if the
-     breakpoint, watchpoint or catchpoint type is not supported,
-     -1 for failure.  */
-  int (*remove_location) (struct bp_location *, enum remove_bp_reason reason);
-
-  /* Return true if it the target has stopped due to hitting
-     breakpoint location BL.  This function does not check if we
-     should stop, only if BL explains the stop.  ASPACE is the address
-     space in which the event occurred, BP_ADDR is the address at
-     which the inferior stopped, and WS is the target_waitstatus
-     describing the event.  */
-  int (*breakpoint_hit) (const struct bp_location *bl,
-			 const address_space *aspace,
-			 CORE_ADDR bp_addr,
-			 const target_waitstatus &ws);
-
-  /* Check internal conditions of the breakpoint referred to by BS.
-     If we should not stop for this breakpoint, set BS->stop to 0.  */
-  void (*check_status) (struct bpstat *bs);
-
-  /* Tell how many hardware resources (debug registers) are needed
-     for this breakpoint.  If this function is not provided, then
-     the breakpoint or watchpoint needs one debug register.  */
-  int (*resources_needed) (const struct bp_location *);
-
-  /* Tell whether we can downgrade from a hardware watchpoint to a software
-     one.  If not, the user will not be able to enable the watchpoint when
-     there are not enough hardware resources available.  */
-  int (*works_in_software_mode) (const struct breakpoint *);
-
-  /* The normal print routine for this breakpoint, called when we
-     hit it.  */
-  enum print_stop_action (*print_it) (struct bpstat *bs);
-
-  /* Display information about this breakpoint, for "info
-     breakpoints".  Returns false if this method should use the
-     default behavior.  */
-  bool (*print_one) (struct breakpoint *, struct bp_location **);
-
-  /* Display extra information about this breakpoint, below the normal
-     breakpoint description in "info breakpoints".
-
-     In the example below, the "address range" line was printed
-     by print_one_detail_ranged_breakpoint.
-
-     (gdb) info breakpoints
-     Num     Type           Disp Enb Address    What
-     2       hw breakpoint  keep y              in main at test-watch.c:70
-	     address range: [0x10000458, 0x100004c7]
-
-   */
-  void (*print_one_detail) (const struct breakpoint *, struct ui_out *);
-
-  /* Display information about this breakpoint after setting it
-     (roughly speaking; this is called from "mention").  */
-  void (*print_mention) (struct breakpoint *);
-
-  /* Print to FP the CLI command that recreates this breakpoint.  */
-  void (*print_recreate) (struct breakpoint *, struct ui_file *fp);
-
   /* Create SALs from location, storing the result in linespec_result.
 
      For an explanation about the arguments, see the function
@@ -659,25 +585,6 @@ struct breakpoint_ops
 				  enum bptype, enum bpdisp, int, int,
 				  int, const struct breakpoint_ops *,
 				  int, int, int, unsigned);
-
-  /* Given the location (second parameter), this method decodes it and
-     returns the SAL locations related to it.  For ordinary
-     breakpoints, it calls `decode_line_full'.  If SEARCH_PSPACE is
-     not NULL, symbol search is restricted to just that program space.
-
-     This function is called inside `location_to_sals'.  */
-  std::vector<symtab_and_line> (*decode_location)
-    (struct breakpoint *b,
-     struct event_location *location,
-     struct program_space *search_pspace);
-
-  /* Return true if this breakpoint explains a signal.  See
-     bpstat_explains_signal.  */
-  int (*explains_signal) (struct breakpoint *, enum gdb_signal);
-
-  /* Called after evaluating the breakpoint's condition,
-     and only if it evaluated true.  */
-  void (*after_condition_true) (struct bpstat *bs);
 };
 
 /* Helper for breakpoint_ops->print_recreate implementations.  Prints
-- 
2.31.1


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

* [PATCH 32/36] Remove vtable_breakpoint_ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (30 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 31/36] Remove most fields from breakpoint_ops Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 33/36] Remove breakpoint ops initialization Tom Tromey
                   ` (4 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

There's no need to have vtable_breakpoint_ops any more, so remove it
in favor of base_breakpoint_ops.
---
 gdb/breakpoint.c                 | 91 +++++++++++---------------------
 gdb/breakpoint.h                 |  4 +-
 gdb/mi/mi-cmd-break.c            |  4 +-
 gdb/python/py-finishbreakpoint.c |  2 +-
 4 files changed, 34 insertions(+), 67 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index c97a55f488a..89893d48b20 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3346,7 +3346,7 @@ create_overlay_event_breakpoint (void)
       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
       b = create_internal_breakpoint (objfile->arch (), addr,
 				      bp_overlay_event,
-				      &vtable_breakpoint_ops);
+				      &base_breakpoint_ops);
       initialize_explicit_location (&explicit_loc);
       explicit_loc.function_name = ASTRDUP (func_name);
       b->location = new_explicit_location (&explicit_loc);
@@ -3406,7 +3406,7 @@ create_longjmp_master_breakpoint_probe (objfile *objfile)
       b = create_internal_breakpoint (gdbarch,
 				      p->get_relocated_address (objfile),
 				      bp_longjmp_master,
-				      &vtable_breakpoint_ops);
+				      &base_breakpoint_ops);
       b->location = new_probe_location ("-probe-stap libc:longjmp");
       b->enable_state = bp_disabled;
     }
@@ -3455,7 +3455,7 @@ create_longjmp_master_breakpoint_names (objfile *objfile)
 
       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
       b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
-				      &vtable_breakpoint_ops);
+				      &base_breakpoint_ops);
       initialize_explicit_location (&explicit_loc);
       explicit_loc.function_name = ASTRDUP (func_name);
       b->location = new_explicit_location (&explicit_loc);
@@ -3539,7 +3539,7 @@ create_std_terminate_master_breakpoint (void)
 	  addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
 	  b = create_internal_breakpoint (objfile->arch (), addr,
 					  bp_std_terminate_master,
-					  &vtable_breakpoint_ops);
+					  &base_breakpoint_ops);
 	  initialize_explicit_location (&explicit_loc);
 	  explicit_loc.function_name = ASTRDUP (func_name);
 	  b->location = new_explicit_location (&explicit_loc);
@@ -3592,7 +3592,7 @@ create_exception_master_breakpoint_probe (objfile *objfile)
       b = create_internal_breakpoint (gdbarch,
 				      p->get_relocated_address (objfile),
 				      bp_exception_master,
-				      &vtable_breakpoint_ops);
+				      &base_breakpoint_ops);
       b->location = new_probe_location ("-probe-stap libgcc:unwind");
       b->enable_state = bp_disabled;
     }
@@ -3638,7 +3638,7 @@ create_exception_master_breakpoint_hook (objfile *objfile)
   addr = gdbarch_convert_from_func_ptr_addr
     (gdbarch, addr, current_inferior ()->top_target ());
   b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
-				  &vtable_breakpoint_ops);
+				  &base_breakpoint_ops);
   initialize_explicit_location (&explicit_loc);
   explicit_loc.function_name = ASTRDUP (func_name);
   b->location = new_explicit_location (&explicit_loc);
@@ -7317,7 +7317,7 @@ set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
 	/* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
 	   after their removal.  */
 	clone = momentary_breakpoint_from_master (b, type,
-						  &vtable_breakpoint_ops, 1);
+						  &base_breakpoint_ops, 1);
 	clone->thread = thread;
       }
 
@@ -7363,7 +7363,7 @@ set_longjmp_breakpoint_for_call_dummy (void)
 	struct breakpoint *new_b;
 
 	new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
-						  &vtable_breakpoint_ops,
+						  &base_breakpoint_ops,
 						  1);
 	new_b->thread = inferior_thread ()->global_num;
 
@@ -7495,7 +7495,7 @@ set_std_terminate_breakpoint (void)
 	&& b->type == bp_std_terminate_master)
       {
 	momentary_breakpoint_from_master (b, bp_std_terminate,
-					  &vtable_breakpoint_ops, 1);
+					  &base_breakpoint_ops, 1);
       }
 }
 
@@ -7514,7 +7514,7 @@ create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
   struct breakpoint *b;
 
   b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
-				  &vtable_breakpoint_ops);
+				  &base_breakpoint_ops);
 
   b->enable_state = bp_enabled;
   /* location has to be used or breakpoint_re_set will delete me.  */
@@ -7537,7 +7537,7 @@ struct breakpoint *
 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
 {
   return create_internal_breakpoint (gdbarch, address, bp_jit_event,
-				     &vtable_breakpoint_ops);
+				     &base_breakpoint_ops);
 }
 
 /* Remove JIT code registration and unregistration breakpoint(s).  */
@@ -7582,7 +7582,7 @@ create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
   struct breakpoint *b;
 
   b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
-				  &vtable_breakpoint_ops);
+				  &base_breakpoint_ops);
   update_global_location_list_nothrow (insert_mode);
   return b;
 }
@@ -7767,7 +7767,7 @@ init_catchpoint (struct breakpoint *b,
   sal.pspace = current_program_space;
 
   init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint,
-		       &vtable_breakpoint_ops);
+		       &base_breakpoint_ops);
 
   if (cond_string == nullptr)
     b->cond_string.reset ();
@@ -7902,7 +7902,7 @@ new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
   std::unique_ptr<breakpoint> b (new momentary_breakpoint ());
 
   init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
-					&vtable_breakpoint_ops);
+					&base_breakpoint_ops);
 
   b->disposition = disp_donttouch;
   b->frame_id = null_frame_id;
@@ -7927,7 +7927,7 @@ set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
      tail-called one.  */
   gdb_assert (!frame_id_artificial_p (frame_id));
 
-  b = set_raw_breakpoint (gdbarch, sal, type, &vtable_breakpoint_ops);
+  b = set_raw_breakpoint (gdbarch, sal, type, &base_breakpoint_ops);
   b->enable_state = bp_enabled;
   b->disposition = disp_donttouch;
   b->frame_id = frame_id;
@@ -7986,7 +7986,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
   if (orig == NULL)
     return NULL;
 
-  gdb_assert (orig->ops = &vtable_breakpoint_ops);
+  gdb_assert (orig->ops = &base_breakpoint_ops);
   return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
 }
 
@@ -8770,14 +8770,14 @@ breakpoint_ops_for_event_location_type (enum event_location_type location_type,
       if (location_type == PROBE_LOCATION)
 	return &tracepoint_probe_breakpoint_ops;
       else
-	return &vtable_breakpoint_ops;
+	return &base_breakpoint_ops;
     }
   else
     {
       if (location_type == PROBE_LOCATION)
 	return &bkpt_probe_breakpoint_ops;
       else
-	return &vtable_breakpoint_ops;
+	return &base_breakpoint_ops;
     }
 }
 
@@ -8790,7 +8790,7 @@ breakpoint_ops_for_event_location (const struct event_location *location,
   if (location != nullptr)
     return breakpoint_ops_for_event_location_type
       (event_location_type (location), is_tracepoint);
-  return &vtable_breakpoint_ops;
+  return &base_breakpoint_ops;
 }
 
 /* See breakpoint.h.  */
@@ -9198,7 +9198,7 @@ dprintf_command (const char *arg, int from_tty)
 		     0, bp_dprintf,
 		     0 /* Ignore count */,
 		     pending_break_support,
-		     &vtable_breakpoint_ops,
+		     &base_breakpoint_ops,
 		     from_tty,
 		     1 /* enabled */,
 		     0 /* internal */,
@@ -9466,7 +9466,7 @@ break_range_command (const char *arg, int from_tty)
   std::unique_ptr<breakpoint> br (new ranged_breakpoint ());
   init_raw_breakpoint (br.get (), get_current_arch (),
 		       sal_start, bp_hardware_breakpoint,
-		       &vtable_breakpoint_ops);
+		       &base_breakpoint_ops);
   b = add_to_breakpoint_chain (std::move (br));
 
   set_breakpoint_count (breakpoint_count + 1);
@@ -10160,7 +10160,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
 	  scope_breakpoint
 	    = create_internal_breakpoint (caller_arch, caller_pc,
 					  bp_watchpoint_scope,
-					  &vtable_breakpoint_ops);
+					  &base_breakpoint_ops);
 
 	  /* create_internal_breakpoint could invalidate WP_FRAME.  */
 	  wp_frame = NULL;
@@ -10201,7 +10201,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
   else
     w.reset (new watchpoint ());
   init_raw_breakpoint_without_location (w.get (), nullptr, bp_type,
-					&vtable_breakpoint_ops);
+					&base_breakpoint_ops);
 
   w->thread = thread;
   w->task = task;
@@ -10653,7 +10653,7 @@ init_ada_exception_breakpoint (struct breakpoint *b,
     }
 
   init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint,
-		       &vtable_breakpoint_ops);
+		       &base_breakpoint_ops);
 
   b->enable_state = enabled ? bp_enabled : bp_disabled;
   b->disposition = tempflag ? disp_del : disp_donttouch;
@@ -11612,31 +11612,6 @@ breakpoint::print_recreate (struct ui_file *fp)
   internal_error_pure_virtual_called ();
 }
 
-static void
-base_breakpoint_create_sals_from_location
-  (struct event_location *location,
-   struct linespec_result *canonical,
-   enum bptype type_wanted)
-{
-  internal_error_pure_virtual_called ();
-}
-
-static void
-base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
-					struct linespec_result *c,
-					gdb::unique_xmalloc_ptr<char> cond_string,
-					gdb::unique_xmalloc_ptr<char> extra_string,
-					enum bptype type_wanted,
-					enum bpdisp disposition,
-					int thread,
-					int task, int ignore_count,
-					const struct breakpoint_ops *o,
-					int from_tty, int enabled,
-					int internal, unsigned flags)
-{
-  internal_error_pure_virtual_called ();
-}
-
 std::vector<symtab_and_line>
 breakpoint::decode_location (struct event_location *location,
 			     struct program_space *search_pspace)
@@ -11645,12 +11620,6 @@ breakpoint::decode_location (struct event_location *location,
 }
 
 struct breakpoint_ops base_breakpoint_ops =
-{
-  base_breakpoint_create_sals_from_location,
-  base_breakpoint_create_breakpoints_sal,
-};
-
-struct breakpoint_ops vtable_breakpoint_ops =
 {
   create_sals_from_location_default,
   create_breakpoints_sal_default,
@@ -13745,7 +13714,7 @@ ftrace_command (const char *arg, int from_tty)
 		     bp_fast_tracepoint /* type_wanted */,
 		     0 /* Ignore count */,
 		     pending_break_support,
-		     &vtable_breakpoint_ops,
+		     &base_breakpoint_ops,
 		     from_tty,
 		     1 /* enabled */,
 		     0 /* internal */, 0);
@@ -13770,7 +13739,7 @@ strace_command (const char *arg, int from_tty)
     }
   else
     {
-      ops = &vtable_breakpoint_ops;
+      ops = &base_breakpoint_ops;
       location = string_to_event_location (&arg, current_language);
       type = bp_static_tracepoint;
     }
@@ -13853,7 +13822,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
 			  utp->type /* type_wanted */,
 			  0 /* Ignore count */,
 			  pending_break_support,
-			  &vtable_breakpoint_ops,
+			  &base_breakpoint_ops,
 			  0 /* from_tty */,
 			  utp->enabled /* enabled */,
 			  0 /* internal */,
@@ -14400,17 +14369,17 @@ initialize_breakpoint_ops (void)
 
   /* Probe breakpoints.  */
   ops = &bkpt_probe_breakpoint_ops;
-  *ops = vtable_breakpoint_ops;
+  *ops = base_breakpoint_ops;
   ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
 
   /* Probe tracepoints.  */
   ops = &tracepoint_probe_breakpoint_ops;
-  *ops = vtable_breakpoint_ops;
+  *ops = base_breakpoint_ops;
   ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
 
   /* Static tracepoints with marker (`-m').  */
   ops = &strace_marker_breakpoint_ops;
-  *ops = vtable_breakpoint_ops;
+  *ops = base_breakpoint_ops;
   ops->create_sals_from_location = strace_marker_create_sals_from_location;
   ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
 }
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 86f7a9d9665..1c9d9159806 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1381,7 +1381,6 @@ extern void rwatch_command_wrapper (const char *, int, bool);
 extern void tbreak_command (const char *, int);
 
 extern struct breakpoint_ops base_breakpoint_ops;
-extern struct breakpoint_ops vtable_breakpoint_ops;
 
 extern void initialize_breakpoint_ops (void);
 
@@ -1431,8 +1430,7 @@ extern void install_breakpoint (int internal, std::unique_ptr<breakpoint> &&b,
 /* Returns the breakpoint ops appropriate for use with with LOCATION and
    according to IS_TRACEPOINT.  Use this to ensure, for example, that you pass
    the correct ops to create_breakpoint for probe locations.  If LOCATION is
-   NULL, returns bkpt_breakpoint_ops (or vtable_breakpoint_ops, if
-   IS_TRACEPOINT is true).  */
+   NULL, returns base_breakpoint_ops.  */
 
 extern const struct breakpoint_ops *breakpoint_ops_for_event_location
   (const struct event_location *location, bool is_tracepoint);
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index fb034317a6e..1d9fc0de436 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -327,12 +327,12 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
   else if (dprintf)
     {
       type_wanted = bp_dprintf;
-      ops = &vtable_breakpoint_ops;
+      ops = &base_breakpoint_ops;
     }
   else
     {
       type_wanted = hardware ? bp_hardware_breakpoint : bp_breakpoint;
-      ops = &vtable_breakpoint_ops;
+      ops = &base_breakpoint_ops;
     }
 
   if (is_explicit)
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 00129b09240..cbf3a25e911 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -300,7 +300,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 			 bp_breakpoint,
 			 0,
 			 AUTO_BOOLEAN_TRUE,
-			 &vtable_breakpoint_ops,
+			 &base_breakpoint_ops,
 			 0, 1, internal_bp, 0);
     }
   catch (const gdb_exception &except)
-- 
2.31.1


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

* [PATCH 33/36] Remove breakpoint ops initialization
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (31 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 32/36] Remove vtable_breakpoint_ops Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 34/36] Constify breakpoint_ops Tom Tromey
                   ` (3 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

initialize_breakpoint_ops does not do much any more, so remove it in
favor of statically-initialize objects.
---
 gdb/breakpoint.c | 70 +++++++++++++++++++++---------------------------
 gdb/breakpoint.h |  2 --
 2 files changed, 31 insertions(+), 41 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 89893d48b20..3e1883dc3cc 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -234,11 +234,34 @@ static bool is_masked_watchpoint (const struct breakpoint *b);
 
 static int strace_marker_p (struct breakpoint *b);
 
+static void bkpt_probe_create_sals_from_location
+     (struct event_location *location,
+      struct linespec_result *canonical,
+      enum bptype type_wanted);
+static void tracepoint_probe_create_sals_from_location
+     (struct event_location *location,
+      struct linespec_result *canonical,
+      enum bptype type_wanted);
+
+struct breakpoint_ops base_breakpoint_ops =
+{
+  create_sals_from_location_default,
+  create_breakpoints_sal_default,
+};
+
 /* Breakpoints set on probes.  */
-static struct breakpoint_ops bkpt_probe_breakpoint_ops;
+static struct breakpoint_ops bkpt_probe_breakpoint_ops =
+{
+  bkpt_probe_create_sals_from_location,
+  create_breakpoints_sal_default,
+};
 
 /* Tracepoints set on probes.  */
-static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
+static struct breakpoint_ops tracepoint_probe_breakpoint_ops =
+{
+  tracepoint_probe_create_sals_from_location,
+  create_breakpoints_sal_default,
+};
 
 /* The structure to be used in regular breakpoints.  */
 struct ordinary_breakpoint : public base_breakpoint
@@ -11619,12 +11642,6 @@ breakpoint::decode_location (struct event_location *location,
   internal_error_pure_virtual_called ();
 }
 
-struct breakpoint_ops base_breakpoint_ops =
-{
-  create_sals_from_location_default,
-  create_breakpoints_sal_default,
-};
-
 /* Default breakpoint_ops methods.  */
 
 void
@@ -12240,7 +12257,12 @@ static_marker_tracepoint::decode_location (struct event_location *location,
     error (_("marker %s not found"), static_trace_marker_id.c_str ());
 }
 
-static struct breakpoint_ops strace_marker_breakpoint_ops;
+/* Static tracepoints with marker (`-m').  */
+static struct breakpoint_ops strace_marker_breakpoint_ops =
+{
+  strace_marker_create_sals_from_location,
+  strace_marker_create_breakpoints_sal,
+};
 
 static int
 strace_marker_p (struct breakpoint *b)
@@ -14356,34 +14378,6 @@ breakpoint_free_objfile (struct objfile *objfile)
       loc->symtab = NULL;
 }
 
-void
-initialize_breakpoint_ops (void)
-{
-  static int initialized = 0;
-
-  struct breakpoint_ops *ops;
-
-  if (initialized)
-    return;
-  initialized = 1;
-
-  /* Probe breakpoints.  */
-  ops = &bkpt_probe_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
-
-  /* Probe tracepoints.  */
-  ops = &tracepoint_probe_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
-
-  /* Static tracepoints with marker (`-m').  */
-  ops = &strace_marker_breakpoint_ops;
-  *ops = base_breakpoint_ops;
-  ops->create_sals_from_location = strace_marker_create_sals_from_location;
-  ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
-}
-
 /* Chain containing all defined "enable breakpoint" subcommands.  */
 
 static struct cmd_list_element *enablebreaklist = NULL;
@@ -14398,8 +14392,6 @@ _initialize_breakpoint ()
 {
   struct cmd_list_element *c;
 
-  initialize_breakpoint_ops ();
-
   gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib,
 					 "breakpoint");
   gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile,
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 1c9d9159806..71b0acdc399 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1382,8 +1382,6 @@ extern void tbreak_command (const char *, int);
 
 extern struct breakpoint_ops base_breakpoint_ops;
 
-extern void initialize_breakpoint_ops (void);
-
 /* Arguments to pass as context to some catch command handlers.  */
 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
-- 
2.31.1


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

* [PATCH 34/36] Constify breakpoint_ops
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (32 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 33/36] Remove breakpoint ops initialization Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 35/36] Remove allocate_bp_location Tom Tromey
                   ` (2 subsequent siblings)
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Now that all breakpoint_ops are statically initialized, they can all
be made const.
---
 gdb/breakpoint.c | 8 ++++----
 gdb/breakpoint.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 3e1883dc3cc..009ca88dbdb 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -243,21 +243,21 @@ static void tracepoint_probe_create_sals_from_location
       struct linespec_result *canonical,
       enum bptype type_wanted);
 
-struct breakpoint_ops base_breakpoint_ops =
+const struct breakpoint_ops base_breakpoint_ops =
 {
   create_sals_from_location_default,
   create_breakpoints_sal_default,
 };
 
 /* Breakpoints set on probes.  */
-static struct breakpoint_ops bkpt_probe_breakpoint_ops =
+static const struct breakpoint_ops bkpt_probe_breakpoint_ops =
 {
   bkpt_probe_create_sals_from_location,
   create_breakpoints_sal_default,
 };
 
 /* Tracepoints set on probes.  */
-static struct breakpoint_ops tracepoint_probe_breakpoint_ops =
+static const struct breakpoint_ops tracepoint_probe_breakpoint_ops =
 {
   tracepoint_probe_create_sals_from_location,
   create_breakpoints_sal_default,
@@ -13747,7 +13747,7 @@ ftrace_command (const char *arg, int from_tty)
 static void
 strace_command (const char *arg, int from_tty)
 {
-  struct breakpoint_ops *ops;
+  const struct breakpoint_ops *ops;
   event_location_up location;
   enum bptype type;
 
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 71b0acdc399..984560ada85 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1380,7 +1380,7 @@ extern void awatch_command_wrapper (const char *, int, bool);
 extern void rwatch_command_wrapper (const char *, int, bool);
 extern void tbreak_command (const char *, int);
 
-extern struct breakpoint_ops base_breakpoint_ops;
+extern const struct breakpoint_ops base_breakpoint_ops;
 
 /* Arguments to pass as context to some catch command handlers.  */
 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
-- 
2.31.1


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

* [PATCH 35/36] Remove allocate_bp_location
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (33 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 34/36] Constify breakpoint_ops Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-01-18 19:40 ` [PATCH 36/36] Remove create_breakpoints_sal_default Tom Tromey
  2022-04-22 20:21 ` [PATCH 00/36] C++-ify breakpoints Tom Tromey
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

allocate_bp_location is just a small wrapper for a method call, so
inline it everywhere.
---
 gdb/breakpoint.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 009ca88dbdb..587344d6d74 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -175,8 +175,6 @@ static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
 
 static void decref_bp_location (struct bp_location **loc);
 
-static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
-
 static std::vector<symtab_and_line> bkpt_probe_decode_location
      (struct breakpoint *b,
       struct event_location *location,
@@ -1829,7 +1827,7 @@ software_watchpoint_add_no_memory_location (struct breakpoint *b,
 {
   gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
 
-  b->loc = allocate_bp_location (b);
+  b->loc = b->allocate_location ();
   b->loc->pspace = pspace;
   b->loc->address = -1;
   b->loc->length = -1;
@@ -2082,7 +2080,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
 		  else if (b->type == bp_access_watchpoint)
 		    type = hw_access;
 
-		  loc = allocate_bp_location (b);
+		  loc = b->allocate_location ();
 		  for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
 		    ;
 		  *tmp = loc;
@@ -7137,14 +7135,6 @@ bp_location::bp_location (breakpoint *owner)
 {
 }
 
-/* Allocate a struct bp_location.  */
-
-static struct bp_location *
-allocate_bp_location (struct breakpoint *bpt)
-{
-  return bpt->allocate_location ();
-}
-
 /* Decrement reference count.  If the reference count reaches 0,
    destroy the bp_location.  Sets *BLP to NULL.  */
 
@@ -7975,7 +7965,7 @@ momentary_breakpoint_from_master (struct breakpoint *orig,
   struct breakpoint *copy;
 
   copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
-  copy->loc = allocate_bp_location (copy);
+  copy->loc = copy->allocate_location ();
   set_breakpoint_location_function (copy->loc);
 
   copy->loc->gdbarch = orig->loc->gdbarch;
@@ -8107,7 +8097,7 @@ add_location_to_breakpoint (struct breakpoint *b,
     loc_gdbarch = b->gdbarch;
 
   /* Adjust the breakpoint's address prior to allocating a location.
-     Once we call allocate_bp_location(), that mostly uninitialized
+     Once we call allocate_location(), that mostly uninitialized
      location will be placed on the location chain.  Adjustment of the
      breakpoint may cause target_read_memory() to be called and we do
      not want its scan of the location chain to find a breakpoint and
@@ -8116,7 +8106,7 @@ add_location_to_breakpoint (struct breakpoint *b,
 						sal->pc, b->type);
 
   /* Sort the locations by their ADDRESS.  */
-  loc = allocate_bp_location (b);
+  loc = b->allocate_location ();
   for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
        tmp = &((*tmp)->next))
     ;
-- 
2.31.1


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

* [PATCH 36/36] Remove create_breakpoints_sal_default
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (34 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 35/36] Remove allocate_bp_location Tom Tromey
@ 2022-01-18 19:40 ` Tom Tromey
  2022-04-22 20:21 ` [PATCH 00/36] C++-ify breakpoints Tom Tromey
  36 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-01-18 19:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

create_breakpoints_sal_default is just a simple wrapper, so remove it.
---
 gdb/breakpoint.c | 49 ++++++++++++------------------------------------
 1 file changed, 12 insertions(+), 37 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 587344d6d74..b5325f4a6e9 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -94,15 +94,15 @@ static void
 				     struct linespec_result *canonical,
 				     enum bptype type_wanted);
 
-static void create_breakpoints_sal_default (struct gdbarch *,
-					    struct linespec_result *,
-					    gdb::unique_xmalloc_ptr<char>,
-					    gdb::unique_xmalloc_ptr<char>,
-					    enum bptype,
-					    enum bpdisp, int, int,
-					    int,
-					    const struct breakpoint_ops *,
-					    int, int, int, unsigned);
+static void create_breakpoints_sal (struct gdbarch *,
+				    struct linespec_result *,
+				    gdb::unique_xmalloc_ptr<char>,
+				    gdb::unique_xmalloc_ptr<char>,
+				    enum bptype,
+				    enum bpdisp, int, int,
+				    int,
+				    const struct breakpoint_ops *,
+				    int, int, int, unsigned);
 
 static std::vector<symtab_and_line> decode_location_default
   (struct breakpoint *b, struct event_location *location,
@@ -244,21 +244,21 @@ static void tracepoint_probe_create_sals_from_location
 const struct breakpoint_ops base_breakpoint_ops =
 {
   create_sals_from_location_default,
-  create_breakpoints_sal_default,
+  create_breakpoints_sal,
 };
 
 /* Breakpoints set on probes.  */
 static const struct breakpoint_ops bkpt_probe_breakpoint_ops =
 {
   bkpt_probe_create_sals_from_location,
-  create_breakpoints_sal_default,
+  create_breakpoints_sal,
 };
 
 /* Tracepoints set on probes.  */
 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops =
 {
   tracepoint_probe_create_sals_from_location,
-  create_breakpoints_sal_default,
+  create_breakpoints_sal,
 };
 
 /* The structure to be used in regular breakpoints.  */
@@ -12912,31 +12912,6 @@ create_sals_from_location_default (struct event_location *location,
   parse_breakpoint_sals (location, canonical);
 }
 
-/* Call create_breakpoints_sal for the given arguments.  This is the default
-   function for the `create_breakpoints_sal' method of
-   breakpoint_ops.  */
-
-static void
-create_breakpoints_sal_default (struct gdbarch *gdbarch,
-				struct linespec_result *canonical,
-				gdb::unique_xmalloc_ptr<char> cond_string,
-				gdb::unique_xmalloc_ptr<char> extra_string,
-				enum bptype type_wanted,
-				enum bpdisp disposition,
-				int thread,
-				int task, int ignore_count,
-				const struct breakpoint_ops *ops,
-				int from_tty, int enabled,
-				int internal, unsigned flags)
-{
-  create_breakpoints_sal (gdbarch, canonical,
-			  std::move (cond_string),
-			  std::move (extra_string),
-			  type_wanted, disposition,
-			  thread, task, ignore_count, ops, from_tty,
-			  enabled, internal, flags);
-}
-
 /* Decode the line represented by S by calling decode_line_full.  This is the
    default function for the `decode_location' method of breakpoint_ops.  */
 
-- 
2.31.1


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

* Re: [PATCH 00/36] C++-ify breakpoints
  2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
                   ` (35 preceding siblings ...)
  2022-01-18 19:40 ` [PATCH 36/36] Remove create_breakpoints_sal_default Tom Tromey
@ 2022-04-22 20:21 ` Tom Tromey
  2022-04-23  2:59   ` Simon Marchi
  36 siblings, 1 reply; 49+ messages in thread
From: Tom Tromey @ 2022-04-22 20:21 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> This series somewhat C++-ifies breakpoints.  It turns most
Tom> breakpoint_ops function pointers into virtual methods, and introduces
Tom> a class hierarchy for breakpoints.

I'd appreciate comments on this series.

Tom

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

* Re: [PATCH 01/36] Move "catch load" to a new file
  2022-01-18 19:39 ` [PATCH 01/36] Move "catch load" to a new file Tom Tromey
@ 2022-04-23  2:34   ` Simon Marchi
  2022-04-24 19:35     ` Tom Tromey
  0 siblings, 1 reply; 49+ messages in thread
From: Simon Marchi @ 2022-04-23  2:34 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2022-01-18 14:39, Tom Tromey wrote:
> The "catch load" code is reasonably self-contained, and so this patch
> moves it out of breakpoint.c and into a new file, break-catch-load.c.
> One function from breakpoint.c, print_solib_event, now has to be
> exposed, but this seems pretty reasonable.  This patch moves it to the
> new file, to keep it near the other solib code.  After this change,
> breakpoint.c drops to third place in size, now after remote.c.

I would personally have left print_solib_event, since it's not really
something specific to the catchpoint implementation (what the new file
is about).  I also don't really like when functions are declared and
implemented in files with different basenames (the part before the
extension).

Still, this LGTM either way, I think it makes sense to move the load
catchpoint stuff to its own file.

Simon

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

* Re: [PATCH 00/36] C++-ify breakpoints
  2022-04-22 20:21 ` [PATCH 00/36] C++-ify breakpoints Tom Tromey
@ 2022-04-23  2:59   ` Simon Marchi
  2022-04-29 22:15     ` Tom Tromey
  0 siblings, 1 reply; 49+ messages in thread
From: Simon Marchi @ 2022-04-23  2:59 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches



On 2022-04-22 16:21, Tom Tromey wrote:
>>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
> 
> Tom> This series somewhat C++-ifies breakpoints.  It turns most
> Tom> breakpoint_ops function pointers into virtual methods, and introduces
> Tom> a class hierarchy for breakpoints.
> 
> I'd appreciate comments on this series.
> 
> Tom

Apart from the small comment on patch 1, I don't have any comments.  I appreciate
how you managed to split this up in so many steps.  If we ever have to bisect a
regression due to this series, it will make it much easier.  I have attempted this
conversion in the patch and didn't finish it, I know how much work that is, good
job!

Simon

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

* Re: [PATCH 01/36] Move "catch load" to a new file
  2022-04-23  2:34   ` Simon Marchi
@ 2022-04-24 19:35     ` Tom Tromey
  0 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-04-24 19:35 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

Simon> I would personally have left print_solib_event, since it's not really
Simon> something specific to the catchpoint implementation (what the new file
Simon> is about).  I also don't really like when functions are declared and
Simon> implemented in files with different basenames (the part before the
Simon> extension).

Simon> Still, this LGTM either way, I think it makes sense to move the load
Simon> catchpoint stuff to its own file.

I went ahead and removed the print_solib_event part of this patch,
leaving it in breakpoint.c.

Tom

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

* Re: [PATCH 03/36] Add an assertion to clone_momentary_breakpoint
  2022-01-18 19:39 ` [PATCH 03/36] Add an assertion to clone_momentary_breakpoint Tom Tromey
@ 2022-04-25 13:25   ` Thiago Jung Bauermann
  2022-04-25 19:03     ` Tom Tromey
  0 siblings, 1 reply; 49+ messages in thread
From: Thiago Jung Bauermann @ 2022-04-25 13:25 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches


Hi Tom,

Great patch series! Just something that caught my eye:

Tom Tromey <tom@tromey.com> writes:

> This adds an assertion to clone_momentary_breakpoint.  This will
> eventually be removed, but in the meantime is is useful for helping
> convince oneself that momentary breakpoints will always use
> momentary_breakpoint_ops.  This understanding will help when cleaning
> up the code later.
> ---
>  gdb/breakpoint.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index da9997f18d6..a0b8bd4e127 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -7900,6 +7900,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
>    if (orig == NULL)
>      return NULL;
>  
> +  gdb_assert (orig->ops = &momentary_breakpoint_ops);

This needs to be ‘==’ rather than ‘=’. :-)

>    return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
>  }


-- 
Thiago

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

* Re: [PATCH 04/36] Delete some unnecessary wrapper functions
  2022-01-18 19:39 ` [PATCH 04/36] Delete some unnecessary wrapper functions Tom Tromey
@ 2022-04-25 14:08   ` Thiago Jung Bauermann
  2022-04-25 19:06     ` Tom Tromey
  0 siblings, 1 reply; 49+ messages in thread
From: Thiago Jung Bauermann @ 2022-04-25 14:08 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches


Tom Tromey <tom@tromey.com> writes:

> -static void
> -bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
> -			     struct linespec_result *canonical,
> -			     gdb::unique_xmalloc_ptr<char> cond_string,
> -			     gdb::unique_xmalloc_ptr<char> extra_string,
> -			     enum bptype type_wanted,
> -			     enum bpdisp disposition,
> -			     int thread,
> -			     int task, int ignore_count,
> -			     const struct breakpoint_ops *ops,
> -			     int from_tty, int enabled,
> -			     int internal, unsigned flags)
> -{
> -  create_breakpoints_sal_default (gdbarch, canonical,
> -				  std::move (cond_string),
> -				  std::move (extra_string),
> -				  type_wanted,
> -				  disposition, thread, task,
> -				  ignore_count, ops, from_tty,
> -				  enabled, internal, flags);
> -}

The wrapper here does an std::move() of the string arguments.


> -static void
> -tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
> -				   struct linespec_result *canonical,
> -				   gdb::unique_xmalloc_ptr<char> cond_string,
> -				   gdb::unique_xmalloc_ptr<char> extra_string,
> -				   enum bptype type_wanted,
> -				   enum bpdisp disposition,
> -				   int thread,
> -				   int task, int ignore_count,
> -				   const struct breakpoint_ops *ops,
> -				   int from_tty, int enabled,
> -				   int internal, unsigned flags)
> -{
> -  create_breakpoints_sal_default (gdbarch, canonical,
> -				  std::move (cond_string),
> -				  std::move (extra_string),
> -				  type_wanted,
> -				  disposition, thread, task,
> -				  ignore_count, ops, from_tty,
> -				  enabled, internal, flags);
> -}

Here too.

> @@ -14487,8 +14427,8 @@ initialize_breakpoint_ops (void)
>    ops->insert_location = bkpt_insert_location;
>    ops->remove_location = bkpt_remove_location;
>    ops->breakpoint_hit = bkpt_breakpoint_hit;
> -  ops->create_sals_from_location = bkpt_create_sals_from_location;
> -  ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
> +  ops->create_sals_from_location = create_sals_from_location_default;
> +  ops->create_breakpoints_sal = create_breakpoints_sal_default;
>    ops->decode_location = bkpt_decode_location;
>  
>    /* The breakpoint_ops structure to be used in regular breakpoints.  */
> @@ -14570,8 +14510,8 @@ initialize_breakpoint_ops (void)
>    ops->print_one_detail = tracepoint_print_one_detail;
>    ops->print_mention = tracepoint_print_mention;
>    ops->print_recreate = tracepoint_print_recreate;
> -  ops->create_sals_from_location = tracepoint_create_sals_from_location;
> -  ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
> +  ops->create_sals_from_location = create_sals_from_location_default;
> +  ops->create_breakpoints_sal = create_breakpoints_sal_default;
>    ops->decode_location = tracepoint_decode_location;

So shouldn't the callers of ops->create_breakpoints_sal () be changed to
do the std::move() themselves?

-- 
Thiago

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

* Re: [PATCH 03/36] Add an assertion to clone_momentary_breakpoint
  2022-04-25 13:25   ` Thiago Jung Bauermann
@ 2022-04-25 19:03     ` Tom Tromey
  0 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-04-25 19:03 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: Tom Tromey, gdb-patches

>>>>> "Thiago" == Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:

>> +  gdb_assert (orig->ops = &momentary_breakpoint_ops);

Thiago> This needs to be ‘==’ rather than ‘=’. :-)

Nice catch.  This shows that this patch was actually completely invalid
from the start.  And when fixing this I found out that the error
propagated through several other changes as well.

I'm going to re-test selected parts of the series to make sure that
nothing bad happened.

Tom

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

* Re: [PATCH 04/36] Delete some unnecessary wrapper functions
  2022-04-25 14:08   ` Thiago Jung Bauermann
@ 2022-04-25 19:06     ` Tom Tromey
  2022-04-25 20:06       ` Thiago Jung Bauermann
  0 siblings, 1 reply; 49+ messages in thread
From: Tom Tromey @ 2022-04-25 19:06 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: Tom Tromey, gdb-patches

>>>>> "Thiago" == Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:

Thiago> The wrapper here does an std::move() of the string arguments.

Yeah.  That's needed because std::unique_ptr is move-only.

Thiago> So shouldn't the callers of ops->create_breakpoints_sal () be changed to
Thiago> do the std::move() themselves?

I think there's only one, and it does:

      ops->create_breakpoints_sal (gdbarch, &canonical,
				   std::move (cond_string_copy),
				   std::move (extra_string_copy),
				   type_wanted,
				   tempflag ? disp_del : disp_donttouch,
				   thread, task, ignore_count, ops,
				   from_tty, enabled, internal, flags);

Tom

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

* Re: [PATCH 04/36] Delete some unnecessary wrapper functions
  2022-04-25 19:06     ` Tom Tromey
@ 2022-04-25 20:06       ` Thiago Jung Bauermann
  0 siblings, 0 replies; 49+ messages in thread
From: Thiago Jung Bauermann @ 2022-04-25 20:06 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches


Hello Tom,

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Thiago" == Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:
>
> Thiago> The wrapper here does an std::move() of the string arguments.
>
> Yeah.  That's needed because std::unique_ptr is move-only.
>
> Thiago> So shouldn't the callers of ops->create_breakpoints_sal () be changed to
> Thiago> do the std::move() themselves?
>
> I think there's only one, and it does:
>
>       ops->create_breakpoints_sal (gdbarch, &canonical,
> 				   std::move (cond_string_copy),
> 				   std::move (extra_string_copy),
> 				   type_wanted,
> 				   tempflag ? disp_del : disp_donttouch,
> 				   thread, task, ignore_count, ops,
> 				   from_tty, enabled, internal, flags);

Yes, you are right. Sorry for the noise.

-- 
Thiago

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

* Re: [PATCH 00/36] C++-ify breakpoints
  2022-04-23  2:59   ` Simon Marchi
@ 2022-04-29 22:15     ` Tom Tromey
  0 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-04-29 22:15 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Tom Tromey, Simon Marchi

Tom> I'd appreciate comments on this series.

Simon> Apart from the small comment on patch 1, I don't have any comments.  I appreciate
Simon> how you managed to split this up in so many steps.  If we ever have to bisect a
Simon> regression due to this series, it will make it much easier.  I have attempted this
Simon> conversion in the patch and didn't finish it, I know how much work that is, good
Simon> job!

I'm going to check this in now.

Tom

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

* Re: [PATCH 15/36] Convert base breakpoints to vtable ops
  2022-01-18 19:39 ` [PATCH 15/36] Convert base breakpoints to vtable ops Tom Tromey
@ 2022-05-02 10:27   ` Tom de Vries
  2022-05-02 16:40     ` Tom Tromey
  0 siblings, 1 reply; 49+ messages in thread
From: Tom de Vries @ 2022-05-02 10:27 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 1/18/22 20:39, Tom Tromey wrote:
> This converts base breakpoints to use vtable_breakpoint_ops.

This causes a regression for me:
...
(gdb) PASS: gdb.ada/catch_assert_if.exp: Check catch assertions with 
condition
continue^M
Continuing.^M
breakpoint.c:11568: internal-error: insert_location: \
   pure virtual function called^M
...

Filed as https://sourceware.org/bugzilla/show_bug.cgi?id=29114 .

Thanks,
- Tom

> ---
>   gdb/break-catch-throw.c |  2 +-
>   gdb/breakpoint.c        | 55 ++++++++++++++++++-----------------------
>   gdb/breakpoint.h        | 11 +++++++++
>   3 files changed, 36 insertions(+), 32 deletions(-)
> 
> diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
> index a49736cfd5f..86a8fe4ffc6 100644
> --- a/gdb/break-catch-throw.c
> +++ b/gdb/break-catch-throw.c
> @@ -67,7 +67,7 @@ static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
>   
>   /* The type of an exception catchpoint.  */
>   
> -struct exception_catchpoint : public breakpoint
> +struct exception_catchpoint : public base_breakpoint
>   {
>     /* The kind of exception catchpoint.  */
>   
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index a4ea44995b7..e9b6a801646 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -7873,7 +7873,7 @@ enable_breakpoints_after_startup (void)
>   static struct breakpoint *
>   new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
>   {
> -  std::unique_ptr<breakpoint> b (new breakpoint ());
> +  std::unique_ptr<breakpoint> b (new momentary_breakpoint ());
>   
>     init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
>   					&momentary_breakpoint_ops);
> @@ -11809,22 +11809,22 @@ struct breakpoint_ops vtable_breakpoint_ops =
>   
>   /* Default breakpoint_ops methods.  */
>   
> -static void
> -bkpt_re_set (struct breakpoint *b)
> +void
> +base_breakpoint::re_set ()
>   {
>     /* FIXME: is this still reachable?  */
> -  if (breakpoint_event_location_empty_p (b))
> +  if (breakpoint_event_location_empty_p (this))
>       {
>         /* Anything without a location can't be re-set.  */
> -      delete_breakpoint (b);
> +      delete_breakpoint (this);
>         return;
>       }
>   
> -  breakpoint_re_set_default (b);
> +  breakpoint_re_set_default (this);
>   }
>   
> -static int
> -bkpt_insert_location (struct bp_location *bl)
> +int
> +base_breakpoint::insert_location (struct bp_location *bl)
>   {
>     CORE_ADDR addr = bl->target_info.reqstd_address;
>   
> @@ -11837,8 +11837,9 @@ bkpt_insert_location (struct bp_location *bl)
>       return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
>   }
>   
> -static int
> -bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
> +int
> +base_breakpoint::remove_location (struct bp_location *bl,
> +				  enum remove_bp_reason reason)
>   {
>     if (bl->loc_type == bp_loc_hardware_breakpoint)
>       return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
> @@ -11846,10 +11847,11 @@ bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
>       return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
>   }
>   
> -static int
> -bkpt_breakpoint_hit (const struct bp_location *bl,
> -		     const address_space *aspace, CORE_ADDR bp_addr,
> -		     const target_waitstatus &ws)
> +int
> +base_breakpoint::breakpoint_hit (const struct bp_location *bl,
> +				 const address_space *aspace,
> +				 CORE_ADDR bp_addr,
> +				 const target_waitstatus &ws)
>   {
>     if (ws.kind () != TARGET_WAITKIND_STOPPED
>         || ws.sig () != GDB_SIGNAL_TRAP)
> @@ -11881,7 +11883,7 @@ dprintf_breakpoint_hit (const struct bp_location *bl,
>         return 0;
>       }
>   
> -  return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
> +  return bl->owner->breakpoint_hit (bl, aspace, bp_addr, ws);
>   }
>   
>   static int
> @@ -11985,12 +11987,11 @@ bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
>     print_recreate_thread (tp, fp);
>   }
>   
> -static std::vector<symtab_and_line>
> -bkpt_decode_location (struct breakpoint *b,
> -		      struct event_location *location,
> -		      struct program_space *search_pspace)
> +std::vector<symtab_and_line>
> +base_breakpoint::decode_location (struct event_location *location,
> +				  struct program_space *search_pspace)
>   {
> -  return decode_location_default (b, location, search_pspace);
> +  return decode_location_default (this, location, search_pspace);
>   }
>   
>   /* Virtual table for internal breakpoints.  */
> @@ -12137,7 +12138,7 @@ longjmp_breakpoint::~longjmp_breakpoint ()
>   static int
>   bkpt_probe_insert_location (struct bp_location *bl)
>   {
> -  int v = bkpt_insert_location (bl);
> +  int v = bl->owner->insert_location (bl);
>   
>     if (v == 0)
>       {
> @@ -12156,7 +12157,7 @@ bkpt_probe_remove_location (struct bp_location *bl,
>     /* Let's clear the semaphore before removing the location.  */
>     bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
>   
> -  return bkpt_remove_location (bl, reason);
> +  return bl->owner->remove_location (bl, reason);
>   }
>   
>   static void
> @@ -14572,19 +14573,11 @@ initialize_breakpoint_ops (void)
>        breakpoints (real breakpoints, i.e., user "break" breakpoints,
>        internal and momentary breakpoints, etc.).  */
>     ops = &bkpt_base_breakpoint_ops;
> -  *ops = base_breakpoint_ops;
> -  ops->re_set = bkpt_re_set;
> -  ops->insert_location = bkpt_insert_location;
> -  ops->remove_location = bkpt_remove_location;
> -  ops->breakpoint_hit = bkpt_breakpoint_hit;
> -  ops->create_sals_from_location = create_sals_from_location_default;
> -  ops->create_breakpoints_sal = create_breakpoints_sal_default;
> -  ops->decode_location = bkpt_decode_location;
> +  *ops = vtable_breakpoint_ops;
>   
>     /* The breakpoint_ops structure to be used in regular breakpoints.  */
>     ops = &bkpt_breakpoint_ops;
>     *ops = bkpt_base_breakpoint_ops;
> -  ops->re_set = bkpt_re_set;
>     ops->resources_needed = bkpt_resources_needed;
>     ops->print_it = bkpt_print_it;
>     ops->print_mention = bkpt_print_mention;
> diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
> index a5365bf1808..11b65ab8318 100644
> --- a/gdb/breakpoint.h
> +++ b/gdb/breakpoint.h
> @@ -945,6 +945,17 @@ struct breakpoint
>      breakpoints, etc.).  */
>   struct base_breakpoint : public breakpoint
>   {
> +  void re_set () override;
> +  int insert_location (struct bp_location *) override;
> +  int remove_location (struct bp_location *,
> +		       enum remove_bp_reason reason) override;
> +  int breakpoint_hit (const struct bp_location *bl,
> +		      const address_space *aspace,
> +		      CORE_ADDR bp_addr,
> +		      const target_waitstatus &ws) override;
> +  std::vector<symtab_and_line> decode_location
> +       (struct event_location *location,
> +	struct program_space *search_pspace) override;
>   };
>   
>   /* An instance of this type is used to represent a watchpoint.  */

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

* Re: [PATCH 15/36] Convert base breakpoints to vtable ops
  2022-05-02 10:27   ` Tom de Vries
@ 2022-05-02 16:40     ` Tom Tromey
  0 siblings, 0 replies; 49+ messages in thread
From: Tom Tromey @ 2022-05-02 16:40 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom Tromey, Tom de Vries

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> On 1/18/22 20:39, Tom Tromey wrote:
>> This converts base breakpoints to use vtable_breakpoint_ops.

Tom> This causes a regression for me:
Tom> ...
Tom> (gdb) PASS: gdb.ada/catch_assert_if.exp: Check catch assertions with
Tom> condition
Tom> continue^M
Tom> Continuing.^M
Tom> breakpoint.c:11568: internal-error: insert_location: \
Tom>   pure virtual function called^M
Tom> ...

Tom> Filed as https://sourceware.org/bugzilla/show_bug.cgi?id=29114 .

Sorry about this.
I found it this morning as well, before I saw the note or the bug, and
have checked in a fix.

Tom

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

end of thread, other threads:[~2022-05-02 16:40 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 19:39 [PATCH 00/36] C++-ify breakpoints Tom Tromey
2022-01-18 19:39 ` [PATCH 01/36] Move "catch load" to a new file Tom Tromey
2022-04-23  2:34   ` Simon Marchi
2022-04-24 19:35     ` Tom Tromey
2022-01-18 19:39 ` [PATCH 02/36] Boolify print_solib_event Tom Tromey
2022-01-18 19:39 ` [PATCH 03/36] Add an assertion to clone_momentary_breakpoint Tom Tromey
2022-04-25 13:25   ` Thiago Jung Bauermann
2022-04-25 19:03     ` Tom Tromey
2022-01-18 19:39 ` [PATCH 04/36] Delete some unnecessary wrapper functions Tom Tromey
2022-04-25 14:08   ` Thiago Jung Bauermann
2022-04-25 19:06     ` Tom Tromey
2022-04-25 20:06       ` Thiago Jung Bauermann
2022-01-18 19:39 ` [PATCH 05/36] Return bool from breakpoint_ops::print_one Tom Tromey
2022-01-18 19:39 ` [PATCH 06/36] Add a vtable-based breakpoint ops Tom Tromey
2022-01-18 19:39 ` [PATCH 07/36] Convert break-catch-sig to use vtable ops Tom Tromey
2022-01-18 19:39 ` [PATCH 08/36] Convert break-catch-syscall to " Tom Tromey
2022-01-18 19:39 ` [PATCH 09/36] Convert break-catch-exec " Tom Tromey
2022-01-18 19:39 ` [PATCH 10/36] Convert break-catch-fork " Tom Tromey
2022-01-18 19:39 ` [PATCH 11/36] Convert break-catch-load " Tom Tromey
2022-01-18 19:39 ` [PATCH 12/36] Convert watchpoints " Tom Tromey
2022-01-18 19:39 ` [PATCH 13/36] Convert tracepoints " Tom Tromey
2022-01-18 19:39 ` [PATCH 14/36] Add some new subclasses of breakpoint Tom Tromey
2022-01-18 19:39 ` [PATCH 15/36] Convert base breakpoints to vtable ops Tom Tromey
2022-05-02 10:27   ` Tom de Vries
2022-05-02 16:40     ` Tom Tromey
2022-01-18 19:39 ` [PATCH 16/36] Convert break-catch-throw " Tom Tromey
2022-01-18 19:39 ` [PATCH 17/36] Convert internal breakpoints " Tom Tromey
2022-01-18 19:39 ` [PATCH 18/36] Convert momentary " Tom Tromey
2022-01-18 19:39 ` [PATCH 19/36] Change inheritance of dprintf Tom Tromey
2022-01-18 19:39 ` [PATCH 20/36] Convert ordinary breakpoints to vtable ops Tom Tromey
2022-01-18 19:39 ` [PATCH 21/36] Convert Ada catchpoints " Tom Tromey
2022-01-18 19:39 ` [PATCH 22/36] Convert dprintf " Tom Tromey
2022-01-18 19:39 ` [PATCH 23/36] Convert ranged breakpoints " Tom Tromey
2022-01-18 19:39 ` [PATCH 24/36] Add bp_static_marker_tracepoint Tom Tromey
2022-01-18 19:39 ` [PATCH 25/36] Convert static marker tracepoints to vtable ops Tom Tromey
2022-01-18 19:39 ` [PATCH 26/36] Remove bkpt_base_breakpoint_ops Tom Tromey
2022-01-18 19:39 ` [PATCH 27/36] Merge probe and ordinary breakpoints Tom Tromey
2022-01-18 19:39 ` [PATCH 28/36] Merge probe and ordinary tracepoints Tom Tromey
2022-01-18 19:40 ` [PATCH 29/36] Remove breakpoint_ops from init_ada_exception_breakpoint Tom Tromey
2022-01-18 19:40 ` [PATCH 30/36] Remove breakpoint_ops from init_catchpoint Tom Tromey
2022-01-18 19:40 ` [PATCH 31/36] Remove most fields from breakpoint_ops Tom Tromey
2022-01-18 19:40 ` [PATCH 32/36] Remove vtable_breakpoint_ops Tom Tromey
2022-01-18 19:40 ` [PATCH 33/36] Remove breakpoint ops initialization Tom Tromey
2022-01-18 19:40 ` [PATCH 34/36] Constify breakpoint_ops Tom Tromey
2022-01-18 19:40 ` [PATCH 35/36] Remove allocate_bp_location Tom Tromey
2022-01-18 19:40 ` [PATCH 36/36] Remove create_breakpoints_sal_default Tom Tromey
2022-04-22 20:21 ` [PATCH 00/36] C++-ify breakpoints Tom Tromey
2022-04-23  2:59   ` Simon Marchi
2022-04-29 22:15     ` 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).