aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-11-16 10:44:42 -0700
committerTom Tromey <tromey@adacore.com>2023-12-11 11:44:33 -0700
commit3a12e74ecedfc416aafeda26dbe335ad7962a283 (patch)
tree3887e5a68052763ffc5a9f7256bf78859cd67d45 /gdb/python
parentf895e1592d5f4e58776e6a2d7ccdcc028cc5df80 (diff)
downloadgdb-3a12e74ecedfc416aafeda26dbe335ad7962a283.zip
gdb-3a12e74ecedfc416aafeda26dbe335ad7962a283.tar.gz
gdb-3a12e74ecedfc416aafeda26dbe335ad7962a283.tar.bz2
Introduce gdb.interrupt
DAP cancellation needs a way to interrupt whatever is happening on gdb's main thread -- whether that is the inferior, a gdb CLI command, or Python code. This patch adds a new gdb.interrupt() function for this purpose. It simply sets the quit flag and lets gdb do the rest. No tests in this patch -- instead this is tested via the DAP cancellation tests. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/python.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 8a36673..832f374 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1118,6 +1118,23 @@ gdbpy_post_event (PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+/* Interrupt the current operation on the main thread. */
+static PyObject *
+gdbpy_interrupt (PyObject *self, PyObject *args)
+{
+ {
+ /* Make sure the interrupt isn't delivered immediately somehow.
+ This probably is not truly needed, but at the same time it
+ seems more clear to be explicit about the intent. */
+ gdbpy_allow_threads temporarily_exit_python;
+ scoped_disable_cooperative_sigint_handling no_python_sigint;
+
+ set_quit_flag ();
+ }
+
+ Py_RETURN_NONE;
+}
+
/* This is the extension_language_ops.before_prompt "method". */
@@ -2678,6 +2695,8 @@ Parse String as an expression, evaluate it, and return the result as a Value."
{ "post_event", gdbpy_post_event, METH_VARARGS,
"Post an event into gdb's event loop." },
+ { "interrupt", gdbpy_interrupt, METH_NOARGS,
+ "Interrupt gdb's current operation." },
{ "target_charset", gdbpy_target_charset, METH_NOARGS,
"target_charset () -> string.\n\