From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 6C0F33858D1E for ; Fri, 28 Jul 2023 06:49:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C0F33858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7D6261F8A8; Fri, 28 Jul 2023 06:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690526992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YgYyQhvHtb4/u3Hi13inboQqkPY4m0jy8Ihkr9TEXzE=; b=lBEpmchFYRN97wjl38FLwle03dqW+knjIOQ2ORF+0fu9ELn5KRpVHNq75nVD9btDz+QYUi HBZ+DvRMavy4vpO5ong0ESvwQY9+ZGZrHttEMtTS+exjC2SZUMGAlN5gpM+4hGzUYSG4dV n9jee1Yjw1BSqIDJry2h7oZqhgfPNqg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690526992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YgYyQhvHtb4/u3Hi13inboQqkPY4m0jy8Ihkr9TEXzE=; b=bFvmqEvMlO0MKlSVDHX9vWhN6Op/xg9dldZsdLpQrbT0WOmiiqecJIZwpFTh4Hks6pyUga LwZ4X+uFMbLQK6BQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 59841133F7; Fri, 28 Jul 2023 06:49:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id E6orFBBlw2R4NgAAMHmgww (envelope-from ); Fri, 28 Jul 2023 06:49:52 +0000 Message-ID: Date: Fri, 28 Jul 2023 08:49:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval Content-Language: en-US To: Tom Tromey , gdb-patches@sourceware.org Cc: =?UTF-8?Q?Alexandra_H=c3=a1jkov=c3=a1?= References: <20230727135835.2450275-1-tromey@adacore.com> From: Tom de Vries In-Reply-To: <20230727135835.2450275-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 Reviewed-By: Tom de Vries 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)