aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog10
-rw-r--r--gdb/python/python.c56
2 files changed, 40 insertions, 26 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e5b4019..cf46c4e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2020-05-28 Kevin Buettner <kevinb@redhat.com>
+ Keith Seitz <keiths@redhat.com>
+
+ * python/python.c (do_start_initialization): Call PyEval_SaveThread
+ instead of PyEval_ReleaseLock.
+ (class gdbpy_gil): Move to earlier in file.
+ (finalize_python): Set gdb_python_initialized.
+ (gdbpy_check_quit_flag): Acquire GIL via gdbpy_gil. Return early
+ when not initialized.
+
2020-05-28 Simon Marchi <simon.marchi@efficios.com>
* dwarf2/loc.c (class dwarf_evaluate_loc_desc)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 67f362b..4bdd220 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -238,6 +238,30 @@ gdbpy_enter::~gdbpy_enter ()
PyGILState_Release (m_state);
}
+/* A helper class to save and restore the GIL, but without touching
+ the other globals that are handled by gdbpy_enter. */
+
+class gdbpy_gil
+{
+public:
+
+ gdbpy_gil ()
+ : m_state (PyGILState_Ensure ())
+ {
+ }
+
+ ~gdbpy_gil ()
+ {
+ PyGILState_Release (m_state);
+ }
+
+ DISABLE_COPY_AND_ASSIGN (gdbpy_gil);
+
+private:
+
+ PyGILState_STATE m_state;
+};
+
/* Set the quit flag. */
static void
@@ -251,6 +275,10 @@ gdbpy_set_quit_flag (const struct extension_language_defn *extlang)
static int
gdbpy_check_quit_flag (const struct extension_language_defn *extlang)
{
+ if (!gdb_python_initialized)
+ return 0;
+
+ gdbpy_gil gil;
return PyOS_InterruptOccurred ();
}
@@ -943,30 +971,6 @@ gdbpy_source_script (const struct extension_language_defn *extlang,
/* Posting and handling events. */
-/* A helper class to save and restore the GIL, but without touching
- the other globals that are handled by gdbpy_enter. */
-
-class gdbpy_gil
-{
-public:
-
- gdbpy_gil ()
- : m_state (PyGILState_Ensure ())
- {
- }
-
- ~gdbpy_gil ()
- {
- PyGILState_Release (m_state);
- }
-
- DISABLE_COPY_AND_ASSIGN (gdbpy_gil);
-
-private:
-
- PyGILState_STATE m_state;
-};
-
/* A single event. */
struct gdbpy_event
{
@@ -1616,6 +1620,7 @@ finalize_python (void *ignore)
Py_Finalize ();
+ gdb_python_initialized = false;
restore_active_ext_lang (previous_active);
}
@@ -1785,8 +1790,7 @@ do_start_initialization ()
return false;
/* Release the GIL while gdb runs. */
- PyThreadState_Swap (NULL);
- PyEval_ReleaseLock ();
+ PyEval_SaveThread ();
make_final_cleanup (finalize_python, NULL);