From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by sourceware.org (Postfix) with ESMTPS id 0670C3858D28 for ; Mon, 30 Jan 2023 19:01:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0670C3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f53.google.com with SMTP id n13so1725020wmr.4 for ; Mon, 30 Jan 2023 11:01:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4vgqeFKmlhjx9dndCkc5ASnB6kw7iT0C+0CXhwcvRQ8=; b=xGO1opMxOXEVYutc9l+XZDPWQrHzeb65K7h4L8M+gqLey5WNfreYGnrG2wNjPDMOep b0hnz9z/avTpxPWdKqsi+hVhHpD61IPMUYxv5h7mbg40VJ7V1BMMRY5G/1cIklmqlK/f 40aOqarPBlHcWz5kHf73pbhxzDVZTdxkTT5fcjeG5UZ+iYSw0UsD/xwW0erQmlQZ3a1U PLOakXrm6MvQX5ZPu2SxnBpQA1yTHkU2+kp4JjWWLN0anAPEpRmVm010TGHYvE4YIcHf lR2/F3BblSEarUxJkZxeJIRDl8QGzK5tEBbeZDAUfP3ujgndiN4d/9A7yMdbjjO1SJy7 xyrA== X-Gm-Message-State: AFqh2krxFIPZl55o47DQLYfaYVllcpgj2+b7sP4/xLuqm+nGwa1XuJ9l NNPqujSLLG6/pQTCtYqzERk= X-Google-Smtp-Source: AMrXdXvW/KHXY6kENP6Vkzb2iQjeuWo/LTG5vDM27yYmpRH+lgaIsLTUzX/MmqWhogfw+paJtbatTw== X-Received: by 2002:a05:600c:3d9b:b0:3db:1afd:ac36 with SMTP id bi27-20020a05600c3d9b00b003db1afdac36mr47167896wmb.32.1675105277807; Mon, 30 Jan 2023 11:01:17 -0800 (PST) Received: from ?IPv6:2001:8a0:f92b:9e00::1fe? ([2001:8a0:f92b:9e00::1fe]) by smtp.gmail.com with ESMTPSA id n10-20020a05600c180a00b003daf672a616sm13260615wmp.22.2023.01.30.11.01.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Jan 2023 11:01:17 -0800 (PST) Subject: Re: [PATCH v4 4/8] Python QUIT processing updates To: Kevin Buettner , gdb-patches@sourceware.org Cc: simark@simark.ca, tdevries@suse.de References: <20230112015630.32999-1-kevinb@redhat.com> <20230112015630.32999-5-kevinb@redhat.com> From: Pedro Alves Message-ID: <67d02aee-281d-5436-a969-90a3072867fe@palves.net> Date: Mon, 30 Jan 2023 19:01:16 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20230112015630.32999-5-kevinb@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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 List-Id: On 2023-01-12 1:56 a.m., Kevin Buettner wrote: > 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 I guess this is OK as long as we don't hook up Python at a very low level where running quit_force() would be dangerous. Alternatively, couldn't we force some Python exception/error which is not catch-able from Python code? Set some error flag in the Python interpreter or something, so that it aborts the Python code as soon as we return to the Python interpreter. We'd use the set_quit_flag() trick here where you're calling quit_force (and instead of calling quit_force), so that as soon as we get out of the Python interpreter on the other end, we'd re-raise gdb_exception_forced_quit. Pedro Alves > --- > 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; >