[PATCH v2 00/47] Windows non-stop mode

Pedro Alves
2025-05-19T13:24:05Z

After a long while (a year, w00t!), here is another iteration of the
Windows non-stop work.

I've pushed the series to the users/palves/windows-non-stop-v2 branch
on sourceware.org, for your convenience.

Compared to the previous version from a year ago (gasp!), here:

https://inbox.sourceware.org/gdb-patches/20240507234233.371123-1-pedro@palves.net/

... many issues where fixed, and it should be a lot more stable. I
think I fixed the problems Tromey found out when he ran the series
against the AdaCore testsuite, particularly around detaching.

The series is bigger, it is now 47 patches instead of 34.

These patches are new:

+ [PATCH v2 01/47] Make default_gdb_exit resilient to failed closes
+ [PATCH v2 02/47] Add test for continuing with some threads running
+ [PATCH v2 03/47] infrun: Remove unnecessary currently_stepping call
+ [PATCH v2 04/47] infrun: Split currently_stepping, fix sw watchpoints issue
+ [PATCH v2 05/47] thread_info::executing+resumed -> thread_info::internal_state
+ [PATCH v2 36/47] linux-nat: Factor out get_detach_signal code to common code
+ [PATCH v2 37/47] Windows GDB: make windows_thread_info be private thread_info data
+ [PATCH v2 38/47] Introduce windows_nat::event_code_to_string
+ [PATCH v2 40/47] Windows gdb: Eliminate invalidate_context
+ [PATCH v2 42/47] gdb_test_multiple: Anchor prompt match if -lbl
+ [PATCH v2 43/47] Windows gdb: extra thread info => show exiting
+ [PATCH v2 44/47] Add gdb.threads/leader-exit-schedlock.exp
+ [PATCH v2 45/47] infrun: with AS+NS, prefer process exit over thread exit
+ [PATCH v2 46/47] Windows gdb: Always non-stop

The last one above (#46) was split from the main non-stop patch so
that AS-on-NS is only activated after the new infrun changes are
merged.

Note that patches above with subject that starts with "infrun" or
"thread_info" are changes to common code.

This patch from the previous version of the series was dropped:

- windows_per_inferior::continue_one_thread, unify WoW64/non-WoW64 paths

... as no longer needed, since Hannes's:

commit b2682eade4db993bc8231007ba94aec4e4728c61
Author: Hannes Domani <ssbssa@yahoo.de>
AuthorDate: Fri Dec 6 14:04:00 2024 +0100

Reduce WOW64 code duplication

The "Windows gdb: Add non-stop support" patch changed in some
important areas compared to the previous version. Here's a summary:

- We can't use DBG_REPLY_LATER with thread/process exit events. For
those, we need to use the pre-exiting pending-status mechanism.

- When a thread that is abruptly killed has a pending DBG_REPLY_LATER
reply queued in the kernel, we always see that queued event first
before the thread exit event.

- The above two points required careful handling of the
(th->suspended == -1) state in some places.

- windows-nat.c was in some cases deleting the thread before
reporting TARGET_WAITKIND_THREAD_EXITED to infrun (when
target_thread_events was active), resulting in a double free,
because infrun deletes the thread as well. OTOH, when
TARGET_WAITKIND_THREAD_EXITED was reported and windows-nat.c didn't
delete the thread, nothing was deleting the corresponding
windows_thread_info object, resulting weird confusion in the
windows backend, with stale threads still in the backend list.

- TARGET_WAITKIND_NO_RESUMED is now implemented.

- The new "Add gdb.threads/leader-exit-schedlock.exp" patch adds a
test that exercises all the points above. The pre-existing
"gdb.base/ending-run.exp" testcase also covers some aspects.

- Adjusted to new model introduced by the
"thread_info::executing+resumed -> thread_info::internal_state"
patch earlier in the series.

- Adjusted to windows_thread_info being owned by the thread_info
object.

- The do_initial_windows_stuff run-to-initial-breakpoint loop now
handles target_thread_events enabled correctly.

- Fixes detaching with queued DBG_REPLY_LATER events on the kernel
side. The Windows kernel re-raises any exception previously
intercepted and deferred with DBG_REPLY_LATER in the inferior after
we detach. We need to flush those events, otherwise the inferior
dies immediately after the detach, due to an unhandled exception.

- The intro text added to windows-nat.c has more paragraphs and
sections detailing the new things I've learned along the way since
the last time.

In the NEWS patch, I'm now mentioning scheduler-locking support too.
Previously I only mentioned non-stop.

I've added "Approved-By:" tags from last year's review, to patches
that haven't changed since. Some of them I could have pushed back
then, but I didn't want to do that until the v2 series was complete,
in case some problems I was addressing in v2 were caused by those
preparatory patches.

The "prerequisite-patch-id" at the bottom is:

[PATCH] Fix build when RUSAGE_THREAD is not available & add warning
https://inbox.sourceware.org/gdb-patches/20250517213056.3251858-1-pedro@palves.net/T/#u

Here's the original intro blurb, still accurate:

This series adds non-stop mode support to the Windows native backend,
on Windows 10 and above. Earlier Windows versions lack the necessary
feature, so those keep working in all-stop mode, only.

After the series, the Windows target backend defaults to working in
non-stop mode (as in, "maint set target-non-stop"), even if
user-visible mode is all-stop ("set non-stop off"). This is the same
as the Linux backend.

I've been testing this on Cygwin native with the GDB testsuite as I've
been developing this. Running the testsuite on Cygwin is a pain, and
many testcases run into cascading timeouts still, and some even hang
the test run forever until you kill them manually. I've got another
series of patches to improve such tests and skip others, and that's
what I've been testing with. I've also tested the series with the
windows-nat backend forced to all-stop mode.

Pedro Alves (47):
Make default_gdb_exit resilient to failed closes
Add test for continuing with some threads running
infrun: Remove unnecessary currently_stepping call
infrun: Split currently_stepping, fix sw watchpoints issue
thread_info::executing+resumed -> thread_info::internal_state
Windows gdb: Dead code in windows_nat_target::do_initial_windows_stuff
Windows gdb: Eliminate global current_process.dr[8] global
Windows gdb+gdbserver: New find_thread, replaces
thread_rec(DONT_INVALIDATE_CONTEXT)
Windows gdb: handle_output_debug_string return type
Windows gdb: Eliminate reload_context
Windows gdb+gdbserver: Eliminate thread_rec(INVALIDATE_CONTEXT) calls
Windows gdb+gdbserver: Eliminate DONT_SUSPEND
Windows gdb+gdbserver: Eliminate windows_process_info::thread_rec
Windows gdb: Simplify windows_nat_target::wait
Windows gdb+gdbserver: Move suspending thread to when returning event
Windows gdb: Introduce continue_last_debug_event_main_thread
Windows gdb: Introduce windows_continue_flags
Windows gdb: Factor code out of windows_nat_target::windows_continue
Windows gdb: Pending stop and current_event
Windows gdb+gdbserver: Elim desired_stop_thread_id / rework
pending_stops
Windows gdb+gdbserver: Introduce get_last_debug_event_ptid
Windows gdb: Can't pass signal to thread other than last stopped
thread
Windows gdbserver: Fix scheduler-locking
Windows gdb: Enable "set scheduler-locking on"
Windows gdbserver: Eliminate soft-interrupt mechanism
Windows gdb+gdbserver: Make current_event per-thread state
Windows gdb+gdbserver: Make last_sig per-thread state
Windows gdb+gdbserver: Make siginfo_er per-thread state
Add backpointer from windows_thread_info to windows_process_info
Windows gdb+gdbserver: Share $_siginfo reading code
Windows gdb+gdbserver: Eliminate struct pending_stop
Windows gdb: Change serial_event management
Windows gdb: cygwin_set_dr => windows_set_dr, etc.
Windows gdb: Avoid writing debug registers if watchpoint hit pending
Windows gdb+gdbserver: Check whether DBG_REPLY_LATER is available
linux-nat: Factor out get_detach_signal code to common code
Windows GDB: make windows_thread_info be private thread_info data
Introduce windows_nat::event_code_to_string
Windows gdb: Add non-stop support
Windows gdb: Eliminate invalidate_context
Windows gdb: Watchpoints while running (internal vs external stops)
gdb_test_multiple: Anchor prompt match if -lbl
Windows gdb: extra thread info => show exiting
Add gdb.threads/leader-exit-schedlock.exp
infrun: with AS+NS, prefer process exit over thread exit
Windows gdb: Always non-stop (default to "maint set target-non-stop
on")
Mention Windows scheduler-locking and non-stop support in NEWS

gdb/NEWS | 6 +
gdb/aarch64-tdep.c | 2 +-
gdb/amd-dbgapi-target.c | 8 +-
gdb/breakpoint.c | 9 +-
gdb/bsd-uthread.c | 4 +-
gdb/fork-child.c | 4 +-
gdb/frame.c | 4 +-
gdb/gcore.c | 4 +-
gdb/gdbthread.h | 150 +-
gdb/i386-tdep.c | 4 +-
gdb/inf-ptrace.c | 2 +-
gdb/infcall.c | 8 +-
gdb/infcmd.c | 39 +-
gdb/inferior.h | 4 +-
gdb/inflow.c | 2 +-
gdb/infrun.c | 429 ++--
gdb/infrun.h | 13 +-
gdb/linux-fork.c | 9 +-
gdb/linux-nat.c | 44 +-
gdb/linux-thread-db.c | 4 +-
gdb/mi/mi-cmd-var.c | 4 +-
gdb/mi/mi-interp.c | 2 +-
gdb/mi/mi-main.c | 8 +-
gdb/nat/windows-nat.c | 176 +-
gdb/nat/windows-nat.h | 223 +-
gdb/process-stratum-target.c | 6 +-
gdb/python/py-infthread.c | 6 +-
gdb/record-btrace.c | 20 +-
gdb/record-full.c | 6 +-
gdb/regcache.c | 2 +-
gdb/remote.c | 76 +-
gdb/sol-thread.c | 4 +-
gdb/target.c | 15 +-
.../gdb.threads/continue-some-running.c | 76 +
.../gdb.threads/continue-some-running.exp | 52 +
.../gdb.threads/leader-exit-schedlock.c | 56 +
.../gdb.threads/leader-exit-schedlock.exp | 215 ++
.../gdb.threads/step-over-process-exit.c | 49 +
.../gdb.threads/step-over-process-exit.exp | 66 +
.../sw-watchpoint-step-over-bp-with-threads.c | 64 +
...w-watchpoint-step-over-bp-with-threads.exp | 91 +
gdb/testsuite/lib/gdb.exp | 8 +-
gdb/thread-iter.h | 2 +-
gdb/thread.c | 299 ++-
gdb/top.c | 2 +-
gdb/windows-nat.c | 2033 +++++++++++++----
gdbserver/win32-low.cc | 450 ++--
gdbserver/win32-low.h | 19 +-
48 files changed, 3369 insertions(+), 1410 deletions(-)
create mode 100644 gdb/testsuite/gdb.threads/continue-some-running.c
create mode 100644 gdb/testsuite/gdb.threads/continue-some-running.exp
create mode 100644 gdb/testsuite/gdb.threads/leader-exit-schedlock.c
create mode 100644 gdb/testsuite/gdb.threads/leader-exit-schedlock.exp
create mode 100644 gdb/testsuite/gdb.threads/step-over-process-exit.c
create mode 100644 gdb/testsuite/gdb.threads/step-over-process-exit.exp
create mode 100644 gdb/testsuite/gdb.threads/sw-watchpoint-step-over-bp-with-threads.c
create mode 100644 gdb/testsuite/gdb.threads/sw-watchpoint-step-over-bp-with-threads.exp

base-commit: e1ec485cfa29f9c45370b9d0c12480ebb0a0be06
prerequisite-patch-id: 474281ed1de7dcad710a9f1415fe4866fe3e36cb
--
2.49.0