From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/4] Remove ALL_BREAKPOINTS_SAFE
Date: Sun, 16 Apr 2023 10:28:30 -0600 [thread overview]
Message-ID: <20230416-remove-all-macros-v1-4-f118956faafe@tromey.com> (raw)
In-Reply-To: <20230416-remove-all-macros-v1-0-f118956faafe@tromey.com>
There's just a single remaining use of the ALL_BREAKPOINTS_SAFE macro;
this patch replaces it with a for-each and an explicit temporary
variable.
---
gdb/breakpoint.c | 134 ++++++++++++++++++++++++++-----------------------------
1 file changed, 63 insertions(+), 71 deletions(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 46287da5f87..b1460b51b0c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -610,15 +610,6 @@ static int overlay_events_enabled;
/* See description in breakpoint.h. */
bool target_exact_watchpoints = false;
-/* Walk the following statement or block through all breakpoints.
- ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
- current breakpoint. */
-
-#define ALL_BREAKPOINTS_SAFE(B,TMP) \
- for (B = breakpoint_chain; \
- B ? (TMP=B->next, 1): 0; \
- B = TMP)
-
/* Chains of all breakpoints defined. */
static struct breakpoint *breakpoint_chain;
@@ -7616,72 +7607,73 @@ set_longjmp_breakpoint_for_call_dummy (void)
void
check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
{
- struct breakpoint *b, *b_tmp;
+ for (struct breakpoint *b : all_breakpoints_safe ())
+ {
+ struct breakpoint *b_tmp = b->next;
+ if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
+ {
+ struct breakpoint *dummy_b = b->related_breakpoint;
- ALL_BREAKPOINTS_SAFE (b, b_tmp)
- if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
- {
- struct breakpoint *dummy_b = b->related_breakpoint;
-
- /* Find the bp_call_dummy breakpoint in the list of breakpoints
- chained off b->related_breakpoint. */
- while (dummy_b != b && dummy_b->type != bp_call_dummy)
- dummy_b = dummy_b->related_breakpoint;
-
- /* If there was no bp_call_dummy breakpoint then there's nothing
- more to do. Or, if the dummy frame associated with the
- bp_call_dummy is still on the stack then we need to leave this
- bp_call_dummy in place. */
- if (dummy_b->type != bp_call_dummy
- || frame_find_by_id (dummy_b->frame_id) != NULL)
- continue;
+ /* Find the bp_call_dummy breakpoint in the list of breakpoints
+ chained off b->related_breakpoint. */
+ while (dummy_b != b && dummy_b->type != bp_call_dummy)
+ dummy_b = dummy_b->related_breakpoint;
- /* We didn't find the dummy frame on the stack, this could be
- because we have longjmp'd to a stack frame that is previous to
- the dummy frame, or it could be because the stack unwind is
- broken at some point between the longjmp frame and the dummy
- frame.
-
- Next we figure out why the stack unwind stopped. If it looks
- like the unwind is complete then we assume the dummy frame has
- been jumped over, however, if the unwind stopped for an
- unexpected reason then we assume the stack unwind is currently
- broken, and that we will (eventually) return to the dummy
- frame.
-
- It might be tempting to consider using frame_id_inner here, but
- that is not safe. There is no guarantee that the stack frames
- we are looking at here are even on the same stack as the
- original dummy frame, hence frame_id_inner can't be used. See
- the comments on frame_id_inner for more details. */
- bool unwind_finished_unexpectedly = false;
- for (frame_info_ptr fi = get_current_frame (); fi != nullptr; )
- {
- frame_info_ptr prev = get_prev_frame (fi);
- if (prev == nullptr)
- {
- /* FI is the last stack frame. Why did this frame not
- unwind further? */
- auto stop_reason = get_frame_unwind_stop_reason (fi);
- if (stop_reason != UNWIND_NO_REASON
- && stop_reason != UNWIND_OUTERMOST)
- unwind_finished_unexpectedly = true;
- }
- fi = prev;
- }
- if (unwind_finished_unexpectedly)
- continue;
+ /* If there was no bp_call_dummy breakpoint then there's nothing
+ more to do. Or, if the dummy frame associated with the
+ bp_call_dummy is still on the stack then we need to leave this
+ bp_call_dummy in place. */
+ if (dummy_b->type != bp_call_dummy
+ || frame_find_by_id (dummy_b->frame_id) != NULL)
+ continue;
- dummy_frame_discard (dummy_b->frame_id, tp);
+ /* We didn't find the dummy frame on the stack, this could be
+ because we have longjmp'd to a stack frame that is previous to
+ the dummy frame, or it could be because the stack unwind is
+ broken at some point between the longjmp frame and the dummy
+ frame.
+
+ Next we figure out why the stack unwind stopped. If it looks
+ like the unwind is complete then we assume the dummy frame has
+ been jumped over, however, if the unwind stopped for an
+ unexpected reason then we assume the stack unwind is currently
+ broken, and that we will (eventually) return to the dummy
+ frame.
+
+ It might be tempting to consider using frame_id_inner here, but
+ that is not safe. There is no guarantee that the stack frames
+ we are looking at here are even on the same stack as the
+ original dummy frame, hence frame_id_inner can't be used. See
+ the comments on frame_id_inner for more details. */
+ bool unwind_finished_unexpectedly = false;
+ for (frame_info_ptr fi = get_current_frame (); fi != nullptr; )
+ {
+ frame_info_ptr prev = get_prev_frame (fi);
+ if (prev == nullptr)
+ {
+ /* FI is the last stack frame. Why did this frame not
+ unwind further? */
+ auto stop_reason = get_frame_unwind_stop_reason (fi);
+ if (stop_reason != UNWIND_NO_REASON
+ && stop_reason != UNWIND_OUTERMOST)
+ unwind_finished_unexpectedly = true;
+ }
+ fi = prev;
+ }
+ if (unwind_finished_unexpectedly)
+ continue;
- while (b->related_breakpoint != b)
- {
- if (b_tmp == b->related_breakpoint)
- b_tmp = b->related_breakpoint->next;
- delete_breakpoint (b->related_breakpoint);
- }
- delete_breakpoint (b);
- }
+ dummy_frame_discard (dummy_b->frame_id, tp);
+
+ while (b->related_breakpoint != b)
+ {
+ if (b_tmp == b->related_breakpoint)
+ b_tmp = b->related_breakpoint->next;
+ delete_breakpoint (b->related_breakpoint);
+ }
+ delete_breakpoint (b);
+ }
+ }
}
void
--
2.39.2
next prev parent reply other threads:[~2023-04-16 16:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-16 16:28 [PATCH 0/4] Remove remaining ALL_ iterator macros Tom Tromey
2023-04-16 16:28 ` [PATCH 1/4] Rename objfile::sections Tom Tromey
2023-04-17 17:57 ` Keith Seitz
2023-05-07 18:43 ` Tom Tromey
2023-04-16 16:28 ` [PATCH 2/4] Remove ALL_OBJFILE_OSECTIONS Tom Tromey
2023-04-16 16:28 ` [PATCH 3/4] Remove ALL_DICT_SYMBOLS Tom Tromey
2023-04-16 16:28 ` Tom Tromey [this message]
2023-05-08 2:24 ` [PATCH 4/4] Remove ALL_BREAKPOINTS_SAFE Simon Marchi
2023-05-08 14:59 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230416-remove-all-macros-v1-4-f118956faafe@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).