aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-07-27 07:54:18 -0600
committerTom Tromey <tromey@adacore.com>2023-07-28 06:15:30 -0600
commit0c8a0b88d18d9c8d6cd52bd1a56d6ab88570f287 (patch)
tree62a57b6dae1eed0da48c0622e7b9ae2e44d7820a
parent95b83567a4500c9cc14480dc171cf1d26a1555a6 (diff)
downloadbinutils-0c8a0b88d18d9c8d6cd52bd1a56d6ab88570f287.zip
binutils-0c8a0b88d18d9c8d6cd52bd1a56d6ab88570f287.tar.gz
binutils-0c8a0b88d18d9c8d6cd52bd1a56d6ab88570f287.tar.bz2
Re-acquire GIL earlier in gdbpy_parse_and_eval
Tom de Vries filed a bug about an intermittent gdb DAP failure -- and coincidentally, at the same time, Alexandra Hájková sent email about a somewhat similar failure. After looking into this for a while (with no results) using ASan and valgrind, I found that setting PYTHONMALLOC=malloc_debug found the bug instantly. The problem is that gdbpy_parse_and_eval releases the GIL while calling parse_and_eval, but fails to re-acquire it before calling value_to_value_object. This is easily fixed by introducing a new scope. I wonder whether the test suite should unconditionally set PYTHONMALLOC=malloc_debug. Tested-by: Tom de Vries <tdevries@suse.de> Reviewed-By: Tom de Vries <tdevries@suse.de> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30686
-rw-r--r--gdb/python/python.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 505fc44..6a978d6 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -994,9 +994,17 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args, PyObject *kw)
PyObject *result = nullptr;
try
{
- gdbpy_allow_threads allow_threads;
scoped_value_mark free_values;
- struct value *val = parse_and_eval (expr_str, flags);
+ struct value *val;
+ {
+ /* Allow other Python threads to run while we're evaluating
+ the expression. This is important because the expression
+ could involve inferior calls or otherwise be a lengthy
+ calculation. We take care here to re-acquire the GIL here
+ before continuing with Python work. */
+ gdbpy_allow_threads allow_threads;
+ val = parse_and_eval (expr_str, flags);
+ }
result = value_to_value_object (val);
}
catch (const gdb_exception &except)