* NEWS: Update.
authorTom Tromey <tromey@redhat.com>
Thu, 20 Sep 2012 20:54:11 +0000 (20:54 +0000)
committerTom Tromey <tromey@redhat.com>
Thu, 20 Sep 2012 20:54:11 +0000 (20:54 +0000)
* python/python.c (finalize_python): New function.
(_initialize_python): Make a final cleanup.
testsuite
* gdb.python/python.exp: Test atexit.register.

gdb/ChangeLog
gdb/NEWS
gdb/python/python.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/python.exp

index d36c95e4cbfe11fe4dafece2e14104a252293f5a..b11ac7cfb53b1349311da8b9dc627c0a7a68eddd 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-20  Tom Tromey  <tromey@redhat.com>
+
+       * NEWS: Update.
+       * python/python.c (finalize_python): New function.
+       (_initialize_python): Make a final cleanup.
+
 2012-09-19  Doug Evans  <dje@google.com>
 
        * buildsym.h (param_symbols): Delete, unused.
index 365b2d48a982f56037ff6d6bf3c84ed8b3c0cd90..86f57d86e063b9100d75a398cf662e4907352f48 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -7,6 +7,8 @@
 
   ** Vectors can be created with gdb.Type.vector.
 
+  ** Python's atexit.register now works in GDB.
+
 * New Python-based convenience functions:
 
   ** $_memeq(buf1, buf2, length)
index 3cfb284eaf7c6c2aba402781cb339b55a68a81f6..c66dc60356f0ec02f86e747fb0e860d48da23a30 100644 (file)
@@ -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 */
 }
 
index b7e0f0b997368c7b6bf43e01371bbb8afe72968e..789b49d71a8615bb929168005fc9ac08db8bb236 100644 (file)
@@ -1,3 +1,7 @@
+2012-09-20  Tom Tromey  <tromey@redhat.com>
+
+       * gdb.python/python.exp: Test atexit.register.
+
 2012-09-20  Doug Evans  <dje@google.com>
 
        * boards/dwarf4-gdb-index.exp: New file.
index 9f29e3a756907f688bb646594ca5f060ec9ef163..6f0ce1cc6a7dee3aeee46b48b267b26916c153c4 100644 (file)
@@ -141,6 +141,24 @@ gdb_test "python print a" ".*aliases -- Aliases of other commands.*" "verify hel
 gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1
 gdb_test "python print nothread == None" "True" "Ensure that no threads are returned"
 
+gdb_py_test_multiple "register atexit function" \
+    "python" "" \
+    "import atexit" "" \
+    "def printit(arg):" "" \
+    "  print arg" "" \
+    "atexit.register(printit, 'good bye world')" "" \
+    "end" ""
+
+send_gdb "quit\n"
+gdb_expect {
+    -re "good bye world" {
+       pass "atexit handling"
+    }
+    default {
+       fail "atexit handling"
+    }
+}
+
 # Start with a fresh gdb.
 clean_restart ${testfile}
 
This page took 0.047758 seconds and 4 git commands to generate.