From: Matthieu Longo <matthieu.longo@arm.com>
To: gdb-patches@sourceware.org, Simon Marchi <simark@simark.ca>
Subject: Re: [PATCH v1 2/2] gdb: rely on the first non-exited thread TPID when reading Linux procfs files
Date: Mon, 24 Aug 2026 17:27:43 +0100 [thread overview]
Message-ID: <02026863-1425-41e7-be23-41a9638fd088@arm.com> (raw)
In-Reply-To: <0c8c7cd4-0de0-4677-993b-f5c9704b2e15@arm.com>
On 24/08/2026 17:25, Matthieu Longo wrote:
> On 24/08/2026 16:29, Matthieu Longo wrote:
>> On 20/08/2026 16:48, Simon Marchi wrote:
>>> On 7/28/26 10:33 AM, Matthieu Longo wrote:
>>>> +/* 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).
>>>
>>
>> The idea is to inform the user if a fallback occurs.
>> Now, if I move the printing to another function, I don't have the fetched information anymore, and
>> cannot figure out easily if a fallback happened and using which thread.
>>
>> It is ugly but I could not find better.
>> Do you have a better approach ?
>>> Matthieu
>
> There is actually a way to figure it out by comparing ptid.pid () and ptid.lwp ().
>
> Sent r2 addressing your comment.
> https://inbox.sourceware.org/gdb-patches/20260824162155.467233-1-matthieu.longo@arm.com/T/#u
>
> Matthieu
Sorry, I mistakenly removed you from CC by not clicking the "reply all" button.
Matthieu
next prev parent reply other threads:[~2026-08-24 16:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 14:33 [PATCH v1 0/2] gdb: fix for bug 31207 Matthieu Longo
2026-07-28 14:33 ` [PATCH v1 1/2] gdb: rename any_thread_of_inferior to any_non_exited_thread_of_inferior Matthieu Longo
2026-08-20 15:37 ` Simon Marchi
2026-08-24 14:17 ` Matthieu Longo
2026-07-28 14:33 ` [PATCH v1 2/2] gdb: rely on the first non-exited thread TPID when reading Linux procfs files Matthieu Longo
2026-08-03 4:48 ` Thiago Jung Bauermann
2026-08-13 15:13 ` Matthieu Longo
2026-08-20 15:48 ` Simon Marchi
2026-08-24 15:29 ` Matthieu Longo
2026-08-24 16:25 ` Matthieu Longo
2026-08-24 16:27 ` Matthieu Longo [this message]
2026-08-20 11:09 ` [PATCH v1 0/2] gdb: fix for bug 31207 Matthieu Longo
2026-08-21 15:39 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=02026863-1425-41e7-be23-41a9638fd088@arm.com \
--to=matthieu.longo@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox