public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/4] gdb: used scoped_restore_frame in update_watchpoint
Date: Wed,  5 Oct 2022 10:32:50 +0100	[thread overview]
Message-ID: <56902b3d9d93987a9d3573eb80a0a5afbe86be0a.1664962269.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1664962269.git.aburgess@redhat.com>

I was doing some int to bool cleanup in update_watchpoint, and I
noticed a manual version of scoped_restore_selected_frame.  As always
when these things are done manually, there is the chance that, in an
error case, we might leave the wrong frame selected.

This commit updates things to use scoped_restore_selected_frame, and
also converts a local variable from int to bool.

The only user visible change after this commit is in the case where
update_watchpoint throws an error - we should now correctly restore
the previously selected frame.  Otherwise, this commit should be
invisible to the user.
---
 gdb/breakpoint.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 6e1a15e4f1b..57281a199b0 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1926,9 +1926,7 @@ add_dummy_location (struct breakpoint *b,
 static void
 update_watchpoint (struct watchpoint *b, int reparse)
 {
-  int within_current_scope;
-  struct frame_id saved_frame_id;
-  int frame_saved;
+  bool within_current_scope;
 
   /* 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
@@ -1938,12 +1936,12 @@ update_watchpoint (struct watchpoint *b, int reparse)
 
   if (b->disposition == disp_del_at_next_stop)
     return;
- 
-  frame_saved = 0;
+
+  gdb::optional<scoped_restore_selected_frame> restore_frame;
 
   /* Determine if the watchpoint is within scope.  */
   if (b->exp_valid_block == NULL)
-    within_current_scope = 1;
+    within_current_scope = true;
   else
     {
       struct frame_info *fi = get_current_frame ();
@@ -1962,8 +1960,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
       /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
 	 took a frame parameter, so that we didn't have to change the
 	 selected frame.  */
-      frame_saved = 1;
-      saved_frame_id = get_frame_id (get_selected_frame (NULL));
+      restore_frame.emplace ();
 
       fi = frame_find_by_id (b->watchpoint_frame);
       within_current_scope = (fi != NULL);
@@ -2229,10 +2226,6 @@ in which its expression is valid.\n"),
 		  b->number);
       watchpoint_del_at_next_stop (b);
     }
-
-  /* Restore the selected frame.  */
-  if (frame_saved)
-    select_frame (frame_find_by_id (saved_frame_id));
 }
 
 
-- 
2.25.4


  parent reply	other threads:[~2022-10-05  9:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05  9:32 [PATCH 0/4] Const args, int->bool, and scoped_restore in breakpoint.c Andrew Burgess
2022-10-05  9:32 ` [PATCH 1/4] gdb: make some bp_location arguments const " Andrew Burgess
2022-10-18 13:46   ` Bruno Larsen
2022-10-05  9:32 ` Andrew Burgess [this message]
2022-10-05  9:32 ` [PATCH 3/4] gdb: make use of scoped_restore in unduplicated_should_be_inserted Andrew Burgess
2022-10-05  9:32 ` [PATCH 4/4] gdb: some int to bool conversion in breakpoint.c Andrew Burgess
2022-10-19 13:07 ` [PATCHv2 0/4] Const args, int->bool, and scoped_restore " Andrew Burgess
2022-10-19 13:07   ` [PATCHv2 1/4] gdb: make some bp_location arguments const " Andrew Burgess
2022-10-19 13:07   ` [PATCHv2 2/4] gdb: used scoped_restore_frame in update_watchpoint Andrew Burgess
2022-10-19 13:07   ` [PATCHv2 3/4] gdb: make use of scoped_restore in unduplicated_should_be_inserted Andrew Burgess
2022-10-19 13:07   ` [PATCHv2 4/4] gdb: some int to bool conversion in breakpoint.c Andrew Burgess
2022-10-19 20:03     ` Simon Marchi
2022-10-20 15:48       ` Andrew Burgess

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=56902b3d9d93987a9d3573eb80a0a5afbe86be0a.1664962269.git.aburgess@redhat.com \
    --to=aburgess@redhat.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).