public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Convert break-catch-throw to vtable ops
@ 2022-04-29 22:23 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-04-29 22:23 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5bd3caf1b2f95139764916e2a6e07a95453b717f

commit 5bd3caf1b2f95139764916e2a6e07a95453b717f
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Jan 14 18:52:13 2022 -0700

    Convert break-catch-throw to vtable ops
    
    This converts break-catch-throw.c to use vtable_breakpoint_ops.

Diff:
---
 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 62a404f33ac..f9bcc8d0b74 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;
   gdb_printf (fp, bp_temp ? "tcatch " : "catch ");
   switch (kind)
     {
@@ -348,16 +338,16 @@ print_recreate_exception_catchpoint (struct breakpoint *b,
       gdb_printf (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);
 }
@@ -516,32 +506,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."),


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-29 22:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 22:23 [binutils-gdb] Convert break-catch-throw to vtable ops 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).