From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uLO0B7Wp9mPWHTsAWB0awg (envelope-from ) for ; Wed, 22 Feb 2023 18:48:05 -0500 Received: by simark.ca (Postfix, from userid 112) id 1B1C41E222; Wed, 22 Feb 2023 18:48:05 -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=RkTHB+Di; 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=ham 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 DBEA41E221 for ; Wed, 22 Feb 2023 18:48:03 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7AF8C3858288 for ; Wed, 22 Feb 2023 23:48:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AF8C3858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677109683; bh=M8NEymySLaJDkkel35MlSOiDA7CNXblNgBbCCZpCshU=; 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=RkTHB+DiQVb7uXJcDfIbr1uUE2ZM1/a6MgkXGjIAy5B/QrWJrs5r5vZ6EhYBuQDo3 jC5wYjlRuoisLmLJlxbz9mroz7cJ+i7GfDslDpaHX3q44sP3tTq/Sgh4bn1tHU9xML Wgl4vIH4CTCksfVS/plqZWqZjLa9/xa+XXr7fjlE= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 135A53858C83 for ; Wed, 22 Feb 2023 23:47:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 135A53858C83 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-246-h8jGt-mbNvuaroyWiEgApA-1; Wed, 22 Feb 2023 18:47:16 -0500 X-MC-Unique: h8jGt-mbNvuaroyWiEgApA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F74428237C0; Wed, 22 Feb 2023 23:47:16 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.16.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2F78440D9; Wed, 22 Feb 2023 23:47:15 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, Kevin Buettner , Tom de Vries Subject: [PATCH v5 8/8] Forced quit cases handled by resetting sync_quit_force_run Date: Wed, 22 Feb 2023 16:46:13 -0700 Message-Id: <20230222234613.29662-9-kevinb@redhat.com> In-Reply-To: <20230222234613.29662-1-kevinb@redhat.com> References: <20230222234613.29662-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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 Tested-by: Tom de Vries --- gdb/linux-fork.c | 12 ++++++++++++ gdb/tui/tui-io.c | 8 ++++++++ gdb/tui/tui.c | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 61545b859ea..a6e74c0cb52 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -430,6 +430,18 @@ 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. */ + set_force_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 a17cf38a1f2..7752701378e 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -1271,6 +1271,14 @@ 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. */ + set_force_quit_flag (); + return 0; + } catch (const gdb_exception &ex) { /* Just in case, don't ever let an exception escape to readline. diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index cdae9ffe02b..3604194a760 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -122,6 +122,13 @@ tui_rl_switch_mode (int notused1, int notused2) tui_enable (); } } + catch (const gdb_exception_forced_quit &ex) + { + /* Ideally, we'd do a 'throw' here, but as noted above, we can't + do that, so, instead, we'll set the necessary flags so that + a later QUIT check will restart the forced quit. */ + set_force_quit_flag (); + } catch (const gdb_exception &ex) { exception_print (gdb_stderr, ex); -- 2.34.3