From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gI45L+Ehh2rngjIAWB0awg (envelope-from ) for ; Thu, 20 Aug 2026 11:48:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1787240929; bh=DwwTcK+pdr/Gece3+Kz5iUfe7LMQdUQdQEZ/4Uc88cs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=K68g+DVeXfBnNmpnkEOp/EfchqrDPPahRe6jpSyzWL9xRPLKxRmw3gsG37GAS6kk6 mTTP1rsZVCO8O21Lgs/iuxLsA7JJfQiP7O5OsNWHBC31b5bcciKgdCfBFim62c5qe0 I6OXYYFH5YU4nE7sQS4dXF9/uAkSKXRmK8E8Da7k= Received: by simark.ca (Postfix, from userid 112) id AC5F21E0A3; Thu, 20 Aug 2026 11:48:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=I3zHpWiY; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 77F311E033 for ; Thu, 20 Aug 2026 11:48:48 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 963614BAE7EE for ; Thu, 20 Aug 2026 15:48:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 963614BAE7EE Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=I3zHpWiY Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id BE74E4BA2E04 for ; Thu, 20 Aug 2026 15:48:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE74E4BA2E04 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE74E4BA2E04 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787240903; cv=none; b=uVPm+ddcRJncd0W1qA+nTzCiac98OVB3EqksNCFf4hD29vzCfX9HfiPUwdvBKrk1QB/Rs+R9JI9ENWeC7RGpp3vR5BXwmBbEcOjbhGwD/OyKi1i/REIsPGChTxF4C59UwfzaKYnt/GCJxWz4icuI3MtJoXDHBD7s45TTmd+hoek= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787240903; c=relaxed/simple; bh=DwwTcK+pdr/Gece3+Kz5iUfe7LMQdUQdQEZ/4Uc88cs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=QmleWkG0PXXJ1+/psKt6o/h86wgz3Ds7/DFeMU12aat9cJ6MFfHF7cGcVHWDUxxzi0hHDgmd5wXtE/lxLvt1SN9bkzqd2ECiDc9kdcDAFDfYQUT8ikscAcBlN1IQPPDGzK+tCXgNZDImYG2nJGsIycRdE2larkJTPWrSomv2JCQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=I3zHpWiY DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE74E4BA2E04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1787240902; bh=DwwTcK+pdr/Gece3+Kz5iUfe7LMQdUQdQEZ/4Uc88cs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=I3zHpWiYj2bBgP9H5YEnOiL8t5eXGl71dZIGBP7nyy+ROykryuh89XgIONjPtydBh 9frTAl3OfEiFR+n4lFx5E0SFk8pyy6eAZ9kRHsaDgqgHFkeYu9W8WI1rb6f6T0rHzP StbSYNukCpJxhLJ8GkaT7fHle92APQpm7/9aPGSw= Received: by simark.ca (Postfix) id 6C2FB1E033; Thu, 20 Aug 2026 11:48:21 -0400 (EDT) Message-ID: Date: Thu, 20 Aug 2026 11:48:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/2] gdb: rely on the first non-exited thread TPID when reading Linux procfs files To: Matthieu Longo , gdb-patches@sourceware.org Cc: Luis Machado , Luis Machado , Thiago Jung Bauermann References: <20260728143317.245389-1-matthieu.longo@arm.com> <20260728143317.245389-3-matthieu.longo@arm.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20260728143317.245389-3-matthieu.longo@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 7/28/26 10:33 AM, Matthieu Longo wrote: > diff --git a/gdb/inferior.h b/gdb/inferior.h > index 5c7a52319e7..91dc4e636fd 100644 > --- a/gdb/inferior.h > +++ b/gdb/inferior.h > @@ -513,6 +513,17 @@ class inferior : public refcounted_object, > /* Find (non-exited) thread PTID of this inferior. */ > thread_info *find_thread (ptid_t ptid); > > + /* Return the first non-exited thread of this inferior. > + > + This is only a best-effort choice of a thread that is expected to still > + exist in the target. A thread may have exited after GDB last updated its > + thread list, or GDB/gdbserver may have observed the exit but not yet > + propagated it through all layers. Therefore the returned thread is not > + guaranteed to still be alive when it is later accessed. This avoids the > + common case where the current thread has exited, but callers must still be > + prepared for the selected thread to no longer exist. */ > + ptid_t first_non_exited_thread () const; I think it would be more consistent with the other "find thread" methods to return the `thread_info *` > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > index 8c53ffd5e89..9bdcc55a0e1 100644 > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -457,6 +457,44 @@ linux_has_shared_address_space (struct gdbarch *gdbarch) > return linux_is_uclinux (); > } > > +/* Return a PTID that identifies the current process and can be used to > + access procfs safely. > + > + The returned PTID is that of the thread-group leader whenever it is > + still alive. If the leader has already exited, the PTID of the first > + non-exited thread in the current inferior is returned instead. > + This ensures that the returned PTID always refers to a live thread > + whose procfs entries are present and populated. */ > +static ptid_t > +get_process_reference_ptid (bool verbose = false) > +{ > + /* Get the current thread. */ > + thread_info *thr = inferior_thread (); > + > + /* Construct the PTID of the thread-group leader. On Linux, > + the leader's LWP ID is equal to the process ID. */ > + ptid_t leader_ptid (thr->ptid.pid (), thr->ptid.pid ()); > + > + /* Use the thread-group leader if it is still alive. Otherwise, use > + the first thread that has not exited. */ > + thread_info *leader_thr > + = current_inferior ()->find_thread (leader_ptid); > + ptid_t ptid = (leader_thr == nullptr > + ? current_inferior ()->first_non_exited_thread () > + : leader_ptid); > + > + if (!verbose) > + return ptid; > + > + if (leader_thr != nullptr) > + gdb_printf (_("process %d\n"), leader_ptid.pid ()); > + else > + gdb_printf (_("process %d [Note: information where gathered from LWP %ld " \ > + "as the thread-group leader (LWP=%ld) already exited.]\n"), > + ptid.pid (), ptid.lwp (), leader_ptid.lwp ()); I don't think the printfs should be part of this getter function. Move it to a separate function called by whoever needs it. Or just inline it, it looks like there is just a single caller that needs it (linux_info_proc). And really (IIUC), this function only really needs to return a tid (the id of one LWP), not a ptid. Simon