From patchwork Thu Jan 12 01:56:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62989 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 F0A5838493D1 for ; Thu, 12 Jan 2023 01:57:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0A5838493D1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488676; bh=S8GaHFkKAQBU5+TZm8XO9dGZxble4ufG970IP+C2P+U=; 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=ODcM7PWyQwSmA2N+mgJX7g7s0oRkmKvROGWoHnZUXVfIbxC5G/DOVvih+5l+/5zCP LMYmw92P0M9T3FVmBwy3h7YRpvJfsj411k8+9ySxksfVkrGQ5DAIRwu/BAH4N8HZQL RQYciupFbmz2pRP+8dEidXZlPuOsUcnjGhbypGAE= 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 C9073385B52E for ; Thu, 12 Jan 2023 01:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9073385B52E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-263-yz-zbe77M7KeAyosMPZU4w-1; Wed, 11 Jan 2023 20:57:03 -0500 X-MC-Unique: yz-zbe77M7KeAyosMPZU4w-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 113A1185A78B; Thu, 12 Jan 2023 01:57:03 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 600CA492C14; Thu, 12 Jan 2023 01:57:02 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 1/8] Introduce gdb_exception_forced_quit Date: Wed, 11 Jan 2023 18:56:23 -0700 Message-Id: <20230112015630.32999-2-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=-10.6 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" This commit adds a new exception 'gdb_exception_forced_quit', reason code 'REASON_FORCED_QUIT', return mask 'RETURN_MASK_FORCED_QUIT', and a wrapper for throwing the exception, throw_forced_quit(). The addition of this exception plus supporting code will allow us to recognize that a SIGTERM has been received by GDB and then propagate recognition of that fact to the upper levels of GDB where it can be correctly handled. At the moment, when GDB receives a SIGTERM, it will attempt to exit via a series of calls from the QUIT checking code. However, before it can exit, it must do various cleanups, such as killing or detaching all inferiors. Should these cleanups be attempted while GDB is executing very low level code, such as reading target memory from within ps_xfer_memory(), it can happen that some of GDB's state is out of sync with regard to the cleanup code's expectations. In the case just mentioned, it's been observed that inferior_ptid and the current_thread_ are not in sync; this triggers an assert / internal error. This commit only introduces the exception plus supporting machinery; changes which use this new exception are in later commits in this series. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdbsupport/common-exceptions.cc | 14 ++++++++++++++ gdbsupport/common-exceptions.h | 22 +++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gdbsupport/common-exceptions.cc b/gdbsupport/common-exceptions.cc index d0dd8081c41..edc1b56181a 100644 --- a/gdbsupport/common-exceptions.cc +++ b/gdbsupport/common-exceptions.cc @@ -184,6 +184,8 @@ throw_exception (gdb_exception &&exception) { if (exception.reason == RETURN_QUIT) throw gdb_exception_quit (std::move (exception)); + else if (exception.reason == RETURN_FORCED_QUIT) + throw gdb_exception_forced_quit (std::move (exception)); else if (exception.reason == RETURN_ERROR) throw gdb_exception_error (std::move (exception)); else @@ -196,6 +198,8 @@ throw_it (enum return_reason reason, enum errors error, const char *fmt, { if (reason == RETURN_QUIT) throw gdb_exception_quit (fmt, ap); + else if (reason == RETURN_FORCED_QUIT) + throw gdb_exception_forced_quit (fmt, ap); else if (reason == RETURN_ERROR) throw gdb_exception_error (error, fmt, ap); else @@ -233,3 +237,13 @@ throw_quit (const char *fmt, ...) throw_vquit (fmt, args); va_end (args); } + +void +throw_forced_quit (const char *fmt, ...) +{ + va_list args; + + va_start (args, fmt); + throw_it (RETURN_FORCED_QUIT, GDB_NO_ERROR, fmt, args); + va_end (args); +} diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h index a2a4f5a3892..f9b59ece736 100644 --- a/gdbsupport/common-exceptions.h +++ b/gdbsupport/common-exceptions.h @@ -32,6 +32,8 @@ enum return_reason { + /* SIGTERM sent to GDB. */ + RETURN_FORCED_QUIT = -3, /* User interrupt. */ RETURN_QUIT = -2, /* Any other error. */ @@ -42,9 +44,10 @@ enum return_reason typedef enum { + RETURN_MASK_FORCED_QUIT = RETURN_MASK (RETURN_FORCED_QUIT), RETURN_MASK_QUIT = RETURN_MASK (RETURN_QUIT), RETURN_MASK_ERROR = RETURN_MASK (RETURN_ERROR), - RETURN_MASK_ALL = (RETURN_MASK_QUIT | RETURN_MASK_ERROR) + RETURN_MASK_ALL = (RETURN_MASK_FORCED_QUIT | RETURN_MASK_QUIT | RETURN_MASK_ERROR) } return_mask; /* Describe all exceptions. */ @@ -294,6 +297,21 @@ struct gdb_exception_quit : public gdb_exception } }; +struct gdb_exception_forced_quit : public gdb_exception +{ + gdb_exception_forced_quit (const char *fmt, va_list ap) + ATTRIBUTE_PRINTF (2, 0) + : gdb_exception (RETURN_FORCED_QUIT, GDB_NO_ERROR, fmt, ap) + { + } + + explicit gdb_exception_forced_quit (gdb_exception &&ex) noexcept + : gdb_exception (std::move (ex)) + { + gdb_assert (ex.reason == RETURN_FORCED_QUIT); + } +}; + /* An exception type that inherits from both std::bad_alloc and a gdb exception. This is necessary because operator new can only throw std::bad_alloc, and OTOH, we want exceptions thrown due to memory @@ -336,5 +354,7 @@ extern void throw_error (enum errors error, const char *fmt, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3); extern void throw_quit (const char *fmt, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); +extern void throw_forced_quit (const char *fmt, ...) + ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); #endif /* COMMON_COMMON_EXCEPTIONS_H */ From patchwork Thu Jan 12 01:56:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62988 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 DE40F385B539 for ; Thu, 12 Jan 2023 01:57:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE40F385B539 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488656; bh=Kx//dLWc+sM0kTFHrJi+0VSIYoB/NlQfx2dSXanEpy0=; 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=WQAbGGgQJzlUUV0gzfQYBbTR34e8MUwrrpYAf4ppIxjH16Y/LFRvvkZ5GjILaNrAV O1irzArVeOdWkUxveQSy4EdtOSU9OpnX9dO7P6VIj+B7gm1RzqaZ4IBNVI28X+tOat H+coOtlTs5VTR7ctVZ4wcOqWw+CBbVwKBSr07J9U= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id A4893385B533 for ; Thu, 12 Jan 2023 01:57:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4893385B533 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-ivwOET4IOTWXgvikIsiXLg-1; Wed, 11 Jan 2023 20:57:06 -0500 X-MC-Unique: ivwOET4IOTWXgvikIsiXLg-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 CAE5A85A588; Thu, 12 Jan 2023 01:57:05 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2340B492C14; Thu, 12 Jan 2023 01:57:05 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 2/8] Handle gdb SIGTERM by throwing / catching gdb_exception_force_quit Date: Wed, 11 Jan 2023 18:56:24 -0700 Message-Id: <20230112015630.32999-3-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=-10.6 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" When a GDB process receives the SIGTERM signal, handle_sigterm() in event-top.c is called. The global variable 'sync_quit_force_run' is set by this signal handler. It does some other things too, but the setting of this global is the important bit for the SIGTERM part of this discussion. GDB will periodically check to see whether a Ctrl-C or SIGTERM has been received. This is performed via use of the QUIT macro in GDB's code. QUIT is defined to invoke maybe_quit(), which will be periodically called during any lengthy operation. This is supposed to ensure that the user won't have to wait too long for a Ctrl-C or SIGTERM to be acted upon. When a Ctrl-C / SIGINT is received, quit_handler() will decide whether to pass the SIGINT onto the inferior or to call quit() which causes gdb_exception_quit to be thrown. This exception (usually) propagates to the top level. Control is then returned to the top level event loop. At the moment, SIGTERM is handled very differently. Instead of throwing an exception, quit_force() is called. This does eventually cause GDB to exit(), but prior to that happening, the inferiors are killed or detached and other target related cleanup occurs. As shown in this discussion between Pedro Alves and myself... https://sourceware.org/pipermail/gdb-patches/2021-July/180802.html https://sourceware.org/pipermail/gdb-patches/2021-July/180902.html https://sourceware.org/pipermail/gdb-patches/2021-July/180903.html ...we found that it is possible for inferior_ptid and current_thread_ to get out of sync. When that happens, the "current_thread_ != nullptr" assertion in inferior_thread() can fail resulting in a GDB internal error. Pedro recommended that we "let the normal quit exception propagate all the way to the top level, and then have the top level call quit_force if sync_quit_force_run is set." However, after the v2 series for this patch set, we tweaked that idea by introducing a new exception for handling SIGTERM. This commit implements the obvious part of Pedro's suggestion: Instead of calling quit_force from quit(), throw_forced_quit() is now called instead. This causes the new exception 'gdb_exception_forced_quit' to be thrown. At the top level, I changed catch_command_errors() and captured_main() to catch gdb_exception_forced_quit and then call quit_force() from the catch block. I also changed start_event_loop() to also catch gdb_exception_forced_quit; while we could also call quit_force() from that catch block, it's sufficient to simply rethrow the exception since it'll be caught by the newly added code in captured_main(). Making these changes fixed the failure / regression that I was seeing for gdb.base/gdb-sigterm.exp when run on a machine with glibc-2.34. However, there are many other paths back to the top level which this test case does not test. I did an audit of all of the try / catch code in GDB in which calls in the try-block might (eventually) call QUIT. I found many cases where gdb_exception_quit and the new gdb_exception_forced_quit will be swallowed. (When using GDB, have you ever hit Ctrl-C and not have it do anything; if so, it could be due to a swallowed gdb_exception_quit in one of the cases I've identified.) The rest of the patches in this series deal with this concern. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/main.c | 12 ++++++++++++ gdb/utils.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gdb/main.c b/gdb/main.c index c04d37a45f9..323d99321c7 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -410,6 +410,10 @@ start_event_loop () { result = gdb_do_one_event (); } + catch (const gdb_exception_forced_quit &ex) + { + throw; + } catch (const gdb_exception &ex) { exception_print (gdb_stderr, ex); @@ -518,6 +522,10 @@ catch_command_errors (catch_command_errors_const_ftype command, if (do_bp_actions) bpstat_do_actions (); } + catch (const gdb_exception_forced_quit &e) + { + quit_force (NULL, 0); + } catch (const gdb_exception &e) { return handle_command_errors (e); @@ -1309,6 +1317,10 @@ captured_main (void *data) { captured_command_loop (); } + catch (const gdb_exception_forced_quit &ex) + { + quit_force (NULL, 0); + } catch (const gdb_exception &ex) { exception_print (gdb_stderr, ex); diff --git a/gdb/utils.c b/gdb/utils.c index 734c5bf7f70..0e126cf103b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -673,7 +673,7 @@ quit (void) if (sync_quit_force_run) { sync_quit_force_run = 0; - quit_force (NULL, 0); + throw_forced_quit ("SIGTERM"); } #ifdef __MSDOS__ From patchwork Thu Jan 12 01:56:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62993 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 AF7D238432E5 for ; Thu, 12 Jan 2023 01:58:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF7D238432E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488706; bh=S+yykIqeAiFmwrAs08Wid6+ckJIj0R7tVUW9nCwuadI=; 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=narM0MFoT8pa9BkADb/QJAquzS6qzcxY/U5Av5AdZtylWGswkbZHmQ7tMCuGKgfDL nKTG8jRftbMkiZsy2Bkh0icd/a/ZbEQJAXX+CA+9Dlvs33213n2T4HOEBmfkDSlMwG DM8CSbHw4dq+G5VrVo8CWdo33CXluy+QGLar94Is= 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 71468385B52B for ; Thu, 12 Jan 2023 01:57:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71468385B52B 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-27-7lwStyd7Nc6b9vO-lIiUBA-1; Wed, 11 Jan 2023 20:57:08 -0500 X-MC-Unique: 7lwStyd7Nc6b9vO-lIiUBA-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 A03722999B2E; Thu, 12 Jan 2023 01:57:07 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEB6A492C14; Thu, 12 Jan 2023 01:57:06 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 3/8] Catch gdb_exception_error instead of gdb_exception (in many places) Date: Wed, 11 Jan 2023 18:56:25 -0700 Message-Id: <20230112015630.32999-4-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" As described in the previous commit for this series, I became concerned that there might be instances in which a QUIT (due to either a SIGINT or SIGTERM) might not cause execution to return to the top level. In some (though very few) instances, it is okay to not propagate the exception for a Ctrl-C / SIGINT, but I don't think that it is ever okay to swallow the exception caused by a SIGTERM. Allowing that to happen would definitely be a deviation from the current behavior in which GDB exits upon receipt of a SIGTERM. I looked at all cases where an exception handler catches a gdb_exception. Handlers which did NOT need modification were those which satisifed one or more of the following conditions: 1) There is no call path to maybe_quit() in the try block. I used a static analysis tool to help make this determination. In instances where the tool didn't provide an answer of "yes, this call path can result in maybe_quit() being called", I reviewed it by hand. 2) The catch block contains a throw for conditions that it doesn't want to handle; these "not handled" conditions must include the quit exception and the new "forced quit" exception. 3) There was (also) a catch for gdb_exception_quit. Any try/catch blocks not meeting the above conditions could potentially swallow a QUIT exception. My first thought was to add catch blocks for gdb_exception_quit and then rethrow the exception. But Pedro pointed out that this can be handled without adding additional code by simply catching gdb_exception_error instead. That's what this patch series does. There are some oddball cases which needed to be handled differently, plus the extension languages, but those are handled in later patches. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/ada-lang.c | 2 +- gdb/breakpoint.c | 8 ++++---- gdb/i386-linux-tdep.c | 2 +- gdb/inf-loop.c | 2 +- gdb/infcmd.c | 2 +- gdb/infrun.c | 2 +- gdb/jit.c | 2 +- gdb/mi/mi-cmd-break.c | 2 +- gdb/mi/mi-interp.c | 2 +- gdb/objc-lang.c | 2 +- gdb/parse.c | 2 +- gdb/printcmd.c | 2 +- gdb/record-btrace.c | 2 +- gdb/record-full.c | 2 +- gdb/solib.c | 2 +- gdb/sparc64-linux-tdep.c | 2 +- gdb/symfile-mem.c | 2 +- 17 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 40f85914a56..241dd1b9f24 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12320,7 +12320,7 @@ should_stop_exception (const struct bp_location *bl) scoped_value_mark mark; stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ())); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, _("Error in testing exception condition:\n")); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 8cfc46e0bed..af8b62e4880 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2833,7 +2833,7 @@ insert_bp_location (struct bp_location *bl, if (val) bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } - catch (gdb_exception &e) + catch (gdb_exception_error &e) { rethrow_on_target_close_error (e); bp_excpt = std::move (e); @@ -5295,7 +5295,7 @@ bpstat_check_watchpoint (bpstat *bs) { e = watchpoint_check (bs); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error evaluating expression " @@ -5539,7 +5539,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) { condition_result = breakpoint_cond_eval (cond); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error in testing breakpoint condition:\n"); @@ -13476,7 +13476,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, bpt->enable_state = bp_enabled; update_watchpoint (w, true /* reparse */); } - catch (const gdb_exception &e) + catch (const gdb_exception_error &e) { bpt->enable_state = orig_enable_state; exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index ad0377de5a6..a6adeca1b97 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -415,7 +415,7 @@ i386_linux_report_signal_info (struct gdbarch *gdbarch, struct ui_out *uiout, access = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr"); } - catch (const gdb_exception &exception) + catch (const gdb_exception_error &exception) { return; } diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c index f49d1c3c872..b9f25008247 100644 --- a/gdb/inf-loop.c +++ b/gdb/inf-loop.c @@ -69,7 +69,7 @@ inferior_event_handler (enum inferior_event_type event_type) { bpstat_do_actions (); } - catch (const gdb_exception &e) + catch (const gdb_exception_error &e) { /* If the user was running a foreground execution command, then propagate the error so that the prompt diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 0497ad05091..895d84025cf 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1588,7 +1588,7 @@ print_return_value (struct ui_out *uiout, struct return_value_info *rv) delete the breakpoint. */ print_return_value_1 (uiout, rv); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stdout, ex); } diff --git a/gdb/infrun.c b/gdb/infrun.c index 181d961d80d..9cfafda5ace 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8730,7 +8730,7 @@ normal_stop (void) { execute_cmd_pre_hook (stop_command); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error while running hook_stop:\n"); diff --git a/gdb/jit.c b/gdb/jit.c index 48bfef0a026..7f6b289cdd3 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -715,7 +715,7 @@ jit_reader_try_read_symtab (gdbarch *gdbarch, jit_code_entry *code_entry, code_entry->symfile_size)) status = 0; } - catch (const gdb_exception &e) + catch (const gdb_exception_error &e) { status = 0; } diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 8b0483803b6..75957b75bad 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -58,7 +58,7 @@ breakpoint_notify (struct breakpoint *b) { print_breakpoint (b); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); } diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index cf3d738edce..ba58044f868 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -847,7 +847,7 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, breakpoint *bp) print_breakpoint (bp); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); } diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index e17a4c406c0..054895c02e3 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -1286,7 +1286,7 @@ find_objc_msgcall_submethod (int (*f) (CORE_ADDR, CORE_ADDR *), if (f (pc, new_pc) == 0) return 1; } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Unable to determine target of " diff --git a/gdb/parse.c b/gdb/parse.c index 2f7d58061ab..9aa080ff974 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -514,7 +514,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, { lang->parser (&ps); } - catch (const gdb_exception &except) + catch (const gdb_exception_error &except) { /* If parsing for completion, allow this to succeed; but if no expression elements have been written, then there's nothing diff --git a/gdb/printcmd.c b/gdb/printcmd.c index c3c2e5ad612..fe26771abe4 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2109,7 +2109,7 @@ do_one_display (struct display *d) d->exp = parse_expression (d->exp_string.c_str (), &tracker); d->block = tracker.block (); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { /* Can't re-parse the expression. Disable this display item. */ d->enabled_p = false; diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 0daba893813..61de8491bb9 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -2932,7 +2932,7 @@ cmd_record_btrace_start (const char *args, int from_tty) { execute_command ("target record-btrace", from_tty); } - catch (const gdb_exception &exception) + catch (const gdb_exception_error &exception) { record_btrace_conf.format = BTRACE_FORMAT_BTS; diff --git a/gdb/record-full.c b/gdb/record-full.c index e3cfa3f45d5..15c5b7d682e 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -785,7 +785,7 @@ record_full_message_wrapper_safe (struct regcache *regcache, { record_full_message (regcache, signal); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); return false; diff --git a/gdb/solib.c b/gdb/solib.c index 60bdf46cb91..ec0fcfb5beb 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -785,7 +785,7 @@ update_solib_list (int from_tty) { ops->open_symbol_file_object (from_tty); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error reading attached " diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c index beff812eeef..685df066f3a 100644 --- a/gdb/sparc64-linux-tdep.c +++ b/gdb/sparc64-linux-tdep.c @@ -139,7 +139,7 @@ sparc64_linux_report_signal_info (struct gdbarch *gdbarch, struct ui_out *uiout, if (si_code >= SEGV_ACCADI && si_code <= SEGV_ADIPERR) addr = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr"); } - catch (const gdb_exception &exception) + catch (const gdb_exception_error &exception) { return; } diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index d36b9090e7e..7ac3ac709ec 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -197,7 +197,7 @@ add_vsyscall_page (inferior *inf) name.c_str (), 0 /* from_tty */); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); } From patchwork Thu Jan 12 01:56:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62990 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 35A0B38493EE for ; Thu, 12 Jan 2023 01:58:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35A0B38493EE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488683; bh=0D/HFrdv47G5wKpn6D/qnShS+q43VwmBDA4Vm3mYR7M=; 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=Qxl/FyOnm3d/LdJSJt8F1vFykX6GMtH8L8CdB9dqQmRhJiH3JrXdwPjywn4cYg3xm eP5YZjebvzBwIrH4KsdLMSp3tm/B0S0w/KmEAxumE6vqVfweKT2P4e/YivJ2UeEJEY P5hCL+YjcVQnqmT5CgZ8Fvsd6ajw/IKoBba6gvyk= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 57262385483E for ; Thu, 12 Jan 2023 01:57:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57262385483E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-ln5W1EwZPEuIBKFVvMNl0Q-1; Wed, 11 Jan 2023 20:57:09 -0500 X-MC-Unique: ln5W1EwZPEuIBKFVvMNl0Q-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 7429E811E6E; Thu, 12 Jan 2023 01:57:09 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3220492C14; Thu, 12 Jan 2023 01:57:08 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 4/8] Python QUIT processing updates Date: Wed, 11 Jan 2023 18:56:26 -0700 Message-Id: <20230112015630.32999-5-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=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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" See the previous patches in this series for the motivation behind these changes. This commit contains updates to Python's QUIT handling. Ideally, we'd like to throw gdb_exception_forced_quit through the extension language; I made an attempt to do this for gdb_exception_quit in an earlier version of this patch, but Pedro pointed out that it is (almost certainly) not safe to do so. Still, we definitely don't want to swallow the exception representing a SIGTERM for GDB, nor do we want to force modules written in the extension language to have to explicitly handle this case. Since the idea is for GDB to cleanup and quit for this exception, we'll simply call quit_force() just as if the gdb_exception_forced_quit propagation had managed to make it back to the top level. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/python/py-finishbreakpoint.c | 5 +++++ gdb/python/py-gdb-readline.c | 4 ++++ gdb/python/py-symbol.c | 5 +++++ gdb/python/py-utils.c | 3 +++ gdb/python/py-value.c | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index d4d129110e9..1a224b35779 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -20,6 +20,7 @@ #include "defs.h" +#include "top.h" /* For quit_force(). */ #include "python-internal.h" #include "breakpoint.h" #include "frame.h" @@ -271,6 +272,10 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) } } } + catch (const gdb_exception_forced_quit &except) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { /* Just swallow. Either the return type or the function value diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index ea0f78c9ad8..b9294ad9afc 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -46,6 +46,10 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, p = command_line_input (buffer, prompt, "python"); } /* Handle errors by raising Python exceptions. */ + catch (const gdb_exception_forced_quit &e) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { /* Detect user interrupt (Ctrl-C). */ diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index b8777966c47..899b0787582 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -18,6 +18,7 @@ along with this program. If not, see . */ #include "defs.h" +#include "top.h" /* For force_quit (). */ #include "block.h" #include "frame.h" #include "symtab.h" @@ -515,6 +516,10 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw) = get_selected_frame (_("No frame selected.")); block = get_frame_block (selected_frame, NULL); } + catch (const gdb_exception_forced_quit &e) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { /* Nothing. */ diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 624b90a827f..d5b07a80d82 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -18,6 +18,7 @@ along with this program. If not, see . */ #include "defs.h" +#include "top.h" /* For quit_force (). */ #include "charset.h" #include "value.h" #include "python-internal.h" @@ -219,6 +220,8 @@ gdbpy_convert_exception (const struct gdb_exception &exception) if (exception.reason == RETURN_QUIT) exc_class = PyExc_KeyboardInterrupt; + else if (exception.reason == RETURN_FORCED_QUIT) + quit_force (NULL, 0); else if (exception.error == MEMORY_ERROR) exc_class = gdbpy_gdb_memory_error; else diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index dcc92e51b60..9473468035b 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -18,6 +18,7 @@ along with this program. If not, see . */ #include "defs.h" +#include "top.h" /* For quit_force (). */ #include "charset.h" #include "value.h" #include "language.h" @@ -371,6 +372,10 @@ valpy_get_address (PyObject *self, void *closure) res_val = value_addr (val_obj->value); val_obj->address = value_to_value_object (res_val); } + catch (const gdb_exception_forced_quit &except) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { val_obj->address = Py_None; From patchwork Thu Jan 12 01:56:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62996 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 A0DF438493F6 for ; Thu, 12 Jan 2023 01:58:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0DF438493F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488735; bh=17hoIFvqTcH8F8PW5XAaAP0vAcOUtLAekcBTXkDVTwE=; 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=ujoTCkFTU9r9LAhyt/R9jRABsp5EJBLZSvhk0+0vw4j8RkOGDmr7f4+b+kmkC9nNf /kBoovu8tkDyyEAmcqkBToYUOVsbwUSQifIR7Q/x0sqhl4TOdO6JBvJTSN5g7ELpbn mOuqgxGY+ISiwu2W+U/PABhGuMx8CU0dSS11IjCQ= 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 7D4E5385B51F for ; Thu, 12 Jan 2023 01:57:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D4E5385B51F 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-145-ppm30v4IMqiP1iFavExzXg-1; Wed, 11 Jan 2023 20:57:11 -0500 X-MC-Unique: ppm30v4IMqiP1iFavExzXg-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 6BFEA3C0252E; Thu, 12 Jan 2023 01:57:11 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id B94D1492C14; Thu, 12 Jan 2023 01:57:10 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 5/8] Guile QUIT processing updates Date: Wed, 11 Jan 2023 18:56:27 -0700 Message-Id: <20230112015630.32999-6-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=-10.7 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, URIBL_ABUSE_SURBL 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" This commit contains QUIT processing updates for GDB's Guile support. As with the Python updates, we don't want to permit this code to swallow the exception, gdb_exception_forced_quit, which is associated with GDB receiving a SIGTERM. I've adopted the same solution that I used for Python; whereever a gdb_exception is caught in try/catch code in the Guile extension language support, a catch for gdb_exception_forced_quit has been added; this catch block will simply call quit_force(), which will cause the necessary cleanups to occur followed by GDB exiting. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/guile/guile-internal.h | 5 +++++ gdb/guile/scm-pretty-print.c | 5 +++++ gdb/guile/scm-type.c | 5 +++++ gdb/guile/scm-value.c | 5 +++++ gdb/top.h | 2 +- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h index 42ecb3c24f9..b04ef17a5ad 100644 --- a/gdb/guile/guile-internal.h +++ b/gdb/guile/guile-internal.h @@ -29,6 +29,7 @@ #include "symtab.h" #include "libguile.h" #include "objfiles.h" +#include "top.h" /* For quit_force(). */ struct block; struct frame_info; @@ -704,6 +705,10 @@ gdbscm_wrap (Function &&func, Args &&... args) { result = func (std::forward (args)...); } + catch (const gdb_exception_forced_quit &e) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { exc = unpack (except); diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c index cb6677c8831..c618101bad8 100644 --- a/gdb/guile/scm-pretty-print.c +++ b/gdb/guile/scm-pretty-print.c @@ -21,6 +21,7 @@ conventions, et.al. */ #include "defs.h" +#include "top.h" /* For quit_force(). */ #include "charset.h" #include "symtab.h" /* Needed by language.h. */ #include "language.h" @@ -558,6 +559,10 @@ ppscm_pretty_print_one_value (SCM printer, struct value **out_value, (_("invalid result from pretty-printer to-string"), result); } } + catch (const gdb_exception_forced_quit &except) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { } diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c index da16d22990c..008e792cc34 100644 --- a/gdb/guile/scm-type.c +++ b/gdb/guile/scm-type.c @@ -21,6 +21,7 @@ conventions, et.al. */ #include "defs.h" +#include "top.h" /* For quit_force(). */ #include "arch-utils.h" #include "value.h" #include "gdbtypes.h" @@ -132,6 +133,10 @@ tyscm_type_name (struct type *type) &type_print_raw_options); return stb.release (); } + catch (const gdb_exception_forced_quit &except) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { excp = gdbscm_scm_from_gdb_exception (unpack (except)); diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c index b9948303bc1..0b92b211df7 100644 --- a/gdb/guile/scm-value.c +++ b/gdb/guile/scm-value.c @@ -21,6 +21,7 @@ conventions, et.al. */ #include "defs.h" +#include "top.h" /* For quit_force(). */ #include "arch-utils.h" #include "charset.h" #include "cp-abi.h" @@ -416,6 +417,10 @@ gdbscm_value_address (SCM self) { address = vlscm_scm_from_value (value_addr (value)); } + catch (const gdb_exception_forced_quit &except) + { + quit_force (NULL, 0); + } catch (const gdb_exception &except) { } diff --git a/gdb/top.h b/gdb/top.h index 9f9a0281be4..5a1352ef81c 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -236,7 +236,7 @@ extern void read_command_file (FILE *); extern void init_history (void); extern void command_loop (void); extern int quit_confirm (void); -extern void quit_force (int *, int); +extern void quit_force (int *, int) ATTRIBUTE_NORETURN; extern void quit_command (const char *, int); extern void quit_cover (void); extern void execute_command (const char *, int); From patchwork Thu Jan 12 01:56:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62992 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 7D974385B51B for ; Thu, 12 Jan 2023 01:58:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D974385B51B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488697; bh=LGuB103ZCdO9RzI59ThJRC5h+jdj0L0asmCG6GkWEiQ=; 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=CnjHj+2CMeAbM3J3wSdoIuf1U8gMtyllXhNCAxtdS1+s5NMmaQhly2bs8sjZaJCuy 8hWUemZup1Cly2oUiC4GfbLxFTaDULPl+tMtB3EaDV17XQ6ZF0EEc9KIadF9aKSb2B aicE5Q1hA9VhA1DfwtUChTIqZzXn6z6XcX46IY6M= 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 BBFB7385559A for ; Thu, 12 Jan 2023 01:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBFB7385559A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-323-B8ChzFgmP--a68W4HbGI2g-1; Wed, 11 Jan 2023 20:57:13 -0500 X-MC-Unique: B8ChzFgmP--a68W4HbGI2g-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 713B4882824; Thu, 12 Jan 2023 01:57:13 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF513492C14; Thu, 12 Jan 2023 01:57:12 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 6/8] Call quit_force for gdb_exception_forced_quit in safe_execute_command Date: Wed, 11 Jan 2023 18:56:28 -0700 Message-Id: <20230112015630.32999-7-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=-10.6 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" In gdb/cli/cli-interp.c, safe_execute_command catches gdb_exception. In the previous series, I had changed it to instead catch gdb_exception_error, which would allow gdb_exception_quit and gdb_exception_forced_quit to not be caught, thus propagating as normal. Pedro found some problems with doing this for safe_execute_command. See: https://sourceware.org/pipermail/gdb-patches/2022-March/186320.html Pedro suggested: "Maybe we can just eliminate safe_execute_command and let exceptions propagate normally." I'm not doing that here, though I think it might be worth trying. Instead, what I've done is to catch gdb_exception_forced_quit and, when caught, call quit_force() thus forcing GDB to terminate. After (re)reading Pedro's remarks, I think there's still a problem with this area of the code (in which gdb_exception_quit is turned into an error in interpreter_exec_cmd), but that problem existed before this patch series and I think that fully addressing it should be the subject of a different set of patches. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/cli/cli-interp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 5f2ff726f26..066e55b64f1 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -353,6 +353,17 @@ safe_execute_command (struct ui_out *command_uiout, const char *command, { execute_command (command, from_tty); } + catch (gdb_exception_forced_quit &exception) + { + /* Due to the way that the cli_inter::exec is structured, it is + not safe to only catch gdb_exception_error below, thus + allowing quit exceptions to propagate through. (The CLI + stream won't be reset as it should be.) So, for + gdb_exception_forced_quit, which corresponds to GDB having + received a SIGTERM signal, call quit_force() here which will + cause GDB to terminate. */ + quit_force (NULL, 0); + } catch (gdb_exception &exception) { e = std::move (exception); From patchwork Thu Jan 12 01:56:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62994 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 A87CB38432E9 for ; Thu, 12 Jan 2023 01:58:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A87CB38432E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488712; bh=01kjtP1W1WxAkC+ezCgNc8b1fVwF0W0F4+LiU+qDzOw=; 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=ZOix0Dii33zYGC2AiAggbq7ZIKX5ecGVFURUhIRRLQ++dVtyFPVdAZsNB6iL+Z93l 8HpOYCiwdUCXK+vgHMBew0iI4icGDfRG0pXFy9NUCJ97ME8tJnRU4Fb5WOLMW5aCu4 wJHn9qVN8qme2RtwSA+xBlBER54re0ZtVpADYkoQ= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 167C23858D20 for ; Thu, 12 Jan 2023 01:57:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 167C23858D20 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-120-HLo8-biZN6eScKqNHpJzZg-1; Wed, 11 Jan 2023 20:57:15 -0500 X-MC-Unique: HLo8-biZN6eScKqNHpJzZg-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 7B3D4858F09; Thu, 12 Jan 2023 01:57:15 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id C809E492C14; Thu, 12 Jan 2023 01:57:14 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 7/8] QUIT processing w/ explicit throw for gdb_exception_forced_quit Date: Wed, 11 Jan 2023 18:56:29 -0700 Message-Id: <20230112015630.32999-8-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=-10.6 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" This commit contains changes which have an explicit throw for gdb_exception_forced_quit, or, in a couple of cases for gdb_exception, but with a throw following a check to see if 'reason' is RETURN_FORCED_QUIT. Most of these are straightforward - it made sense to continue to allow an existing catch of gdb_exception to also catch gdb_exception_quit; in these cases, a catch/throw for gdb_exception_forced_quit was added. There are two cases, however, which deserve a more detailed explanation. 1) remote_fileio_request in gdb/remote-fileio.c: The try block calls do_remote_fileio_request which can (in turn) call one of the functions in remote_fio_func_map[]. Taking the first one, remote_fileio_func_open(), we have the following call path to maybe_quit(): remote_fileio_func_open(remote_target*, char*) -> target_read_memory(unsigned long, unsigned char*, long) -> target_read(target_ops*, target_object, char const*, unsigned char*, unsigned long, long) -> maybe_quit() Since there is a path to maybe_quit(), we must ensure that the catch block is not permitted to swallow a QUIT representing a SIGTERM. However, for this case, we must take care not to change the way that Ctrl-C / SIGINT is handled; we want to send a suitable EINTR reply to the remote target should that happen. That being the case, I added a catch/throw for gdb_exception_forced_quit. I also did a bit of rewriting here, adding a catch for gdb_exception_quit in favor of checking the 'reason' code in the catch block for gdb_exception. 2) mi_execute_command in gdb/mi/mi-main.c: The try block calls captured_mi_execute_command(); there exists a call path to maybe_quit(): captured_mi_execute_command(ui_out*, mi_parse*) -> mi_cmd_execute(mi_parse*) -> get_current_frame() -> get_prev_frame_always_1(frame_info*) -> frame_register_unwind_location(frame_info*, int, int*, lval_type*, unsigned long*, int*) -> frame_register_unwind(frame_info*, int, int*, int*, lval_type*, unsigned long*, int*, unsigned char*) -> value_entirely_available(value*) -> value_fetch_lazy(value*) -> value_fetch_lazy_memory(value*) -> read_value_memory(value*, long, int, unsigned long, unsigned char*, unsigned long) -> maybe_quit() That being the case, we can't allow the exception handler (catch block) to swallow a gdb_exception_quit for SIGTERM. However, it does seem reasonable to output the exception via the mi interface so that some suitable message regarding SIGTERM might be printed; therefore, I check the exception's 'reason' field for RETURN_FORCED_QUIT and do a throw for this case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/event-top.c | 2 ++ gdb/mi/mi-main.c | 4 ++++ gdb/remote-fileio.c | 15 ++++++++++----- gdb/tui/tui.c | 4 ++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 4a46e1b9346..9d34e574653 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -1281,6 +1281,8 @@ async_disconnect (gdb_client_data arg) gdb_puts ("Could not kill the program being debugged", gdb_stderr); exception_print (gdb_stderr, exception); + if (exception.reason == RETURN_FORCED_QUIT) + throw; } for (inferior *inf : all_inferiors ()) diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index e0cade2edc3..d7ca7843d6f 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1952,6 +1952,10 @@ mi_execute_command (const char *cmd, int from_tty) somewhere. */ mi_print_exception (command->token, result); mi_out_rewind (current_uiout); + + /* Throw to a higher level catch for SIGTERM sent to GDB. */ + if (result.reason == RETURN_FORCED_QUIT) + throw; } bpstat_do_actions (); diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index 3ff2a65b0ec..c804b0b2098 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -1191,12 +1191,17 @@ remote_fileio_request (remote_target *remote, char *buf, int ctrlc_pending_p) { do_remote_fileio_request (remote, buf); } - catch (const gdb_exception &ex) + catch (const gdb_exception_forced_quit &ex) + { + throw; + } + catch (const gdb_exception_quit &ex) { - if (ex.reason == RETURN_QUIT) - remote_fileio_reply (remote, -1, FILEIO_EINTR); - else - remote_fileio_reply (remote, -1, FILEIO_EIO); + remote_fileio_reply (remote, -1, FILEIO_EINTR); + } + catch (const gdb_exception &ex) + { + remote_fileio_reply (remote, -1, FILEIO_EIO); } } diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index cdae9ffe02b..23b47ee163c 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -122,6 +122,10 @@ tui_rl_switch_mode (int notused1, int notused2) tui_enable (); } } + catch (const gdb_exception_forced_quit &ex) + { + throw; + } catch (const gdb_exception &ex) { exception_print (gdb_stderr, ex); 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.