From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6JWmAwpG72C6NwAAWB0awg (envelope-from ) for ; Wed, 14 Jul 2021 16:16:10 -0400 Received: by simark.ca (Postfix, from userid 112) id 0CFD81EDEE; Wed, 14 Jul 2021 16:16:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 85DE61EDDB for ; Wed, 14 Jul 2021 16:16:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA3A53857800 for ; Wed, 14 Jul 2021 20:16:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA3A53857800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626293768; bh=sKxJB7Gj0qrtRWde8WASKPnPh+5vpj8XqXYbn5jYLLQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DwN0JZ+0CyatA2sJoe7QHiaIXkYNFr2Nl86GnjxwISjmbFbIcct/xzJWcpEQkVaM0 InhdiKgcxGkFXe5obINuZ8tlYvkog2pWV1wveYC88IEUCX0I7+YYV+b9dN1TQImkf0 uf8aFBQcIYDt3DMzxj/abD5Nj3qVvgiKGhsdErl0= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 310183858003 for ; Wed, 14 Jul 2021 20:15:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 310183858003 X-ASG-Debug-ID: 1626293742-0c856e67e21a14120001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id xYEfEd0qTfoQiAjm (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Jul 2021 16:15:42 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 8AAF1441DBD; Wed, 14 Jul 2021 16:15:42 -0400 (EDT) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH] gdb: make all_inferiors_safe actually work Date: Wed, 14 Jul 2021 16:15:41 -0400 X-ASG-Orig-Subj: [PATCH] gdb: make all_inferiors_safe actually work Message-Id: <20210714201541.1883926-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.32.0 In-Reply-To: <61f3cd99-8b32-e14a-117e-52aa4c7e6343@polymtl.ca> References: <61f3cd99-8b32-e14a-117e-52aa4c7e6343@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1626293742 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 4956 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.91206 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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. 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) -- 2.32.0