From: Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 4/6] Python QUIT processing updates
Date: Sun, 22 Aug 2021 16:20:01 -0700 [thread overview]
Message-ID: <20210822231959.184061-5-kevinb@redhat.com> (raw)
In-Reply-To: <20210822231959.184061-1-kevinb@redhat.com>
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
next prev parent reply other threads:[~2021-08-22 23:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-22 23:19 [PATCH v2 0/6] glibc-2.34: Fix gdb.base/gdb-sigterm.exp failure/error Kevin Buettner via Gdb-patches
2021-08-22 23:19 ` [PATCH v2 1/6] Handle recursive internal problem in gdb_internal_error_resync Kevin Buettner via Gdb-patches
2021-09-27 17:38 ` Pedro Alves
2022-02-26 20:40 ` Kevin Buettner via Gdb-patches
2021-08-22 23:19 ` [PATCH v2 2/6] Handle gdb SIGTERM via normal QUIT processing Kevin Buettner via Gdb-patches
2021-09-27 17:39 ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 3/6] Catch and (re)throw gdb_exception_quit Kevin Buettner via Gdb-patches
2021-09-27 18:05 ` Pedro Alves
2021-08-22 23:20 ` Kevin Buettner via Gdb-patches [this message]
2021-09-27 18:24 ` [PATCH v2 4/6] Python QUIT processing updates Pedro Alves
2021-08-22 23:20 ` [PATCH v2 5/6] Guile " Kevin Buettner via Gdb-patches
2021-09-27 18:26 ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 6/6] QUIT processing w/ explicit sync_quit_force_run check Kevin Buettner via Gdb-patches
2021-09-27 18:34 ` Pedro Alves
2021-09-27 17:20 ` [PATCH v2 0/6] glibc-2.34: Fix gdb.base/gdb-sigterm.exp failure/error Kevin Buettner via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210822231959.184061-5-kevinb@redhat.com \
--to=gdb-patches@sourceware.org \
--cc=kevinb@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox