From: Simon Marchi Date: Tue, 9 May 2023 14:04:23 +0000 (-0400) Subject: gdb: link breakpoints with intrusive_list X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e2a1578868a2a681fbafd6c56b694cfe9410b8d4;p=binutils-gdb.git gdb: link breakpoints with intrusive_list Change-Id: I043d8d6f3dd864d80d5088f6ffc2c098337249ea Reviewed-By: Andrew Burgess --- diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 0cdf5a7158b..8c613072543 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -614,14 +614,16 @@ bool target_exact_watchpoints = false; /* Chains of all breakpoints defined. */ -static struct breakpoint *breakpoint_chain; +static intrusive_list 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 &&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; diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 450c0c7e59a..6104f5486aa 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -616,7 +616,7 @@ using bp_location_range = iterator_range; /* Abstract base class representing all kinds of breakpoints. */ -struct breakpoint +struct breakpoint : public intrusive_list_node { 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; +using breakpoint_list = intrusive_list; + +using breakpoint_iterator = breakpoint_list::iterator; + +using breakpoint_pointer_iterator = reference_to_pointer_iterator; /* Breakpoint linked list range. */ -using breakpoint_range = iterator_range; +using breakpoint_range = iterator_range; /* 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; + = filtered_iterator; /* Breakpoint linked list range, filtering to only keep tracepoints. */