From: Keith Seitz <keiths@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] gdb: add some asserts to thread_db_notice_clone
Date: Tue, 5 May 2026 11:24:46 -0700 [thread overview]
Message-ID: <c865def8-eb54-465a-ad4b-0e2e7f4b7182@redhat.com> (raw)
In-Reply-To: <2c5f44442eacd91020ce9058abf16442ecf3718a.1775557188.git.aburgess@redhat.com>
Hi,
On 4/7/26 3:22 AM, Andrew Burgess wrote:
> This commit adds some asserts to thread_db_notice_clone, and reorders
> some code. This is really just a refactor ahead of the next commit.
> The changes made here are:
>
> 1. Add an assert that STOPPED is not NULL. We pass STOPPED as the
> first argument to thread_from_lwp, which already assumes that the
> pointer is not NULL. If STOPPED was ever NULL then we would have
> hit a segfault in thread_from_lwp long ago.
>
> 2. Move the thread_from_lwp call relating to the PARENT thread
> before the call relating to the CHILD thread, and assert that the
> value we get back is STOPPED. The thread_from_lwp might also
> gather thread-db related information about PARENT, so the call is
> important, but even if PARENT cannot be managed via thread-db,
> the result we get back should always still be STOPPED (see
> record_thread for more details). Moving this call before the
> call relating to the CHILD thread makes the next commit cleaner.
>
> There should be no user visible changes after this commit as I believe
> both of the things being asserted have always been true.
I'm no expert at this, but your assumption seems correct as far as I
understand it. So this LGTM.
Reviewed-By: Keith Seitz <keiths@redhat.com>
Keith
> ---
> gdb/linux-thread-db.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
> index cd25c55a898..1807352ed76 100644
> --- a/gdb/linux-thread-db.c
> +++ b/gdb/linux-thread-db.c
> @@ -440,12 +440,17 @@ thread_db_notice_clone (ptid_t parent, ptid_t child)
> return false;
>
> thread_info *stopped = linux_target->find_thread (parent);
> -
> - thread_from_lwp (stopped, child);
> + gdb_assert (stopped != nullptr);
>
> /* If we do not know about the main thread's pthread info yet, this
> - would be a good time to find it. */
> - thread_from_lwp (stopped, parent);
> + would be a good time to find it. This should return the same
> + thread_info as STOPPED, but a side effect of this call is that the
> + pthread/thread-db information might have been filled in if it was not
> + already known. */
> + thread_info *parent_info = thread_from_lwp (stopped, parent);
> + gdb_assert (parent_info == stopped);
> +
> + thread_from_lwp (stopped, child);
> return true;
> }
>
next prev parent reply other threads:[~2026-05-05 18:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 10:22 [PATCH 0/3] Better error handling when creating threads with clone() Andrew Burgess
2026-04-07 10:22 ` [PATCH 1/3] gdb: int to bool conversion in linux-thread-db.c Andrew Burgess
2026-05-05 18:19 ` Keith Seitz
2026-04-07 10:22 ` [PATCH 2/3] gdb: add some asserts to thread_db_notice_clone Andrew Burgess
2026-05-05 18:24 ` Keith Seitz [this message]
2026-04-07 10:22 ` [PATCH 3/3] gdb: improve error handling for thread-db thread adoption Andrew Burgess
2026-05-06 19:39 ` Keith Seitz
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=c865def8-eb54-465a-ad4b-0e2e7f4b7182@redhat.com \
--to=keiths@redhat.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/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