gdb: link breakpoints with intrusive_list
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 9 May 2023 14:04:23 +0000 (10:04 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 25 May 2023 13:41:16 +0000 (09:41 -0400)
Change-Id: I043d8d6f3dd864d80d5088f6ffc2c098337249ea
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
gdb/breakpoint.c
gdb/breakpoint.h

index 0cdf5a7158b4a6e9ee8d80a99d64beeef84d829f..8c613072543d3120096b5fc75609578e8836b38a 100644 (file)
@@ -614,14 +614,16 @@ bool target_exact_watchpoints = false;
 
 /* Chains of all breakpoints defined.  */
 
-static struct breakpoint *breakpoint_chain;
+static intrusive_list<breakpoint> breakpoint_chain;
 
 /* See breakpoint.h.  */
 
 breakpoint_range
 all_breakpoints ()
 {
-  return breakpoint_range (breakpoint_chain);
+  return breakpoint_range
+    (breakpoint_pointer_iterator (breakpoint_chain.begin ()),
+     breakpoint_pointer_iterator (breakpoint_chain.end ()));
 }
 
 /* See breakpoint.h.  */
@@ -637,7 +639,9 @@ all_breakpoints_safe ()
 tracepoint_range
 all_tracepoints ()
 {
-  return tracepoint_range (breakpoint_chain);
+  return tracepoint_range
+    (tracepoint_iterator (breakpoint_pointer_iterator (breakpoint_chain.begin ())),
+     tracepoint_iterator (breakpoint_pointer_iterator (breakpoint_chain.end ())));
 }
 
 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS.  */
@@ -7428,23 +7432,12 @@ decref_bp_location (struct bp_location **blp)
 static breakpoint *
 add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b)
 {
-  struct breakpoint *b1;
-  struct breakpoint *result = b.get ();
-
   /* Add this breakpoint to the end of the chain so that a list of
      breakpoints will come out in order of increasing numbers.  */
 
-  b1 = breakpoint_chain;
-  if (b1 == 0)
-    breakpoint_chain = b.release ();
-  else
-    {
-      while (b1->next)
-       b1 = b1->next;
-      b1->next = b.release ();
-    }
+  breakpoint_chain.push_back (*b.release ());
 
-  return result;
+  return &breakpoint_chain.back ();
 }
 
 /* Initialize loc->function_name.  */
@@ -12372,15 +12365,7 @@ delete_breakpoint (struct breakpoint *bpt)
   if (bpt->number)
     gdb::observers::breakpoint_deleted.notify (bpt);
 
-  if (breakpoint_chain == bpt)
-    breakpoint_chain = bpt->next;
-
-  for (breakpoint *b : all_breakpoints ())
-    if (b->next == bpt)
-      {
-       b->next = bpt->next;
-       break;
-      }
+  breakpoint_chain.erase (breakpoint_chain.iterator_to (*bpt));
 
   /* Be sure no bpstat's are pointing at the breakpoint after it's
      been freed.  */
@@ -14442,7 +14427,6 @@ _initialize_breakpoint ()
   gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change,
                                         "breakpoint");
 
-  breakpoint_chain = 0;
   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
      before a breakpoint is set.  */
   breakpoint_count = 0;
index 450c0c7e59af7507164fbd803e20f74d31ed88a0..6104f5486aa57684a05904ab09f27780792a13ac 100644 (file)
@@ -616,7 +616,7 @@ using bp_location_range = iterator_range<bp_location_iterator>;
 
 /* Abstract base class representing all kinds of breakpoints.  */
 
-struct breakpoint
+struct breakpoint : public intrusive_list_node<breakpoint>
 {
   breakpoint (struct gdbarch *gdbarch_, enum bptype bptype,
              bool temp = true, const char *cond_string = nullptr);
@@ -791,7 +791,6 @@ struct breakpoint
     /* Nothing to do.  */
   }
 
-  breakpoint *next = NULL;
   /* Type of breakpoint.  */
   bptype type = bp_none;
   /* Zero means disabled; remember the info but don't break here.  */
@@ -1894,11 +1893,15 @@ public:
 
 /* Breakpoint linked list iterator.  */
 
-using breakpoint_iterator = next_iterator<breakpoint>;
+using breakpoint_list = intrusive_list<breakpoint>;
+
+using breakpoint_iterator = breakpoint_list::iterator;
+
+using breakpoint_pointer_iterator = reference_to_pointer_iterator<breakpoint_iterator>;
 
 /* Breakpoint linked list range.  */
 
-using breakpoint_range = iterator_range<breakpoint_iterator>;
+using breakpoint_range = iterator_range<breakpoint_pointer_iterator>;
 
 /* Return a range to iterate over all breakpoints.  */
 
@@ -1925,7 +1928,7 @@ struct tracepoint_filter
 /* Breakpoint linked list iterator, filtering to only keep tracepoints.  */
 
 using tracepoint_iterator
-  = filtered_iterator<breakpoint_iterator, tracepoint_filter>;
+  = filtered_iterator<breakpoint_pointer_iterator, tracepoint_filter>;
 
 /* Breakpoint linked list range, filtering to only keep tracepoints.  */