Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@yahoo.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] Windows gdb: Don't abort get_windows_debug_event with no threads
Date: Wed, 26 Aug 2026 20:20:37 +0200	[thread overview]
Message-ID: <20260826182037.757713-1-ssbssa@yahoo.de> (raw)
In-Reply-To: <20260826182037.757713-1-ssbssa.ref@yahoo.de>

When a machine is under heavy load, windows sometimes provides the debug
events in a weird order:

  [windows events] get_windows_debug_event: kernel event for pid=22208 tid=0x6df0 code=CREATE_PROCESS_DEBUG_EVENT
  [windows events] get_windows_debug_event: kernel event for pid=22208 tid=0xe74 code=CREATE_THREAD_DEBUG_EVENT
  [windows events] get_windows_debug_event: kernel event for pid=22208 tid=0xe74 code=EXIT_THREAD_DEBUG_EVENT
  [windows events] get_windows_debug_event: kernel event for pid=22208 tid=0x6df0 code=EXIT_THREAD_DEBUG_EVENT

At this point the process has seemingly no threads, even though for the last
thread there should be EXIT_PROCESS_DEBUG_EVENT instead of
EXIT_THREAD_DEBUG_EVENT.  But the next event shows that a new thread was
created, which then finally got EXIT_PROCESS_DEBUG_EVENT:

  [windows events] get_windows_debug_event: kernel event for pid=22208 tid=0x5a7c code=CREATE_THREAD_DEBUG_EVENT
  [windows events] get_windows_debug_event: kernel event for pid=22208 tid=0x5a7c code=EXIT_PROCESS_DEBUG_EVENT

Since the introduction of non-stop support, gdb fails with this error at
the point of no threads:

  No unwaited-for children left.

It's because it added this check which prevents getting the next debug
event:

  /* If there are no resumed threads left, bail.  */
  if (windows_process->windows_initialization_done
      && !any_resumed_thread ())
    {
      ourstatus->set_no_resumed ();
      return minus_one_ptid;
    }

This fixes it by changing any_resumed_thread to return true if there is
no thread at all.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34195
---
 gdb/windows-nat.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 4cd301d4959..2fa15ada27a 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1367,15 +1367,20 @@ windows_nat_target::thread_events (bool enable)
   m_report_thread_events = enable;
 }
 
-/* True if there is any resumed thread.  */
+/* True if there is any resumed thread, or no thread at all.  */
 
 bool
 windows_nat_target::any_resumed_thread ()
 {
+  bool has_thread = false;
   for (thread_info &thread : all_non_exited_threads (this))
-    if (thread.internal_state () == THREAD_INT_RUNNING)
-      return true;
-  return false;
+    {
+      has_thread = true;
+      if (thread.internal_state () == THREAD_INT_RUNNING)
+	return true;
+    }
+  DEBUG_EVENTS ("any_resumed_thread: has_thread=%d", has_thread);
+  return !has_thread;
 }
 
 /* Called for both EXIT_THREAD_DEBUG_EVENT and
-- 
2.54.0


       reply	other threads:[~2026-08-26 18:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260826182037.757713-1-ssbssa.ref@yahoo.de>
2026-08-26 18:20 ` Hannes Domani [this message]
2026-08-26 18:32   ` Eli Zaretskii
2026-08-27 15:25   ` Tom Tromey
2026-08-27 16:18     ` Hannes Domani

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=20260826182037.757713-1-ssbssa@yahoo.de \
    --to=ssbssa@yahoo.de \
    --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