* [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval
@ 2023-07-27 13:58 Tom Tromey
2023-07-28 6:49 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-07-27 13:58 UTC (permalink / raw)
To: gdb-patches; +Cc: Alexandra Hájková, Tom de Vries, Tom Tromey
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.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30686
---
gdb/python/python.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 505fc4412d1..6a978d632e9 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)
--
2.40.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval
2023-07-27 13:58 [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval Tom Tromey
@ 2023-07-28 6:49 ` Tom de Vries
2023-07-28 12:15 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2023-07-28 6:49 UTC (permalink / raw)
To: Tom Tromey, gdb-patches; +Cc: Alexandra Hájková
On 7/27/23 15:58, Tom Tromey wrote:
> 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.
>
Hi,
thanks for taking care of this.
I've tested this, and the PR no longer triggers for me.
[ FYI, I also tested for PR30680, both using the assert patch and tsan,
and that one still triggers. ]
Also, patch LGTM.
Tested-by: Tom de Vries <tdevries@suse.de>
Reviewed-By: Tom de Vries <tdevries@suse.de>
Thanks,
- Tom
> I wonder whether the test suite should unconditionally set
> PYTHONMALLOC=malloc_debug.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30686
> ---
> gdb/python/python.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index 505fc4412d1..6a978d632e9 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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval
2023-07-28 6:49 ` Tom de Vries
@ 2023-07-28 12:15 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2023-07-28 12:15 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom Tromey, gdb-patches, Alexandra Hájková
Tom> Also, patch LGTM.
Tom> Tested-by: Tom de Vries <tdevries@suse.de>
Tom> Reviewed-By: Tom de Vries <tdevries@suse.de>
Thanks, I'm checking it in.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-28 12:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 13:58 [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval Tom Tromey
2023-07-28 6:49 ` Tom de Vries
2023-07-28 12:15 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).