public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Cc: "Alexandra Hájková" <ahajkova@redhat.com>
Subject: Re: [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval
Date: Fri, 28 Jul 2023 08:49:35 +0200	[thread overview]
Message-ID: <f8cb5d3b-c27b-4279-1ce8-03151608fd6a@suse.de> (raw)
In-Reply-To: <20230727135835.2450275-1-tromey@adacore.com>

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)


  reply	other threads:[~2023-07-28  6:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27 13:58 Tom Tromey
2023-07-28  6:49 ` Tom de Vries [this message]
2023-07-28 12:15   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f8cb5d3b-c27b-4279-1ce8-03151608fd6a@suse.de \
    --to=tdevries@suse.de \
    --cc=ahajkova@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).