From patchwork Wed Oct 5 09:32:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58375 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C6D33857367 for ; Wed, 5 Oct 2022 09:33:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C6D33857367 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664962405; bh=EL7zQHA/K3Jq+XO51ihOXX/g7obP8Z0HuSn3V3S3ouM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xVUKkxrlG8ug+YWrJDDXjbSQ8UwTAOzsPl4EQjXS1rvlEMG7g9imyjl0JfkmdgI8Q qT/zt4qt4frFX/pglAkzkS+0iLxgg7DMfYY0tB0s8IodJfjoNxl7p4ZRF9KWniswwi cN24/VURs1tjUInUFlLTY28dtfLDzP0jtISSQCjM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 9F5A03857C4E for ; Wed, 5 Oct 2022 09:33:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9F5A03857C4E Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-665-cLbI5_y_NoGuONMebDg7zQ-1; Wed, 05 Oct 2022 05:32:59 -0400 X-MC-Unique: cLbI5_y_NoGuONMebDg7zQ-1 Received: by mail-wm1-f72.google.com with SMTP id y7-20020a05600c20c700b003bf90b54edbso163563wmm.1 for ; Wed, 05 Oct 2022 02:32:59 -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=EL7zQHA/K3Jq+XO51ihOXX/g7obP8Z0HuSn3V3S3ouM=; b=Va7fuhLzjtXedR4Qgml5SV25E/tisht4S6GqlLBEoelmaJQtrH1NtpFCQmroq3DCUV NgyD7VEv2NgcCRPcUcBM9FTt+kZabrjkg3afJ8GvU8OezRFyIy5o0+i7ZtjA5hCJrzkD PvJhMDMnvb9wxL0zQC6mcIeMGdAYoBDHUZ0JRS/PEsruwLEI3iwG+Xv/+w2j/zbtwqDO whljq7Y2wxsKNXSbAPV0pKgs4SoyB5q8SbWRWQdoLZxQ0xPapOFNgLuBFrr2em2mRe2O d1PuYfLQyG3O/MAU7kihJy7Q7NVuijGPhBs63wdiIaCPYKTgm5mDU0cbC5akT9c0WOo8 jjRA== X-Gm-Message-State: ACrzQf1u3t25Me/O5oyRDkZSJCrknSkZhd55Y11CqG8LpFkO6/B+wKvc vt2hsqR83Ml2cAPNRY3URufEbznPSyzw+e+mgRzBcr0RcOOAVGfLcTtO+G2ctQQ4txqHiRHqpxc GuTOvJNCRuutCmFY6nTHYJZLCV4blETAIDoRl/HB+oiMq2sWUE32XT9DOympZ1+63P3ilRxaGQA == X-Received: by 2002:adf:ef4b:0:b0:22e:5c0c:f5f with SMTP id c11-20020adfef4b000000b0022e5c0c0f5fmr2494844wrp.9.1664962377937; Wed, 05 Oct 2022 02:32:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nC6lOTcTvmOethYatXeVEmE7LEwfsjdP5BAFuRB1hIMatPayRdaa/QiirsusP3MkBFLuSTA== X-Received: by 2002:adf:ef4b:0:b0:22e:5c0c:f5f with SMTP id c11-20020adfef4b000000b0022e5c0c0f5fmr2494825wrp.9.1664962377681; Wed, 05 Oct 2022 02:32:57 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id a14-20020adfed0e000000b0022ae4f8395dsm14413378wro.96.2022.10.05.02.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 02:32:57 -0700 (PDT) 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 Message-Id: <56902b3d9d93987a9d3573eb80a0a5afbe86be0a.1664962269.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 X-Spam-Status: No, score=-12.2 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_LOW, 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 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)); }