From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 2964638582B6 for ; Wed, 19 Oct 2022 13:07:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2964638582B6 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-523-ZAKuCzF8PW6pHhSRQVmYHg-1; Wed, 19 Oct 2022 09:07:20 -0400 X-MC-Unique: ZAKuCzF8PW6pHhSRQVmYHg-1 Received: by mail-qv1-f71.google.com with SMTP id jn13-20020ad45ded000000b004b1d055fbc7so10518332qvb.2 for ; Wed, 19 Oct 2022 06:07:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a1Byd/DwERe/5UmieLYu7NPPu2hgoMvKDRTAEnCKIao=; b=T1Flh8GKBCor/Ftxa37xVLYqLXf2skDV2OVazl1PkFKKymzp3UA/+t7sKUxEh3T+ay /uZQyZ472CXTSVWbYAu5yXBVCOR0ISuCH78GhkxSFpWJajNjgn52901S9InB9nnA/i5v R+FuigjjcLs89FrjGudRfuKIDOBz/eMm0InOgS8Atktq5A0dBGii+9CASmRDIQHKKYCu G1HyRr8G3IqoZk8apiFI7zyHCb0XLkiVA6YAQNfzPYXWNjflny2wcGq+PuCt0sH0XTKX mIgr7LCI0b758wBPLeh9e5aXSURSdr31/AlxFPn+njfnVD2nEwHNw5qih7+wYn/DGjga SD9Q== X-Gm-Message-State: ACrzQf3FFH7mciW5ptMTpt0v0Wtti/NTxvVDQjY/rI9cgUqDCEixBRR8 asU+YnTYKz4DPcuBINgG2/aYrVFasl74RbQIwTM2Lo+Pvi+kGWa3i6mPF6iAaZe+B+bWP8zgqPd 7nEtOkVg14/9Yl+zNSZgvBZobLedXxNWU7NOHNFr/VIvdC7f2szYu+GUalNeF3umoWzC3DS5hrw == X-Received: by 2002:ac8:5b0e:0:b0:399:cbf2:4acc with SMTP id m14-20020ac85b0e000000b00399cbf24accmr6216431qtw.208.1666184839627; Wed, 19 Oct 2022 06:07:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5u3VF6pC5wAC5fIdMGT8AFrRI8jU/ckbFrWhLGOmlJ2W8EeKlC+jVfyZgb1hw5t5/XuMHPTA== X-Received: by 2002:ac8:5b0e:0:b0:399:cbf2:4acc with SMTP id m14-20020ac85b0e000000b00399cbf24accmr6216399qtw.208.1666184839334; Wed, 19 Oct 2022 06:07:19 -0700 (PDT) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id bq12-20020a05620a468c00b006ee957439f2sm4722133qkb.133.2022.10.19.06.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 06:07:19 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCHv2 2/4] gdb: used scoped_restore_frame in update_watchpoint Date: Wed, 19 Oct 2022 14:07:08 +0100 Message-Id: <46bfcd04d1f1361cd2e669546afe8f9143ff7a4b.1666184729.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Oct 2022 13:07:25 -0000 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 e80a46cb01e..3ddf025acca 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; /* 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 reparse) if (b->disposition == disp_del_at_next_stop) return; - - frame_saved = 0; + + gdb::optional restore_frame; /* Determine if the watchpoint is within scope. */ if (b->exp_valid_block == NULL) - within_current_scope = 1; + within_current_scope = true; else { frame_info_ptr fi = 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 = 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); @@ -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)); } -- 2.25.4