From patchwork Thu Jan 12 01:56:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62991 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 80BD5386EC0C for ; Thu, 12 Jan 2023 01:58:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80BD5386EC0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488694; bh=+gtDvXIHCjc/sJCNM5sdRlZrnhgZH2jKIShhFVktVsM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vLz14GUnqyRzShdIVf1/SLWpd1VxRjI4mCmdZ6IqgAWDysHs1duY0YsKY7wVqh/Q1 SgSlfIVDUePz1a7rFygQdgpfNk1PNJY3Y8ZkQxor4kESEMY/PgfHxBRGVwPDQoDclF VbZmphy790O8GRNW5RT6EAMEUczENKS0J4+P+Qv8= 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 924BA3854178 for ; Thu, 12 Jan 2023 01:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 924BA3854178 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-427-7KdTrZt2OBGYN8DkzLtNjA-1; Wed, 11 Jan 2023 20:57:18 -0500 X-MC-Unique: 7KdTrZt2OBGYN8DkzLtNjA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CAF513806630; Thu, 12 Jan 2023 01:57:17 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 256DB492C14; Thu, 12 Jan 2023 01:57:17 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 8/8] Forced quit cases handled by resetting sync_quit_force_run Date: Wed, 11 Jan 2023 18:56:30 -0700 Message-Id: <20230112015630.32999-9-kevinb@redhat.com> In-Reply-To: <20230112015630.32999-1-kevinb@redhat.com> References: <20230112015630.32999-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.0 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-Patchwork-Original-From: Kevin Buettner via Gdb-patches From: Kevin Buettner Reply-To: Kevin Buettner Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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. Another case is the try / catch in tui_getc() in tui-io.c. The existing catch swallows the exception. I've added a catch for 'gdb_exception_forced_quit', which also swallows the exception, but also sets sync_quit_force_run and calls set_quit_flag in order to restart forced quit processing at the next QUIT check. This is required because it isn't safe to throw into/through readline. Thanks to Pedro Alves for suggesting this idea. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/linux-fork.c | 13 +++++++++++++ gdb/tui/tui-io.c | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 61545b859ea..fc2f00d0766 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"), diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 2f39e34df2f..ac3c7296499 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -1275,6 +1275,15 @@ tui_getc (FILE *fp) { return tui_getc_1 (fp); } + catch (const gdb_exception_forced_quit &ex) + { + /* As noted below, it's not safe to let an exception escape + to newline, so, for this case, reset the quit flag for + later QUIT checking. */ + sync_quit_force_run = 1; + set_quit_flag (); + return 0; + } catch (const gdb_exception &ex) { /* Just in case, don't ever let an exception escape to readline.