From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1028) id BCE1C3858032; Mon, 27 Feb 2023 23:21:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BCE1C3858032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677540097; bh=T7JQSdwkznAGbGH05CveyAHrwVhPOgWke2FqJzsbTvA=; h=From:To:Subject:Date:From; b=JaEXa0NegWhDKighobqYoWSFVsbm+iLeAc3xK2qfgHVfBWb06DsWNbPg4jAEMep3N UnD8xxTRFAHSCnT05+y9c9+7TRQvrKXX7Z1JPGwMFyfyO7hH0lDqiur4EOhvspyY8w qnR6yroUIcpCkh3oaq3HkUE3TkCwUvn2Ih4Tyqmo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Kevin Buettner To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Python QUIT processing updates X-Act-Checkin: binutils-gdb X-Git-Author: Kevin Buettner X-Git-Refname: refs/heads/master X-Git-Oldrev: b1ffd1124a8c5170a9e06b867a886b1138d28514 X-Git-Newrev: b940a061c0d549dbe981463414da87cb84a8a9bb Message-Id: <20230227232137.BCE1C3858032@sourceware.org> Date: Mon, 27 Feb 2023 23:21:37 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db940a061c0d5= 49dbe981463414da87cb84a8a9bb commit b940a061c0d549dbe981463414da87cb84a8a9bb Author: Kevin Buettner Date: Mon Feb 27 16:11:37 2023 -0700 Python QUIT processing updates =20 See the previous patches in this series for the motivation behind these changes. =20 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. =20 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. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D26761 Tested-by: Tom de Vries Approved-By: Pedro Alves Diff: --- 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-finishbreakpo= int.c index 3b682f5ad36..159164e8009 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -20,6 +20,7 @@ =20 =20 #include "defs.h" +#include "top.h" /* For quit_force(). */ #include "python-internal.h" #include "breakpoint.h" #include "frame.h" @@ -275,6 +276,10 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObj= ect *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_stdou= t, p =3D 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 e6497ed473f..066a27f0e35 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -18,6 +18,7 @@ along with this program. If not, see . = */ =20 #include "defs.h" +#include "top.h" /* For force_quit (). */ #include "block.h" #include "frame.h" #include "symtab.h" @@ -517,6 +518,10 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *= args, PyObject *kw) =3D get_selected_frame (_("No frame selected.")); block =3D 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 . = */ =20 #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 &ex= ception) =20 if (exception.reason =3D=3D RETURN_QUIT) exc_class =3D PyExc_KeyboardInterrupt; + else if (exception.reason =3D=3D RETURN_FORCED_QUIT) + quit_force (NULL, 0); else if (exception.error =3D=3D MEMORY_ERROR) exc_class =3D gdbpy_gdb_memory_error; else diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 9441a43cad8..65384c781bc 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -18,6 +18,7 @@ along with this program. If not, see . = */ =20 #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 =3D value_addr (val_obj->value); val_obj->address =3D 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 =3D Py_None;