Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Return correct thread for cached event
Date: Wed,  2 Sep 2026 12:09:28 -0600	[thread overview]
Message-ID: <20260902180928.3545493-1-tromey@adacore.com> (raw)

Commit 2e1aacf15a9 ("Windows gdb+gdbserver: Make current_event
per-thread state") introduced a regression.  This was detected by the
AdaCore internal test suite in a somewhat unusual configuration: when
using "attach" with a 32-bit Windows process, an extra stop would be
generated, like:

    (gdb) break break_me
    Breakpoint 1 at 0x1211a04: file pck.adb, line 18.
    (gdb) continue
    Continuing.

    Thread 4 received signal SIGINT, Interrupt.
    [Switching to thread 4 (Thread 6652)]
    0x77034210 in ntdll!RtlUserThreadStart () from C:/Windows/SysWOW64/ntdll.dll

Here, we expect to stop in break_me, but instead stop in some Windows
DLL.

I tracked this down to this hunk in the aforementioned commit:

-      return debug_event_ptid (&windows_process.current_event);
+      return ptid_t (windows_process.process_id,
+		     windows_process.main_thread_id, 0);

What happens here is that the "cached" stop ends up being reported in
the main thread, rather than whatever thread actually caused this
stop.

This patch fixes the problem by arranging to also cache the thread
ptid.

I am not sure whether the call to switch_to_thread here is really
needed; but since other returns seem to switch the thread, I thought
this one ought to as well.

I tested this using the AdaCore internal test suite.

As this is a regression, when it lands I also plan to apply it to the
gdb 18 branch.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34583
---
 gdbserver/win32-low.cc | 5 +++--
 gdbserver/win32-low.h  | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index 13c14a7c69f..55e4b2e2fe3 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -337,6 +337,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
 	  || status.kind () == TARGET_WAITKIND_STOPPED)
 	{
 	  windows_process.cached_status = status;
+	  windows_process.cached_ptid = current_thread->id;
 	  break;
 	}
 
@@ -1145,8 +1146,8 @@ win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus,
 	 fails).  Report it now.  */
       *ourstatus = windows_process.cached_status;
       windows_process.cached_status.set_ignore ();
-      return ptid_t (windows_process.process_id,
-		     windows_process.main_thread_id, 0);
+      switch_to_thread (find_thread_ptid (windows_process.cached_ptid));
+      return windows_process.cached_ptid;
     }
 
   while (1)
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 439adb84bc2..f4f02851734 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -193,6 +193,8 @@ struct gdbserver_windows_process : public windows_nat::windows_process_info
      win32_wait should return it next, instead of fetching the next
      debug event off the win32 API.  */
   struct target_waitstatus cached_status;
+  /* The ptid corresponding to the above status.  */
+  ptid_t cached_ptid;
 
   /* True if current_process_handle needs to be closed.  */
   bool open_process_used = false;

base-commit: 49c379f8c2f8ff888b621b4a070dc1976b942577
-- 
2.55.0


             reply	other threads:[~2026-09-02 18:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 18:09 Tom Tromey [this message]
2026-09-03 14:15 ` Hannes Domani
2026-09-03 15:06   ` Tom Tromey
2026-09-04 12:51 ` Pedro Alves

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=20260902180928.3545493-1-tromey@adacore.com \
    --to=tromey@adacore.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