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;