From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2O/sEzZpv2PY+hQAWB0awg (envelope-from ) for ; Wed, 11 Jan 2023 20:58:14 -0500 Received: by simark.ca (Postfix, from userid 112) id 4F6AC1E128; Wed, 11 Jan 2023 20:58:14 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=idnYBVig; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 034011E0D3 for ; Wed, 11 Jan 2023 20:58:14 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B627D3846404 for ; Thu, 12 Jan 2023 01:58:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B627D3846404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488690; 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=idnYBVigE6iZbqHof4y0kohNrFY2ApugSfX2BQtnD7ftB1QAziFh7Y0du5uJr89lN lmYh9HT0Sk5eZ73nUvX4np6ivd6fItbHItIgWhn/8OW/02FLbU5TV/2cP9jN9VsTO5 TKuKwBk6lXLw9sDd8MzXgRXNz0ChB11ZHU6TZ6XY= 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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: , From: Kevin Buettner via Gdb-patches Reply-To: Kevin Buettner Errors-To: gdb-patches-bounces+public-inbox=simark.ca@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. -- 2.34.3