&& !is_executing (inferior_ptid)));
}
+/* Set watchpoint B to disp_del_at_next_stop, even including its possible
+ associated bp_watchpoint_scope breakpoint. */
+
+static void
+watchpoint_del_at_next_stop (struct breakpoint *b)
+{
+ gdb_assert (is_watchpoint (b));
+
+ if (b->related_breakpoint != b)
+ {
+ gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
+ gdb_assert (b->related_breakpoint->related_breakpoint == b);
+ b->related_breakpoint->disposition = disp_del_at_next_stop;
+ b->related_breakpoint->related_breakpoint = b->related_breakpoint;
+ b->related_breakpoint = b;
+ }
+ b->disposition = disp_del_at_next_stop;
+}
+
/* Assuming that B is a watchpoint:
- Reparse watchpoint expression, if REPARSE is non-zero
- Evaluate expression and store the result in B->val
struct frame_id saved_frame_id;
int frame_saved;
+ gdb_assert (is_watchpoint (b));
+
/* If this is a local watchpoint, we only want to check if the
watchpoint frame is in scope if the current thread is the thread
that was used to create the watchpoint. */
Watchpoint %d deleted because the program has left the block\n\
in which its expression is valid.\n"),
b->number);
- if (b->related_breakpoint)
- {
- b->related_breakpoint->disposition = disp_del_at_next_stop;
- b->related_breakpoint->related_breakpoint = NULL;
- b->related_breakpoint= NULL;
- }
- b->disposition = disp_del_at_next_stop;
+ watchpoint_del_at_next_stop (b);
}
/* Restore the selected frame. */
gdb_assert (bs->breakpoint_at != NULL);
b = bs->breakpoint_at;
+ gdb_assert (is_watchpoint (b));
+
/* If this is a local watchpoint, we only want to check if the
watchpoint frame is in scope if the current thread is the thread
that was used to create the watchpoint. */
" deleted because the program has left the block in\n\
which its expression is valid.\n");
- if (b->related_breakpoint)
- {
- b->related_breakpoint->disposition = disp_del_at_next_stop;
- b->related_breakpoint->related_breakpoint = NULL;
- b->related_breakpoint = NULL;
- }
- b->disposition = disp_del_at_next_stop;
+ watchpoint_del_at_next_stop (b);
return WP_DELETED;
}
case 0:
/* Error from catch_errors. */
printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
- if (b->related_breakpoint)
- b->related_breakpoint->disposition = disp_del_at_next_stop;
- b->disposition = disp_del_at_next_stop;
+ watchpoint_del_at_next_stop (b);
/* We've already printed what needs to be printed. */
bs->print_it = print_it_done;
break;
watchpoint as triggered so that we will handle the
out-of-scope event. We'll get to the watchpoint next
iteration. */
- if (b->type == bp_watchpoint_scope)
+ if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
}
}
b->ops = NULL;
b->condition_not_parsed = 0;
b->py_bp_object = NULL;
+ b->related_breakpoint = b;
/* Add this breakpoint to the end of the chain so that a list of
breakpoints will come out in order of increasing numbers. */
/* At least avoid this stale reference until the reference counting
of breakpoints gets resolved. */
- if (bpt->related_breakpoint != NULL)
+ if (bpt->related_breakpoint != bpt)
{
- gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
- bpt->related_breakpoint->disposition = disp_del_at_next_stop;
- bpt->related_breakpoint->related_breakpoint = NULL;
- bpt->related_breakpoint = NULL;
+ struct breakpoint *related;
+
+ if (bpt->type == bp_watchpoint_scope)
+ watchpoint_del_at_next_stop (bpt->related_breakpoint);
+ else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
+ watchpoint_del_at_next_stop (bpt);
+
+ /* Unlink bpt from the bpt->related_breakpoint ring. */
+ for (related = bpt; related->related_breakpoint != bpt;
+ related = related->related_breakpoint);
+ related->related_breakpoint = bpt->related_breakpoint;
+ bpt->related_breakpoint = bpt;
}
observer_notify_breakpoint_deleted (bpt->number);
ALL_BREAKPOINTS_SAFE (b, tmp)
if (b->number == num)
{
- struct breakpoint *related_breakpoint = b->related_breakpoint;
+ struct breakpoint *related_breakpoint;
+
match = 1;
- function (b, data);
- if (related_breakpoint)
- function (related_breakpoint, data);
+ related_breakpoint = b;
+ do
+ {
+ struct breakpoint *next_related_b;
+
+ /* FUNCTION can be also delete_breakpoint. */
+ next_related_b = related_breakpoint->related_breakpoint;
+ function (related_breakpoint, data);
+
+ /* For delete_breakpoint of the last entry of the ring we
+ were traversing we would never get back to B. */
+ if (next_related_b == related_breakpoint)
+ break;
+ related_breakpoint = next_related_b;
+ }
+ while (related_breakpoint != b);
break;
}
if (match == 0)
--- /dev/null
+# Copyright 2010, 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set testfile "watchpoint-delete"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+ untested ${testfile}.exp
+ return -1
+}
+
+# It is more compatible this way.
+gdb_test_no_output "set can-use-hw-watchpoints 0"
+
+if ![runto_main] {
+ return -1
+}
+
+# Ensure there is a parent frame to create related bp_watchpoint_scope.
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here" ".* break-here .*"
+
+gdb_test "watch x" {Watchpoint [0-9]+: x}
+
+gdb_test_no_output {delete $bpnum}