Convert tracepoints to vtable ops
authorTom Tromey <tom@tromey.com>
Sat, 15 Jan 2022 16:57:44 +0000 (09:57 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 29 Apr 2022 22:14:31 +0000 (16:14 -0600)
This converts tracepoints to use vtable_breakpoint_ops.

gdb/breakpoint.c
gdb/breakpoint.h
gdb/mi/mi-cmd-break.c

index d3a1bea399f32116971bb80c36d4c1fa1e6537a6..5a133e1c31b0472043671f5796f44b17bb94b4a7 100644 (file)
@@ -8744,7 +8744,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
     {
@@ -8764,7 +8764,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.  */
@@ -12117,98 +12117,90 @@ 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:
       gdb_printf (_("Tracepoint"));
-      gdb_printf (_(" %d"), b->number);
+      gdb_printf (_(" %d"), number);
       break;
     case bp_fast_tracepoint:
       gdb_printf (_("Fast tracepoint"));
-      gdb_printf (_(" %d"), b->number);
+      gdb_printf (_(" %d"), number);
       break;
     case bp_static_tracepoint:
       gdb_printf (_("Static tracepoint"));
-      gdb_printf (_(" %d"), b->number);
+      gdb_printf (_(" %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)
     gdb_printf (fp, "ftrace");
-  else if (self->type == bp_static_tracepoint)
+  else if (type == bp_static_tracepoint)
     gdb_printf (fp, "strace");
-  else if (self->type == bp_tracepoint)
+  else if (type == bp_tracepoint)
     gdb_printf (fp, "trace");
   else
     internal_error (__FILE__, __LINE__,
-                   _("unhandled tracepoint type %d"), (int) self->type);
+                   _("unhandled tracepoint type %d"), (int) type);
 
-  gdb_printf (fp, " %s",
-             event_location_to_string (self->location.get ()));
-  print_recreate_thread (self, fp);
+  gdb_printf (fp, " %s", event_location_to_string (location.get ()));
+  print_recreate_thread (this, fp);
 
-  if (tp->pass_count)
-    gdb_printf (fp, "  passcount %d\n", tp->pass_count);
+  if (pass_count)
+    gdb_printf (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
@@ -13858,7 +13850,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);
@@ -13881,7 +13873,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);
     }
 
@@ -13963,7 +13955,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 */,
@@ -14565,27 +14557,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;
index 3d7a59076f095f19fd4ec408c19cee8b348876dd..7d62c0ac459d52f0267664e4add7df39b19e2f3d 100644 (file)
@@ -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;
@@ -1461,7 +1473,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;
 
@@ -1516,7 +1527,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
index 05eac3553aee12832cd6679c8c3b4343be3817eb..a5c78529dd1f77760c7220e470535f3cada670d8 100644 (file)
@@ -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)
     {