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 924BA3854178 for ; Thu, 12 Jan 2023 01:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 924BA3854178 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673488641; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+gtDvXIHCjc/sJCNM5sdRlZrnhgZH2jKIShhFVktVsM=; b=TEQ7be6/tWYG7QOUFVQ3W1rThjHUscjCPFgrEzXBkEMhrh8zJ6VIHWudQ8rtnFIcNTKEKH h/1q+5p8y7En2XmY7CM5tAq6EJZakTyrL3zqgTpHbKdVwtqWA9QYp8I/06/eVjlHVErh7y Kg4sGoNu2w+lK4qpENMvs44zxXtqg8o= 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) From: Kevin Buettner 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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. -- 2.34.3