From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 3rSLHV55n2blVC8AWB0awg (envelope-from ) for ; Tue, 23 Jul 2024 05:35:26 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=obmDJugf; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/1utaaU5; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=dGSO+5HR; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UKHRwFhN; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 5F2831E0C3; Tue, 23 Jul 2024 05:35:26 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 28A9B1E030 for ; Tue, 23 Jul 2024 05:35:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68EFF3861806 for ; Tue, 23 Jul 2024 09:35:23 +0000 (GMT) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 05417385841C for ; Tue, 23 Jul 2024 09:35:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05417385841C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 05417385841C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721727302; cv=none; b=Z6eRI0N+DcNC7Ms4azbQpjr7dv+cUHlsnY6mv9cEdpbuKjqfzpQXBQuilbo02Uwlgz+9O1EQPbRrcdkwM6TrDMclEXZn1QeRhGrZ+HwOk3RGg2Lg7I4Jfd9P0t8LhWHqz4u3j48QrLXHVydzXYM1DJZvd5nM6fvQB/5+7NznKVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721727302; c=relaxed/simple; bh=r4lMUC9bHuGFicKccf5kTpLv8HO2/ZCGnrBGZ1HVA7w=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=B4TqNdMdzO0thref3XSV7DgF/JBbI3xcfV9xOkhskds7T1/Rw420rPaSaDK+8zGPksegegFb1abb7Lg3o7fQiF4lkdFYcRYoaIAcp+CHfsgxLN/bKHnmOneB/3+pi1LEAFwdAG0A/5dw1r9NuysXte1Jd4cdzZldoTJdZa/Vzp0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E1CF31F8B0; Tue, 23 Jul 2024 09:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721727299; 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=gIkwGDrfDbltKl8ZUBMxQOfhaF0NpLHGzcsdfVTmAB0=; b=obmDJugfaPoP2IrwSblYX3VqCkqPjyN05J0N4vl3Km6wlSyTvYAsZOOSKhsuYvWQSE+HBw m6rQzOZrPrwKaS7f1QHzlHoHqfzrLYpoCwOmxR/2Wfa3fixFQ7cfr4RyxdqK+qNb20Wiro 8RH+jPH+FtjBIJ81WPWBFfkwSsZ6zEs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721727299; 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=gIkwGDrfDbltKl8ZUBMxQOfhaF0NpLHGzcsdfVTmAB0=; b=/1utaaU5X+tHVxZKy4w0RFAP1jhUpbM5iAnTjko2Ltu8CTKfwJc6FQCEwiy0hDHeTcQ7Ji YeTErotdrTb73nBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=dGSO+5HR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=UKHRwFhN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721727298; 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=gIkwGDrfDbltKl8ZUBMxQOfhaF0NpLHGzcsdfVTmAB0=; b=dGSO+5HRbvG8AreptXbj7Kv//Q17wn0giuG8JOHg2CyN0uuBj3VQZdcAIc06/lRLc/HoyP TbboFYAsQD1eYDJ2Pp0Crm41Mc8XdYjOgZ96L+yXJZ7Da8qj0MEdcYijYDcPMVcKBw+R5n gIYgn6o19/bxbe1/mgWBLzU3LtO0hoA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721727298; 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=gIkwGDrfDbltKl8ZUBMxQOfhaF0NpLHGzcsdfVTmAB0=; b=UKHRwFhN9XgmKry0Vf1G6+/CfNgrPQhztNGs61Q8QF9qc2VhMSMQE78ZK/EJhQWtxbyZtF QAsqEUj+zhoSj7Aw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C004813874; Tue, 23 Jul 2024 09:34:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id pww8LUJ5n2ZpfAAAD6G6ig (envelope-from ); Tue, 23 Jul 2024 09:34:58 +0000 Message-ID: <1130b669-9bb0-451b-85ed-6589d72ec4cb@suse.de> Date: Tue, 23 Jul 2024 11:35:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb] Prune inferior after switching inferior To: Kevin Buettner Cc: gdb-patches@sourceware.org References: <20240304122120.27659-1-tdevries@suse.de> <20240630131803.50b2450f@f40-zbm-amd> Content-Language: en-US From: Tom de Vries In-Reply-To: <20240630131803.50b2450f@f40-zbm-amd> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -4.30 X-Rspamd-Action: no action X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: E1CF31F8B0 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; XM_UA_NO_VERSION(0.01)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 6/30/24 22:18, Kevin Buettner wrote: > Hi Tom, > > See my comments inline below... > > On Mon, 4 Mar 2024 13:21:20 +0100 > Tom de Vries wrote: > >> Usually with test-case gdb.python/py-progspace-events.exp I get: >> ... >> (gdb) inferior 1^M >> [Switching to inferior 1 [process 4116] (py-progspace-events)]^M >> [Switching to thread 1.1 (Thread 0xf77d0ce0 (LWP 4116))]^M >> 28 { /* Nothing. */ }^M >> (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1 >> step^M >> FreeProgspaceEvent: ^M >> do_parent_stuff () at py-progspace-events.c:41^M >> 41 ++global_var;^M >> (gdb) PASS: gdb.python/py-progspace-events.exp: step >> ... >> >> But occasionally I run into the following FAIL: >> ... >> (gdb) inferior 1^M >> [Switching to inferior 1 [process 5199] (py-progspace-events)]^M >> [Switching to thread 1.1 (Thread 0xf77d0ce0 (LWP 5199))]^M >> 28 { /* Nothing. */ }^M >> (gdb) FreeProgspaceEvent: ^M >> FAIL: gdb.python/py-progspace-events.exp: inferior 1 (timeout) >> ... >> >> This is caused by a race between the handling of an event, and the >> "inferior 1" command. >> >> In the passing case, the event is handled first. During which prune_inferiors >> is called, but it can't remove inferior 1, because it's still the current one. >> >> In the failing case, the "inferior 1" command is handled first. Then during >> handling of the event, prune_inferiors is called, and it can remove inferior 1 >> because it's no longer the current one. >> >> This looks like a test-case issue to me, but ISTM that we can do better: by >> calling prune_inferiors asap, at the end of the "inferior 1" command, we >> stabilize the moment when the inferior is removed: >> ... >> (gdb) inferior 1^M >> [Switching to inferior 1 [process 5199] (py-progspace-events)]^M >> [Switching to thread 1.1 (Thread 0xf77d0ce0 (LWP 5199))]^M >> 28 { /* Nothing. */ }^M >> FreeProgspaceEvent: ^M >> (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1 >> ... >> >> Tested on x86_64-linux. >> >> PR gdb/31440 >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31440 >> --- >> gdb/inferior.c | 4 +++ >> .../gdb.python/py-progspace-events.exp | 31 +++---------------- >> 2 files changed, 9 insertions(+), 26 deletions(-) >> >> diff --git a/gdb/inferior.c b/gdb/inferior.c >> index 5ff5eb98955..4e179f7fb80 100644 >> --- a/gdb/inferior.c >> +++ b/gdb/inferior.c >> @@ -791,6 +791,10 @@ inferior_command (const char *args, int from_tty) >> notify_user_selected_context_changed >> (USER_SELECTED_INFERIOR); >> } >> + >> + /* Switching current inferior may have made one of the inferiors >> + prunable, so prune it. */ >> + prune_inferiors (); >> } >> } >> > > This seems reasonable to me. > >> diff --git a/gdb/testsuite/gdb.python/py-progspace-events.exp b/gdb/testsuite/gdb.python/py-progspace-events.exp >> index 95e4ca8da0b..9dfc7573d40 100644 >> --- a/gdb/testsuite/gdb.python/py-progspace-events.exp >> +++ b/gdb/testsuite/gdb.python/py-progspace-events.exp >> @@ -79,37 +79,16 @@ gdb_test "continue" \ >> "\\\[Inferior $decimal \[^\r\n\]+ exited normally\\\]"] \ >> "continue until inferior 2 exits" >> >> -gdb_test "inferior 1" "\\\[Switching to inferior 1 .*" >> - >> -# Step the inferior. During this process GDB will prune the now >> +# Switch to inferior 1. During this process GDB will prune the now >> # defunct inferior, which deletes its program space, which should >> # trigger the FreeProgspaceEvent. >> # >> -# However, there is a slight problem. When the target is remote, and >> -# GDB is accessing files using remote fileio, then GDB will attempt to >> -# prune the inferior at a point in time when the remote target is >> -# waiting for a stop reply. Pruning an inferior causes GDB to close >> -# files associated with that inferior. >> -# >> -# In non-async mode we can't send fileio packets while waiting for a >> -# stop reply, so the attempts to close files fails, and this shows up >> -# as an error. >> -# >> -# As this error has nothing to do with the feature being tested here, >> -# we just accept the error message, the important part is the >> -# 'FreeProgspaceEvent' string, so long as that appears (just once) >> -# then the test is a success. >> -set warning_msg \ >> - [multi_line \ >> - "warning: cannot close \"\[^\r\n\]+\": Cannot execute this command while the target is running\\." \ >> - "Use the \"interrupt\" command to stop the target" \ >> - "and then try again\\."] >> >> -gdb_test "step" \ >> +gdb_test "inferior 1" \ >> [multi_line \ >> - "^FreeProgspaceEvent.*: (?:\r\n$warning_msg)*" \ >> - "do_parent_stuff \\(\\) at \[^\r\n\]+" \ >> - "$decimal\\s+\[^\r\n\]+"] >> + "\\\[Switching to inferior 1 .*" \ >> + ".*" \ >> + "FreeProgspaceEvent.*: "] > Hi Kevin, thanks for the review. > It appears that you've removed a test here. I'm guessing that the > removed test, "step", was being done in order to trigger the event, > but now that the inferior is being pruned when switching inferiors, > the event happens at that time. If this reasoning is correct, I think > it'd be worth mentioning it in the commit log. > Your reasoning is correct, I'll submit a v2 with updated commit log. > Is it the case that the problem(s) mentioned in the removed comments > have been fixed as well? > I didn't bother with that problem, because the test-case mentions "this error has nothing to do with the feature being tested here". But since you ask, I've tried to modify the test-case to trigger the problem in a way that would still work with this patch applied, hoping that that would provide me with an easy answer. However, I ran into a problem where exiting an inferior in the background changes the active inferior. I've filed this as a PR ( https://sourceware.org/bugzilla/show_bug.cgi?id=31988 ), but perhaps this is expected behaviour, I'm not sure. So unfortunately, my answer is that I don't know whether the problem has been fixed as well. I don't understand the code well enough to be able to reason about this. Thanks, - Tom