From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 7kCsFtMTW2YBBCMAWB0awg (envelope-from ) for ; Sat, 01 Jun 2024 08:28:03 -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=Yj/VcHgM; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=x21BghLN; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=liaB1Aw8; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=HAOSUX4N; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 45D901E0C0; Sat, 1 Jun 2024 08:28:03 -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 066281E092 for ; Sat, 1 Jun 2024 08:28:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55A7E3884573 for ; Sat, 1 Jun 2024 12:28:00 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 20B81385ED40 for ; Sat, 1 Jun 2024 12:27:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20B81385ED40 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 20B81385ED40 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717244847; cv=none; b=qYR0WUFUdkspOlHtDDnRZA5Kk1LJcG4jdfASpY/7k4o4jn3IpSwBHJeeBZrLexIkG6RhMJxvaIJDihxX0nPfobuA2eQbk6NerNVdRdGOCW9OoxRUkKUE792ZwfegfzlDTYieHKIQuuoYtk685rrjk5XCQZoGSakBdt56VbeQrFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717244847; c=relaxed/simple; bh=BkpDkASxiMFkm/L3rMMGoVhzW08/a5Qr7oVbmXqotGw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=OXc/v/I6OBYy7Wv6pWxYAha8uQXUoMPSGAvh6K5Wt6HhIDiiJH/p8OLgu3F788Rl+OdD4mll5T+8NvsuugM8nSqyChLvwnWwieTMB7AY+oHHMtLq2jlk3VPEKPCa9omhBuZaiWkag5LUUyeShof3C2Nr66GUKhpEcEQBcu6VJks= 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-out1.suse.de (Postfix) with ESMTPS id CD98621F6D for ; Sat, 1 Jun 2024 12:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717244844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JB0Mzy6gxuTSmzJMsAPzfJKyuRfRqXsMM5pfcagg7eo=; b=Yj/VcHgM+ivFwowPu5KOgP1m5TL5MWyhv/Dh4YcSDIkxYc50SttRYO/5a0MewsR4KPlohb vpg/POCMbTUl6xcl6i/d2Uwbw+Xnu9lXMH1nXomWVRUJVOxERR161iyKuoZ1kNkypqFpUP Wkkvc2sP9DCxA3a1bYoztAJxahkdMAo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717244844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JB0Mzy6gxuTSmzJMsAPzfJKyuRfRqXsMM5pfcagg7eo=; b=x21BghLNGyoABpapgiKhtc+wMN2Ot0g3sixGvw0CCDuqmYxKja4yInYm6YaoKYcl0BmO6V pIC3GiO0u0HhqNBg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=liaB1Aw8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=HAOSUX4N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717244843; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JB0Mzy6gxuTSmzJMsAPzfJKyuRfRqXsMM5pfcagg7eo=; b=liaB1Aw8f3AXVB+ZViG60WBZ5mrVf9L7GyYLsXZxPd39ioGBTgfo7KmdXsxq1oj/fCuW/H S9ZjIGwxPCluPsUOtLPsMyHUQNo1OPRTvArvpiKf2foVWfQWhl+5wJ5YWoXjejo62u20j+ 4rLU5c44bWlJifr6iP8nRBXK2IlmMx0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717244843; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JB0Mzy6gxuTSmzJMsAPzfJKyuRfRqXsMM5pfcagg7eo=; b=HAOSUX4N6ugaYDPtk0tLP7UCCwg2AH4HlVAdCLGC5+YpaUW/GZ0zfQiwzuLEl8f2Ec/vTX l1m4ZFQQSIrPN6Bw== 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 B99F11378C for ; Sat, 1 Jun 2024 12:27:23 +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 2WbCK6sTW2ZSUwAAD6G6ig (envelope-from ) for ; Sat, 01 Jun 2024 12:27:23 +0000 Message-ID: <34c9df7f-224a-4c49-8976-07c049c5408e@suse.de> Date: Sat, 1 Jun 2024 14:27:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING^3][PATCH] [gdb] Prune inferior after switching inferior From: Tom de Vries To: gdb-patches@sourceware.org References: <20240304122120.27659-1-tdevries@suse.de> <900e6331-86f4-4485-a40c-dc1737ad9732@suse.de> <4671abe5-8d01-46fd-a280-6cf9e4c86c1b@suse.de> Content-Language: en-US In-Reply-To: <4671abe5-8d01-46fd-a280-6cf9e4c86c1b@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spamd-Result: default: False [-4.50 / 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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; XM_UA_NO_VERSION(0.01)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received,2a07:de40:b281:104:10:150:64:97:from]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; 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-Rspamd-Action: no action X-Rspamd-Queue-Id: CD98621F6D X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: -4.50 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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 5/8/24 14:21, Tom de Vries wrote: > On 3/19/24 10:34, Tom de Vries wrote: >> On 3/4/24 13:21, 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. >>> >> >> Ping. > > Ping^2. Ping^3. Thanks, - Tom >>> 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 (); >>>       } >>>   } >>> 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.*: >> $hex>(?:\r\n$warning_msg)*" \ >>> -     "do_parent_stuff \\(\\) at \[^\r\n\]+" \ >>> -     "$decimal\\s+\[^\r\n\]+"] >>> +     "\\\[Switching to inferior 1 .*" \ >>> +     ".*" \ >>> +     "FreeProgspaceEvent.*: "] >>>   # Let this inferior run to completion. >>>   gdb_continue_to_end >>> >>> base-commit: 1485a3fb63619cced99dd7a4a043cf01a0f423d9 >> >