From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 7D70C3850219; Thu, 20 Oct 2022 15:45:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D70C3850219 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666280747; bh=8Jd9rL5R5UixiUynKnVTNQ0/iiA8IfhjTqWEE12WOSw=; h=From:To:Subject:Date:From; b=e13EQjWcJz8HcyoLmaAGqs1zln4i6dyfcx0/btQ78q5nYlXH3ccVsIsdeTsJLh5ZN o3Ri25461k9/jgyWyuSU6p5d4X1fmq5Ubr1Rh7fWArML/Bkf9eaQLSrsqxB/Nx6YzQ 9BCVl5kc5rCck3g8ZWYhmzndfSIMPszBtrsILnK0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: used scoped_restore_frame in update_watchpoint X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: b2ff9ed3050491f72529beeea14859abda3afb4a X-Git-Newrev: 705b6305edc025c31606de16623a549697891193 Message-Id: <20221020154547.7D70C3850219@sourceware.org> Date: Thu, 20 Oct 2022 15:45:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D705b6305edc0= 25c31606de16623a549697891193 commit 705b6305edc025c31606de16623a549697891193 Author: Andrew Burgess Date: Tue Oct 4 14:22:25 2022 +0100 gdb: used scoped_restore_frame in update_watchpoint =20 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. =20 This commit updates things to use scoped_restore_selected_frame, and also converts a local variable from int to bool. =20 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. =20 Approved-By: Simon Marchi Diff: --- gdb/breakpoint.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 8c5c5f5569e..84eeccd0cd7 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1924,9 +1924,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; =20 /* 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 @@ -1936,12 +1934,12 @@ update_watchpoint (struct watchpoint *b, int repars= e) =20 if (b->disposition =3D=3D disp_del_at_next_stop) return; -=20 - frame_saved =3D 0; + + gdb::optional restore_frame; =20 /* Determine if the watchpoint is within scope. */ if (b->exp_valid_block =3D=3D NULL) - within_current_scope =3D 1; + within_current_scope =3D true; else { frame_info_ptr fi =3D get_current_frame (); @@ -1960,8 +1958,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 =3D 1; - saved_frame_id =3D get_frame_id (get_selected_frame (NULL)); + restore_frame.emplace (); =20 fi =3D frame_find_by_id (b->watchpoint_frame); within_current_scope =3D (fi !=3D NULL); @@ -2227,10 +2224,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)); }