Add some new subclasses of breakpoint
authorTom Tromey <tom@tromey.com>
Sat, 15 Jan 2022 20:37:28 +0000 (13:37 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 29 Apr 2022 22:14:31 +0000 (16:14 -0600)
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
gdb/breakpoint.h

index 5a133e1c31b0472043671f5796f44b17bb94b4a7..ab7559723693599eeda65f4a2e51bfdcfc30d090 100644 (file)
@@ -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);
 }
index 7d62c0ac459d52f0267664e4add7df39b19e2f3d..a4b3ce17b01fdd632cfab0ecdafde74dc272c52d 100644 (file)
@@ -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