[binutils-gdb] Windows gdb+gdbserver: Check whether DBG_REPLY_LATER is available
Pedro Alves via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=63ad47116639d58210873e8d3f71db307d7ab3e8 commit 63ad47116639d58210873e8d3f71db307d7ab3e8 Author: Pedro Alves <[email protected]> Date: Thu May 9 12:32:53 2024 +0100 Windows gdb+gdbserver: Check whether DBG_REPLY_LATER is available Per <https://learn.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-continuedebugevent>, DBG_REPLY_LATER is "Supported in Windows 10, version 1507 or above, ..." Since we support versions of Windows older than 10, we need to know whether DBG_REPLY_LATER is available. And we need to know this before starting any inferior. This adds a function that probes for support (and caches the result), by trying to call ContinueDebugEvent on pid=0,tid=0 with DBG_REPLY_LATER, and inspecting the resulting error. Suggested-by: Hannes Domani <[email protected]> Suggested-by: Eli Zaretskii <[email protected]> Approved-By: Tom Tromey <[email protected]> Change-Id: Ia27b981aeecaeef430ec90cebc5b3abdce00449d commit-id:9098a060 Diff: --- gdb/nat/windows-nat.c | 20 ++++++++++++++++++++ gdb/nat/windows-nat.h | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index c6434348607..cf30a66a0c1 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -917,6 +917,26 @@ disable_randomization_available () /* See windows-nat.h. */ +bool +dbg_reply_later_available () +{ + static int available = -1; + if (available == -1) + { + /* DBG_REPLY_LATER is supported since Windows 10, Version 1507. + If supported, this fails with ERROR_INVALID_HANDLE (tested on + Win10 and Win11). If not supported, it fails with + ERROR_INVALID_PARAMETER (tested on Win7). */ + if (ContinueDebugEvent (0, 0, DBG_REPLY_LATER)) + internal_error (_("ContinueDebugEvent call should not " + "have succeeded")); + available = (GetLastError () != ERROR_INVALID_PARAMETER); + } + return available; +} + +/* See windows-nat.h. */ + bool initialize_loadable () { diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 45d186f771a..0a503232718 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -535,6 +535,15 @@ enum_process_modules (WOW64_CONTEXT *, HANDLE process, } #endif +/* This is available starting with Windows 10. */ +#ifndef DBG_REPLY_LATER +# define DBG_REPLY_LATER 0x40010001L +#endif + +/* Return true if it's possible to use DBG_REPLY_LATER with + ContinueDebugEvent on this host. */ +extern bool dbg_reply_later_available (); + /* Load any functions which may not be available in ancient versions of Windows. */