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 9A6813858430 for ; Sun, 27 Feb 2022 00:01:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9A6813858430 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-615-yQqNaihaMei7iIRVXBrATw-1; Sat, 26 Feb 2022 19:01:46 -0500 X-MC-Unique: yQqNaihaMei7iIRVXBrATw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1581C501E0; Sun, 27 Feb 2022 00:01:45 +0000 (UTC) Received: from f35-1.lan (unknown [10.2.16.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A6ED5E26C; Sun, 27 Feb 2022 00:01:44 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH v3 7/7] Handle QUIT processing in the scoped_switch_fork_info destructor Date: Sat, 26 Feb 2022 17:00:51 -0700 Message-Id: <20220227000051.3336149-8-kevinb@redhat.com> In-Reply-To: <20220227000051.3336149-1-kevinb@redhat.com> References: <20220227000051.3336149-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_FMBLA_NEWDOM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Sun, 27 Feb 2022 00:01:51 -0000 During my audit of the use of gdb_exception with regard to QUIT processing, I found a try/catch in the scoped_switch_fork_info destructor. Static analysis found this call path from the destructor to maybe_quit(): scoped_switch_fork_info::~scoped_switch_fork_info() -> remove_breakpoints() -> remove_breakpoint(bp_location*) -> remove_breakpoint_1(bp_location*, remove_bp_reason) -> memory_validate_breakpoint(gdbarch*, bp_target_info*) -> target_read_memory(unsigned long, unsigned char*, long) -> target_read(target_ops*, target_object, char const*, unsigned char*, unsigned long, long) -> maybe_quit() Since it's not safe to do a 'throw' from a destructor, we simply call set_quit_flag and, for gdb_exception_forced_quit, also set sync_quit_force_run. This will cause the appropriate exception to be rethrown at the next QUIT check. Thanks to Pedro Alves for suggesting this idea. --- gdb/linux-fork.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 4baab3c80c7..b8adb7396ba 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -430,6 +430,19 @@ class scoped_switch_fork_info fork_load_infrun_state (m_oldfp); insert_breakpoints (); } + catch (const gdb_exception_quit &ex) + { + /* We can't throw from a destructor, so re-set the quit flag + for later QUIT checking. */ + set_quit_flag (); + } + catch (const gdb_exception_forced_quit &ex) + { + /* Like above, but (eventually) cause GDB to terminate by + setting sync_quit_force_run. */ + sync_quit_force_run = 1; + set_quit_flag (); + } catch (const gdb_exception &ex) { warning (_("Couldn't restore checkpoint state in %s: %s"), -- 2.35.1