Re: [PATCH v2 15/47] Windows gdb+gdbserver: Move suspending thread to when returning event

Tom Tromey
2025-05-28T19:18:12Z

>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> The current code suspends a thread just before calling
Pedro> GetThreadContext. You can only call GetThreadContext if the thread is
Pedro> suspended. But, after WaitForDebugEvent, all threads are implicitly
Pedro> suspended. So I don't think we even needed to call SuspendThread
Pedro> explictly at all before our GetThreadContext calls.

I long suspected this code was wrong but never tried to do anything
about it.

Pedro> However, suspending threads when we're about to present a stop to gdb
Pedro> simplifies adding non-stop support later. This way, the windows
Pedro> SuspendThread state corresponds to whether a thread is suspended or
Pedro> resumed from the core's perspective. Curiously, I noticed that Wine's
Pedro> winedbg does something similar:
Pedro> https://github.com/wine-mirror/wine/blob/234943344f7495d1e072338f0e06fa2d5cbf0aa1/programs/winedbg/gdbproxy.c#L651

Pedro> This makes it much easier to reason about a thread's suspend state,
Pedro> and simplifies adding non-stop mode later on.

Thanks.
Approved-By: Tom Tromey <tom@tromey.com>

Tom