aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
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 3cfb284..c66dc60 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1266,6 +1266,24 @@ user_show_python (char *args, int from_tty)
/* Initialize the Python code. */
+/* This is installed as a final cleanup and cleans up the
+ interpreter. This lets Python's 'atexit' work. */
+
+static void
+finalize_python (void *ignore)
+{
+ /* We don't use ensure_python_env here because if we ever ran the
+ cleanup, gdb would crash -- because the cleanup calls into the
+ Python interpreter, which we are about to destroy. It seems
+ clearer to make the needed calls explicitly here than to create a
+ cleanup and then mysteriously discard it. */
+ PyGILState_Ensure ();
+ python_gdbarch = target_gdbarch;
+ python_language = current_language;
+
+ Py_Finalize ();
+}
+
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_python;
@@ -1427,6 +1445,7 @@ message == an error message without a stack will be printed."),
PyThreadState_Swap (NULL);
PyEval_ReleaseLock ();
+ make_final_cleanup (finalize_python, NULL);
#endif /* HAVE_PYTHON */
}