From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 1/2] gdb: don't return an exited thread from any_non_exited_thread_of_inferior
Date: Thu, 17 Sep 2026 16:16:57 -0400 [thread overview]
Message-ID: <20260917201755.589524-1-simon.marchi@efficios.com> (raw)
any_non_exited_thread_of_inferior prefers to return the selected thread:
/* Prefer the current thread, if there's one. */
if (inf == current_inferior () && inferior_ptid != null_ptid)
return inferior_thread ();
... but the selected thread can be an exited thread. This can happen in
non-stop when the selected thread exits, in which case it is kept around
but marked as exited (see thread_info::deletable).
Check the current thread's state before returning it, and fall through
to the existing loop otherwise.
Note that we also have any_live_thread_of_inferior, which is similar but
differs in subtle ways. We should probably check if we can merge them
at some point.
Change-Id: I620ee200037c6a3fd3d59b96f16750d6b962c724
---
gdb/thread.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/gdb/thread.c b/gdb/thread.c
index 0f86f6efe380..e14254619e34 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -670,9 +670,13 @@ any_non_exited_thread_of_inferior (inferior *inf)
{
gdb_assert (inf->pid != 0);
- /* Prefer the current thread, if there's one. */
+ /* Prefer the current thread, if there's one and it hasn't exited. */
if (inf == current_inferior () && inferior_ptid != null_ptid)
- return inferior_thread ();
+ {
+ if (thread_info *curr_thr = inferior_thread ();
+ curr_thr->state () != THREAD_EXITED)
+ return curr_thr;
+ }
for (thread_info &tp : inf->non_exited_threads ())
return &tp;
base-commit: 0595410d007e5f628e14717cd268e557e166675f
--
2.55.0
next reply other threads:[~2026-09-17 20:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 20:16 Simon Marchi [this message]
2026-09-17 20:16 ` [PATCH 2/2] gdb: use the selected thread's LWP ID when reading Linux procfs files Simon Marchi
2026-09-21 10:22 ` [PATCH 1/2] gdb: don't return an exited thread from any_non_exited_thread_of_inferior Matthieu Longo
2026-09-21 13:46 ` Simon Marchi
[not found] ` <20260917201755.589524-2-simon.marchi@efficios.com_5b6b04a9_release>
2026-09-21 14:26 ` [PATCH 2/2] gdb: use the selected thread's LWP ID when reading Linux procfs files Matthieu Longo
2026-09-21 14:57 ` Simon Marchi
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=20260917201755.589524-1-simon.marchi@efficios.com \
--to=simon.marchi@efficios.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