From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id BAF57385382C for ; Tue, 10 Aug 2021 19:53:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BAF57385382C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 17AJqkda001818 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Aug 2021 15:52:51 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 17AJqkda001818 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 7BFFC1EA7E; Tue, 10 Aug 2021 15:52:46 -0400 (EDT) Subject: Re: [PATCH] gdb: iterate only on vfork parent threads in handle_vfork_child_exec_or_exit To: John Baldwin , gdb-patches@sourceware.org References: <20210805162135.729540-1-simon.marchi@polymtl.ca> <6953d4b9-3473-508c-501e-0003bb7e2ad8@FreeBSD.org> From: Simon Marchi Message-ID: Date: Tue, 10 Aug 2021 15:52:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <6953d4b9-3473-508c-501e-0003bb7e2ad8@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 10 Aug 2021 19:52:46 +0000 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Tue, 10 Aug 2021 19:53:11 -0000 On 2021-08-05 1:08 p.m., John Baldwin wrote: > On 8/5/21 9:21 AM, Simon Marchi via Gdb-patches wrote: >> I spotted what I think is a buglet in proceed_after_vfork_done. After a >> vfork child exits or execs, we resume all the threads of the parent. To >> do so, we iterate on all threads using iterate_over_threads with the >> proceed_after_vfork_done callback. Each thread is resumed if the >> following condition is true: >> >> if (thread->ptid.pid () == pid >> && thread->state == THREAD_RUNNING >> && !thread->executing >> && !thread->stop_requested >> && thread->stop_signal () == GDB_SIGNAL_0) >> >> where `pid` is the pid of the vfork parent. This is not multi-target >> aware: since it only filters on pid, if there is an inferior with the >> same pid in another target, we could end up resuming a thread of that >> other inferior. The chances of the stars aligning for this to happen >> are tiny, but still. >> >> Fix that by iterating only on the vfork parent's threads, instead of on >> all threads. This is more efficient, as we iterate on just the required >> threads (inferiors have their own thread list), and we can drop the pid >> check. The resulting code is also more straightforward in my opinion, >> so it's a win-win. > > This looks sensible to me. Thanks to you and Pedro, pushed. Simon