aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/python.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2008-11-21 14:59:56 +0000
committerTom Tromey <tromey@redhat.com>2008-11-21 14:59:56 +0000
commitca30a76297419a1e0eac2ee6a709dff70d30e56a (patch)
treee13c237992ce5984085aee7f424db45b05c1dab9 /gdb/python/python.c
parent3c9ab205d3020ddcb720946b4b7b1b6cc8de7bcb (diff)
downloadgdb-ca30a76297419a1e0eac2ee6a709dff70d30e56a.zip
gdb-ca30a76297419a1e0eac2ee6a709dff70d30e56a.tar.gz
gdb-ca30a76297419a1e0eac2ee6a709dff70d30e56a.tar.bz2
* python/python-internal.h (PyGILState_Ensure): New define.
(PyGILState_Release): Likewise. (PyEval_InitThreads): Likewise. (PyThreadState_Swap): Likewise. (PyEval_InitThreads): Likewise. * python/python.c (_initialize_python): Initialize threads. Release GIL. (eval_python_from_control_command): Acquire GIL. (python_command): Likewise. * python/python-internal.h (make_cleanup_py_restore_gil): Declare. * python/python-utils.c (py_gil_restore): New function. (make_cleanup_py_restore_gil): Likewise.
Diffstat (limited to 'gdb/python/python.c')
-rw-r--r--gdb/python/python.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 77d8774..50277d4 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -103,10 +103,15 @@ void
eval_python_from_control_command (struct command_line *cmd)
{
char *script;
+ struct cleanup *cleanup;
+ PyGILState_STATE state;
if (cmd->body_count != 1)
error (_("Invalid \"python\" block structure."));
+ state = PyGILState_Ensure ();
+ cleanup = make_cleanup_py_restore_gil (&state);
+
script = compute_python_string (cmd->body_list[0]);
PyRun_SimpleString (script);
xfree (script);
@@ -115,6 +120,8 @@ eval_python_from_control_command (struct command_line *cmd)
gdbpy_print_stack ();
error (_("error while executing Python code"));
}
+
+ do_cleanups (cleanup);
}
/* Implementation of the gdb "python" command. */
@@ -122,6 +129,12 @@ eval_python_from_control_command (struct command_line *cmd)
static void
python_command (char *arg, int from_tty)
{
+ struct cleanup *cleanup;
+ PyGILState_STATE state;
+
+ state = PyGILState_Ensure ();
+ cleanup = make_cleanup_py_restore_gil (&state);
+
while (arg && *arg && isspace (*arg))
++arg;
if (arg && *arg)
@@ -136,10 +149,11 @@ python_command (char *arg, int from_tty)
else
{
struct command_line *l = get_command_line (python_control, "");
- struct cleanup *cleanups = make_cleanup_free_command_lines (&l);
+ make_cleanup_free_command_lines (&l);
execute_control_command_untraced (l);
- do_cleanups (cleanups);
}
+
+ do_cleanups (cleanup);
}
@@ -392,6 +406,7 @@ Enables or disables printing of Python stack traces."),
#ifdef HAVE_PYTHON
Py_Initialize ();
+ PyEval_InitThreads ();
gdb_module = Py_InitModule ("gdb", GdbMethods);
@@ -429,5 +444,10 @@ class GdbOutputFile:\n\
sys.stderr = GdbOutputFile()\n\
sys.stdout = GdbOutputFile()\n\
");
+
+ /* Release the GIL while gdb runs. */
+ PyThreadState_Swap (NULL);
+ PyEval_ReleaseLock ();
+
#endif /* HAVE_PYTHON */
}