aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/python-internal.h25
-rw-r--r--gdb/python/python.c3
2 files changed, 28 insertions, 0 deletions
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index b5d9840..b157d22 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -684,6 +684,31 @@ class gdbpy_enter_varobj : public gdbpy_enter
};
+/* The opposite of gdb_enter: this releases the GIL around a region,
+ allowing other Python threads to run. No Python APIs may be used
+ while this is active. */
+class gdbpy_allow_threads
+{
+public:
+
+ gdbpy_allow_threads ()
+ : m_save (PyEval_SaveThread ())
+ {
+ gdb_assert (m_save != nullptr);
+ }
+
+ ~gdbpy_allow_threads ()
+ {
+ PyEval_RestoreThread (m_save);
+ }
+
+ DISABLE_COPY_AND_ASSIGN (gdbpy_allow_threads);
+
+private:
+
+ PyThreadState *m_save;
+};
+
extern struct gdbarch *python_gdbarch;
extern const struct language_defn *python_language;
diff --git a/gdb/python/python.c b/gdb/python/python.c
index b23aede..c23db2c 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -576,6 +576,8 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
TRY
{
+ gdbpy_allow_threads allow_threads;
+
struct interp *interp;
std::string arg_copy = arg;
@@ -898,6 +900,7 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args)
TRY
{
+ gdbpy_allow_threads allow_threads;
result = parse_and_eval (expr_str);
}
CATCH (except, RETURN_MASK_ALL)