From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /QypGsAK8GB9SQAAWB0awg (envelope-from ) for ; Thu, 15 Jul 2021 06:15:28 -0400 Received: by simark.ca (Postfix, from userid 112) id 5F0191EDF0; Thu, 15 Jul 2021 06:15:28 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5C23D1E54D for ; Thu, 15 Jul 2021 06:15:27 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D2AF3AAB02F for ; Thu, 15 Jul 2021 10:15:26 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 69CA1386185D for ; Thu, 15 Jul 2021 10:15:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69CA1386185D Authentication-Results: sourceware.org; dmarc=none (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-out1.suse.de (Postfix) with ESMTPS id 9E10322959; Thu, 15 Jul 2021 10:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626344114; 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=VD6ojWx+wcSnUDYdpImuLEys3KMMznlFLNylwDuslWI=; b=BuePoLJG6eMlbyYvfLrEUyXpghSXyMiFCAGejPFq6qcaahpG+8suVvIQ4BQ7ayy2FgOv86 ApZaUAr28dfsypvIC0B2UWAzIiUSgL6El7Z92aZvRglXGMDx0DCd1n8ce+PgwAHQe9q/Qz 4uwPnX/N/s8db1tMHEm9sPJgSFNFb68= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626344114; 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=VD6ojWx+wcSnUDYdpImuLEys3KMMznlFLNylwDuslWI=; b=qvvYGL2xxFw/NPYFtw2PgqCh8L3K7SyqcAUrauLOomhbrDsa7vj1yTuFZmCxaRcM39DFVC d+RDyEBF5f9/h9DQ== 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 8AA3813C2F; Thu, 15 Jul 2021 10:15:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id G8LfILIK8GAbFQAAMHmgww (envelope-from ); Thu, 15 Jul 2021 10:15:14 +0000 Subject: Re: [PATCH] gdb: make all_inferiors_safe actually work To: Simon Marchi , gdb-patches@sourceware.org References: <61f3cd99-8b32-e14a-117e-52aa4c7e6343@polymtl.ca> <20210714201541.1883926-1-simon.marchi@polymtl.ca> From: Tom de Vries Message-ID: Date: Thu, 15 Jul 2021 12:15:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210714201541.1883926-1-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 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 Sender: "Gdb-patches" On 7/14/21 10:15 PM, Simon Marchi wrote: > The test gdb.threads/fork-plus-threads.exp fails since 08bdefb58b78 > ("gdb: make inferior_list use intrusive_list"): > > FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left > > Looking at the log, we see that we are left with a bunch of inferiors in > the detach-on-fork=off case: > > info inferiors^M > Num Description Connection Executable ^M > * 1 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 2 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 3 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 4 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 5 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 6 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 7 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 8 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 9 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 10 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > 11 /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M > (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left > > when we expect to have just one. The problem is prune_inferiors not > pruning inferiors. And this is caused by all_inferiors_safe not > actually iterating on inferiors. The current implementation: > > inline all_inferiors_safe_range > all_inferiors_safe () > { > return {}; > } > > default-constructs an all_inferiors_safe_range, which default-constructs > an all_inferiors_safe_iterator as its m_begin field, which > default-constructs a all_inferiors_iterator. A default-constructed > all_inferiors_iterator is an end iterator, which means we have > constructed an (end,end) all_inferiors_safe_range. > > We actually need to pass down the list on which we want to iterator > (that is the inferior_list global), so that all_inferiors_iterator's > first constructor is chosen. We also pass nullptr as the proc_target > filter. In this case, we don't do any filtering, but if in the future > all_inferiors_safe needed to allow filtering on process target (like > all_inferiors does), we could pass down a process target pointer. > > basic_safe_iterator's constructor needs to be changed to allow > constructing the wrapped iterator with multiple arguments, not just one. > > With this, gdb.threads/fork-plus-threads.exp is passing once again for > me. > For me as well. LGTM. One suggestion: I'd do s%/home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads%fork-plus-threads% in the log message for readability. Thanks, - Tom > Change-Id: I650552ede596e3590c4b7606ce403690a0278a01 > --- > gdb/inferior.h | 2 +- > gdbsupport/safe-iterator.h | 10 +++++----- > 2 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/gdb/inferior.h b/gdb/inferior.h > index 6662a3bde463..94fbac0fc571 100644 > --- a/gdb/inferior.h > +++ b/gdb/inferior.h > @@ -676,7 +676,7 @@ extern intrusive_list inferior_list; > inline all_inferiors_safe_range > all_inferiors_safe () > { > - return {}; > + return all_inferiors_safe_range (nullptr, inferior_list); > } > > /* Returns a range representing all inferiors, suitable to use with > diff --git a/gdbsupport/safe-iterator.h b/gdbsupport/safe-iterator.h > index 5cfc5b6ee692..53868d3b3eec 100644 > --- a/gdbsupport/safe-iterator.h > +++ b/gdbsupport/safe-iterator.h > @@ -48,11 +48,11 @@ class basic_safe_iterator > typedef typename Iterator::iterator_category iterator_category; > typedef typename Iterator::difference_type difference_type; > > - /* Construct using the given argument; the end iterator is default > - constructed. */ > - template > - explicit basic_safe_iterator (Arg &&arg) > - : m_it (std::forward (arg)), > + /* Construct the begin iterator using the given arguments; the end iterator is > + default constructed. */ > + template > + explicit basic_safe_iterator (Args &&...args) > + : m_it (std::forward (args)...), > m_next (m_it) > { > if (m_it != m_end) >