aboutsummaryrefslogtreecommitdiff
path: root/gdb/breakpoint.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-12-11 09:21:53 -0700
committerTom Tromey <tom@tromey.com>2020-12-11 09:21:55 -0700
commitb6433ede0708af00be520abdf9209cd776aab2e2 (patch)
treeccb678ca9bc5bdff0664d7c714c3f6ad7a6d00bd /gdb/breakpoint.h
parentbfcb9db853c41ffff74c77d338b8b1378781aa0e (diff)
downloadgdb-b6433ede0708af00be520abdf9209cd776aab2e2.zip
gdb-b6433ede0708af00be520abdf9209cd776aab2e2.tar.gz
gdb-b6433ede0708af00be520abdf9209cd776aab2e2.tar.bz2
Make bp_location derive from refcounted_object
This changes bp_location to derive from refcounted_object, introduces a ref_ptr specialization for this type, and then changes bpstats::bp_location_at to use that specialization. This removes some manual reference counting and simplifies the code. gdb/ChangeLog 2020-12-11 Tom Tromey <tom@tromey.com> * inline-frame.c (stopped_by_user_bp_inline_frame): Update. * ada-lang.c (check_status_exception): Update. * breakpoint.c (free_bp_location): Remove. (decref_bp_location): Use bp_location_ref_policy. (bpstats::bpstats): Don't call incref_bp_location. (bpstats::~bpstats): Remove. (bpstats::bpstats): Update. (bpstat_check_watchpoint, bpstat_check_breakpoint_conditions) (bp_location::bp_location): Update. (incref_bp_location): Remove. (bkpt_print_it): Update. * breakpoint.h (class bp_location): Derive from refcounted_object. (struct bpstats): Remove destructor. <bp_location_at>: Now a bp_location_ref_ptr. <refc>: Remove. (bp_location_ref_ptr): New typedef. (struct bp_location_ref_policy): New.
Diffstat (limited to 'gdb/breakpoint.h')
-rw-r--r--gdb/breakpoint.h30
1 files changed, 24 insertions, 6 deletions
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 4a65dd2..2859552 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -29,6 +29,7 @@
#include <vector>
#include "gdbsupport/array-view.h"
#include "gdbsupport/function-view.h"
+#include "gdbsupport/refcounted-object.h"
#include "cli/cli-script.h"
struct block;
@@ -311,7 +312,7 @@ enum bp_loc_type
bp_loc_other /* Miscellaneous... */
};
-class bp_location
+class bp_location : public refcounted_object
{
public:
bp_location () = default;
@@ -329,9 +330,6 @@ public:
the same parent breakpoint. */
bp_location *next = NULL;
- /* The reference count. */
- int refc = 0;
-
/* Type of this breakpoint location. */
bp_loc_type loc_type {};
@@ -510,6 +508,27 @@ public:
const struct objfile *objfile = NULL;
};
+/* A policy class for bp_location reference counting. */
+struct bp_location_ref_policy
+{
+ static void incref (bp_location *loc)
+ {
+ loc->incref ();
+ }
+
+ static void decref (bp_location *loc)
+ {
+ gdb_assert (loc->refcount () > 0);
+ loc->decref ();
+ if (loc->refcount () == 0)
+ delete loc;
+ }
+};
+
+/* A gdb::ref_ptr that has been specialized for bp_location. */
+typedef gdb::ref_ptr<bp_location, bp_location_ref_policy>
+ bp_location_ref_ptr;
+
/* The possible return values for print_bpstat, print_it_normal,
print_it_done, print_it_noop. */
enum print_stop_action
@@ -1130,7 +1149,6 @@ struct bpstats
{
bpstats ();
bpstats (struct bp_location *bl, bpstat **bs_link_pointer);
- ~bpstats ();
bpstats (const bpstats &);
bpstats &operator= (const bpstats &) = delete;
@@ -1155,7 +1173,7 @@ struct bpstats
What this means is that we should not (in most cases) follow
the `bpstat->bp_location->owner' link, but instead use the
`breakpoint_at' field below. */
- struct bp_location *bp_location_at;
+ bp_location_ref_ptr bp_location_at;
/* Breakpoint that caused the stop. This is nullified if the
breakpoint ends up being deleted. See comments on