Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb: don't return an exited thread from any_non_exited_thread_of_inferior
@ 2026-09-17 20:16 Simon Marchi
  2026-09-17 20:16 ` [PATCH 2/2] gdb: use the selected thread's LWP ID when reading Linux procfs files Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Simon Marchi @ 2026-09-17 20:16 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-21 15:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 20:16 [PATCH 1/2] gdb: don't return an exited thread from any_non_exited_thread_of_inferior Simon Marchi
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox