From: Hannes Domani <ssbssa@yahoo.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 6/8] Windows gdb: Get available XState features
Date: Mon, 27 Jul 2026 19:42:30 +0200 [thread overview]
Message-ID: <20260727174619.1089041-6-ssbssa@yahoo.de> (raw)
In-Reply-To: <20260727174619.1089041-1-ssbssa@yahoo.de>
Also prepares the thread context for the additional registers.
---
v2:
- Remove PKRU from the implemented features mask
---
gdb/nat/windows-nat.c | 54 ++++++++++++++++++++++++++++++++++++++++++-
gdb/nat/windows-nat.h | 5 ++++
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index cd1f9e7bc64..28678b9f1a7 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -20,6 +20,7 @@
#include "gdbsupport/common-debug.h"
#include "gdbsupport/gdb_signals.h"
#include "gdbsupport/gdb_wait.h"
+#include "gdbsupport/x86-xstate.h"
#include "target/target.h"
#undef GetModuleFileNameEx
@@ -84,6 +85,8 @@ RtlGetExtendedFeaturesMask_ftype *RtlGetExtendedFeaturesMask;
RtlSetExtendedFeaturesMask_ftype *RtlSetExtendedFeaturesMask;
RtlLocateExtendedFeature_ftype *RtlLocateExtendedFeature;
#endif
+
+DWORD64 xstate_features;
#endif
/* Note that 'debug_events' must be locally defined in the relevant
@@ -308,12 +311,38 @@ windows_process_info::pid_to_exec_file (int pid)
void windows_process_info::initialize_context (windows_thread_info *th)
{
+#if defined __i386__ || defined __x86_64__
+ if (xstate_features != 0)
+ {
+ DWORD context_flags = with_context (nullptr, [] (auto *context)
+ {
+ return WindowsContext<decltype(context)>::all;
+ });
+ context_flags |= CONTEXT_XSTATE_FLAG;
+ DWORD xstate_size = 0;
+ InitializeContext (NULL, context_flags, NULL, &xstate_size);
+ th->context_buffer.reset (xmalloc (xstate_size));
+ CONTEXT *context = nullptr;
+ if (!InitializeContext (th->context_buffer.get (),
+ context_flags, &context, &xstate_size))
+ error ("InitializeContext failure %lu\n", GetLastError ());
#ifdef __x86_64__
- if (wow64_process)
+ /* InitializeContext actually initializes a WOW64_CONTEXT when
+ context_flags contains a WOW64_CONTEXT_* value, so a cast is needed.
+ */
+ if (wow64_process)
+ th->wow64_context = (WOW64_CONTEXT *) context;
+ else
+#endif
+ th->context = context;
+ }
+#ifdef __x86_64__
+ else if (wow64_process)
{
th->context_buffer.reset (xmalloc (sizeof (WOW64_CONTEXT)));
th->wow64_context = (WOW64_CONTEXT *) th->context_buffer.get ();
}
+#endif
else
#endif
{
@@ -1289,6 +1318,29 @@ initialize_loadable ()
#undef GPA
+#if defined __i386__ || defined __x86_64__
+ if (GetEnabledXStateFeatures != nullptr
+ && InitializeContext != nullptr
+ && GetXStateFeaturesMask != nullptr
+ && SetXStateFeaturesMask != nullptr
+ && LocateXStateFeature != nullptr
+#ifdef __x86_64__
+ && RtlGetExtendedFeaturesMask != nullptr
+ && RtlSetExtendedFeaturesMask != nullptr
+ && RtlLocateExtendedFeature != nullptr
+#endif
+ )
+ {
+ /* Available XState features masked with implemented features. */
+ xstate_features = GetEnabledXStateFeatures ()
+ & (X86_XSTATE_AVX_AVX512_MASK | X86_XSTATE_CET_U);
+ /* The extended XState functions are only needed if the available
+ features exceed SSE. */
+ if ((xstate_features & ~X86_XSTATE_SSE_MASK) == 0)
+ xstate_features = 0;
+ }
+#endif
+
return result;
}
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index a344b0a966f..8fcf5e339cb 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -760,6 +760,11 @@ locate_xstate_feature (WOW64_CONTEXT *context, DWORD feature, DWORD *length)
}
#endif
+#if defined __i386__ || defined __x86_64__
+/* Available XState features. */
+extern DWORD64 xstate_features;
+#endif
+
/* This is available starting with Windows 10. */
#ifndef DBG_REPLY_LATER
# define DBG_REPLY_LATER 0x40010001L
--
2.54.0
next prev parent reply other threads:[~2026-07-27 17:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260727174619.1089041-1-ssbssa.ref@yahoo.de>
2026-07-27 17:42 ` [PATCH v2 1/8] gdb/testsuite: Add Windows replacement for aligned_alloc Hannes Domani
2026-07-27 17:42 ` [PATCH v2 2/8] Windows gdb: Use allocated buffer for CONTEXT Hannes Domani
2026-07-27 17:42 ` [PATCH v2 3/8] Windows gdb: Remove mappings member from windows_per_inferior Hannes Domani
2026-07-27 17:42 ` [PATCH v2 4/8] Windows gdb: Refactor getting pointer to register inside context Hannes Domani
2026-07-27 17:42 ` [PATCH v2 5/8] Windows gdb: Prepare XState functions Hannes Domani
2026-07-27 17:42 ` Hannes Domani [this message]
2026-07-27 17:42 ` [PATCH v2 7/8] Windows gdb: Implement XState (Intel AVX) support Hannes Domani
2026-07-27 17:42 ` [PATCH v2 8/8] Windows gdbserver: " Hannes Domani
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=20260727174619.1089041-6-ssbssa@yahoo.de \
--to=ssbssa@yahoo.de \
--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