]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Windows gdb+gdbserver: Check whether DBG_REPLY_LATER is available
authorPedro Alves <pedro@palves.net>
Thu, 9 May 2024 11:32:53 +0000 (12:32 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 9 Jun 2025 17:09:16 +0000 (18:09 +0100)
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 <ssbssa@yahoo.de>
Suggested-by: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: Ia27b981aeecaeef430ec90cebc5b3abdce00449d

gdb/nat/windows-nat.c
gdb/nat/windows-nat.h

index a548acc97d366d38295dbc4efe5ce06d95db02d5..907d39f317affa65c79f9ad6282027e10bcb158f 100644 (file)
@@ -912,6 +912,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 ()
 {
index 795d6c485feef028445948b74805a1ce4e5c3bd7..667fc832292902e771bd612b3228ae30cec240dd 100644 (file)
@@ -532,6 +532,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.  */