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 05AE03858427 for ; Sun, 27 Feb 2022 00:01:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 05AE03858427 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-657-hRqzPClMP4KJG454hgHc1w-1; Sat, 26 Feb 2022 19:01:43 -0500 X-MC-Unique: hRqzPClMP4KJG454hgHc1w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63A32501E0; Sun, 27 Feb 2022 00:01:42 +0000 (UTC) Received: from f35-1.lan (unknown [10.2.16.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id B87965E26C; Sun, 27 Feb 2022 00:01:41 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH v3 4/7] Python QUIT processing updates Date: Sat, 26 Feb 2022 17:00:48 -0700 Message-Id: <20220227000051.3336149-5-kevinb@redhat.com> In-Reply-To: <20220227000051.3336149-1-kevinb@redhat.com> References: <20220227000051.3336149-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_FMBLA_NEWDOM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Sun, 27 Feb 2022 00:01:47 -0000 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. --- 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 083694fbcce..3e5adf45e06 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" @@ -272,6 +273,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 af388d5ed72..a112e6360a2 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -45,6 +45,10 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, p = command_line_input (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 819a51f7e41..c2d247590cb 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" @@ -501,6 +502,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 73c860bcc96..2bb452ed340 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" @@ -237,6 +238,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 b546344da95..0a4b44c3b65 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; -- 2.35.1