aboutsummaryrefslogtreecommitdiff
path: root/gdb/breakpoint.c
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.c
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.c')
-rw-r--r--gdb/breakpoint.c43
1 files changed, 6 insertions, 37 deletions
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index baf80b6..933fe90 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -172,8 +172,6 @@ static int hw_watchpoint_used_count_others (struct breakpoint *except,
static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
int count);
-static void free_bp_location (struct bp_location *loc);
-static void incref_bp_location (struct bp_location *loc);
static void decref_bp_location (struct bp_location **loc);
static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
@@ -4242,15 +4240,6 @@ is_catchpoint (struct breakpoint *b)
return (b->type == bp_catchpoint);
}
-/* Frees any storage that is part of a bpstat. Does not walk the
- 'next' chain. */
-
-bpstats::~bpstats ()
-{
- if (bp_location_at != NULL)
- decref_bp_location (&bp_location_at);
-}
-
/* Clear a bpstat so that it says we are not at any breakpoint.
Also free any storage that is part of a bpstat. */
@@ -4283,7 +4272,6 @@ bpstats::bpstats (const bpstats &other)
{
if (other.old_val != NULL)
old_val = release_value (value_copy (other.old_val.get ()));
- incref_bp_location (bp_location_at);
}
/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
@@ -4768,21 +4756,19 @@ breakpoint_cond_eval (expression *exp)
bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer)
: next (NULL),
- bp_location_at (bl),
+ bp_location_at (bp_location_ref_ptr::new_reference (bl)),
breakpoint_at (bl->owner),
commands (NULL),
print (0),
stop (0),
print_it (print_it_normal)
{
- incref_bp_location (bl);
**bs_link_pointer = this;
*bs_link_pointer = &next;
}
bpstats::bpstats ()
: next (NULL),
- bp_location_at (NULL),
breakpoint_at (NULL),
commands (NULL),
print (0),
@@ -5060,7 +5046,7 @@ bpstat_check_watchpoint (bpstat bs)
struct watchpoint *b;
/* BS is built for existing struct breakpoint. */
- bl = bs->bp_location_at;
+ bl = bs->bp_location_at.get ();
gdb_assert (bl != NULL);
b = (struct watchpoint *) bs->breakpoint_at;
gdb_assert (b != NULL);
@@ -5236,7 +5222,7 @@ bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
gdb_assert (bs->stop);
/* BS is built for existing struct breakpoint. */
- bl = bs->bp_location_at;
+ bl = bs->bp_location_at.get ();
gdb_assert (bl != NULL);
b = bs->breakpoint_at;
gdb_assert (b != NULL);
@@ -7101,7 +7087,7 @@ bp_location::bp_location (breakpoint *owner, bp_loc_type type)
|| this->loc_type == bp_loc_hardware_breakpoint)
mark_breakpoint_location_modified (this);
- this->refc = 1;
+ incref ();
}
bp_location::bp_location (breakpoint *owner)
@@ -7118,30 +7104,13 @@ allocate_bp_location (struct breakpoint *bpt)
return bpt->ops->allocate_location (bpt);
}
-static void
-free_bp_location (struct bp_location *loc)
-{
- delete loc;
-}
-
-/* Increment reference count. */
-
-static void
-incref_bp_location (struct bp_location *bl)
-{
- ++bl->refc;
-}
-
/* Decrement reference count. If the reference count reaches 0,
destroy the bp_location. Sets *BLP to NULL. */
static void
decref_bp_location (struct bp_location **blp)
{
- gdb_assert ((*blp)->refc > 0);
-
- if (--(*blp)->refc == 0)
- free_bp_location (*blp);
+ bp_location_ref_policy::decref (*blp);
*blp = NULL;
}
@@ -12680,7 +12649,7 @@ bkpt_print_it (bpstat bs)
gdb_assert (bs->bp_location_at != NULL);
- bl = bs->bp_location_at;
+ bl = bs->bp_location_at.get ();
b = bs->breakpoint_at;
bp_temp = b->disposition == disp_del;