From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iCpwBdXcImEkGwAAWB0awg (envelope-from ) for ; Sun, 22 Aug 2021 19:25:09 -0400 Received: by simark.ca (Postfix, from userid 112) id 145301EE18; Sun, 22 Aug 2021 19:25:09 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 2D2DC1E813 for ; Sun, 22 Aug 2021 19:25:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2821385782D for ; Sun, 22 Aug 2021 23:25:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2821385782D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629674707; bh=LwHaWlL9OcQyATq2xZaZFzkxelGtyhmhnBaaZ0j6wVw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qfxj9bE5KoRZ3GrqvKknm+1bNVMc5eW8pLqm5P0nIoxvKZdrYaBSKN6ACNvxbb5Q5 16V4I/ruHCuXDWrcjM7Lj3w8bg6PPSGo1rlRTYhl8wyy81U2qu8BE2c7NL2YBnCgE1 v++xmdZR99Qqg/2rSaZY1OAGpE1Mnzj7lZTtQek8= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id EBDA13854816 for ; Sun, 22 Aug 2021 23:24:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EBDA13854816 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-ywhNDuKsMvOYVbQQ7uX5oA-1; Sun, 22 Aug 2021 19:24:20 -0400 X-MC-Unique: ywhNDuKsMvOYVbQQ7uX5oA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 753BA10053E9 for ; Sun, 22 Aug 2021 23:24:19 +0000 (UTC) Received: from f34-1.lan (ovpn-112-47.phx2.redhat.com [10.3.112.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FB0B1017CE8; Sun, 22 Aug 2021 23:24:19 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH v2 4/6] Python QUIT processing updates Date: Sun, 22 Aug 2021 16:20:01 -0700 Message-Id: <20210822231959.184061-5-kevinb@redhat.com> In-Reply-To: <20210822231959.184061-1-kevinb@redhat.com> References: <20210822231959.184061-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" 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" See the previous patch in this series for the motivation behind these updates. This commit contains updates to Python's QUIT handling. Specifically, it makes sure that a SIGTERM sent to GDB will be propagated to the top level. While there are instances where we want to allow python code to catch Ctrl-C / SIGINT (and possibly) swallow it, I don't think we want that behavior for SIGTERM. Therefore, there are cases where sync_quit_force_run is checked explicitly. In other cases, I was able to defer the decision to GDB_PY_HANDLE_EXCEPTION. (My goal was to minimize explicit references to sync_quit_force_run.) --- gdb/python/py-finishbreakpoint.c | 6 ++++-- gdb/python/py-gdb-readline.c | 12 ++++++++---- gdb/python/py-symbol.c | 4 ++++ gdb/python/py-utils.c | 4 +++- gdb/python/py-value.c | 4 ++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index 1d8373d807e..120e40db6eb 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -270,8 +270,10 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) } catch (const gdb_exception &except) { - /* Just swallow. Either the return type or the function value - remain NULL. */ + /* Swallow everything except for a SIGTERM sent to GDB. Either the + return type or the function value remain NULL. */ + if (sync_quit_force_run) + throw; } if (self_bpfinish->return_type == NULL || self_bpfinish->function_value == NULL) diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index 978c3a8b185..ba1dad931d2 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -45,12 +45,16 @@ 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_quit &except) + { + /* Propagate exception for SIGTERM. */ + if (sync_quit_force_run) + throw; + /* Otherwise, return for user interrupt (Ctrl-C). */ + return NULL; + } catch (const gdb_exception &except) { - /* Detect user interrupt (Ctrl-C). */ - if (except.reason == RETURN_QUIT) - return NULL; - /* The thread state is nulled during gdbpy_readline_wrapper, with the original value saved in the following undocumented variable (see Python's Parser/myreadline.c and diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index d44b55ed5a9..89bddefaa1c 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -501,6 +501,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_quit &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } catch (const gdb_exception &except) { /* Nothing. */ diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 10c4173efcd..d6d8cb82e96 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -233,7 +233,9 @@ gdbpy_convert_exception (const struct gdb_exception &exception) { PyObject *exc_class; - if (exception.reason == RETURN_QUIT) + if (sync_quit_force_run) + throw exception; + else if (exception.reason == RETURN_QUIT) exc_class = PyExc_KeyboardInterrupt; else if (exception.error == MEMORY_ERROR) exc_class = gdbpy_gdb_memory_error; diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 8df8a15f8d6..cfc7a87d766 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -350,6 +350,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_quit &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } catch (const gdb_exception &except) { val_obj->address = Py_None; -- 2.31.1