From: "Joos, Christina" <christina.joos@intel.com>
To: Hannes Domani <ssbssa@yahoo.de>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH v2 7/8] Windows gdb: Implement XState (Intel AVX) support
Date: Wed, 26 Aug 2026 14:28:34 +0000 [thread overview]
Message-ID: <SN7PR11MB7638D75A111388607FC684BD89AE2@SN7PR11MB7638.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20260727174619.1089041-7-ssbssa@yahoo.de>
Hi Hannes,
Thanks a lot for working on this.
I did not find the time to try this out on windows myself, since I was not able to work last week.
This is my code-based review for now.
> -----Original Message-----
> From: Hannes Domani <ssbssa@yahoo.de>
> Sent: Montag, 27. Juli 2026 19:43
> To: gdb-patches@sourceware.org
> Subject: [PATCH v2 7/8] Windows gdb: Implement XState (Intel AVX) support
The commit message header still seems somewhat misleading, as it references only
Intel AVX, while the commit also includes changes related to AVX-512 and shadow stack.
I think it would be helpful if we'd adapt the commit message header of this patch to
include AVX-512, too.
For shadow stack I think it would make sense to move this to a separate commit and give
more details on the tests that are passing/ not passing and the limitations we have in
windows for shadow stack enabled programs.
Besides reading or writing the shadow stack pointer for linux we had to enable
- displaced stepping
- the return command
- inferior calls
for shadow stack enabled programs, which are all covered by current shadow stack tests.
Based on what you said
~~~
It turns out binutils/gcc really don't support this on windows yet.
To enable this in the executable, at least a special marker bit has to be set in the Extended DLL Characteristics [1].
With msvc you can do that with the /CETCOMPAT linker argument [2].
So I compiled amd64-shadow-stack.c with msvc and /CETCOMPAT, and tried it out with my gdb build.
Before I always got $pl3_ssp=0, and with this new exe I always get $pl3_ssp=1.
~~~
I assume you cannot execute those tests. Can you confirm?
Would it make sense to add dedicated tests for windows shadow stack (in the
shadow-stack specific patch), based on the current enablement you describe above ?
Or, maybe even better, can you adapt the proc allow_ssp_tests for window support?
You said:
" It turns out binutils/gcc really don't support this on windows yet."
Could you add a fix to make this work for windows using msvc and /CETCOMPAT ?
In any case, all this information should be part of the commit message.
I also wonder if we should provide some feedback to the user when he attempts to
write the shadow stack pointer.
Currently we see this, right?
~~~
(gdb) p $pl3_ssp=0x12345678
$11 = (void *) 0x12345678
(gdb) ni
error return C:/gdb/src/gdb.git/gdb/x86-windows-nat.c:242 was 1660: The thread context could not be updated because this has been restricted for the process.
0x00007ffd63720574 in ntdll!ZwMapViewOfSection () from C:\WINDOWS\SYSTEM32\ntdll.dll
~~~
I am not GDB windows expert, so I am not sure if that is useful information for the user.
Whatever we display when attempting to write the register, I think it would make sense
to document this somehow. At least in the commits message + even better we could add
a test for this.
> This adds support for the Intel AVX and AVX-512 registers on Windows.
> It enables accessing registers $ymm0 - $ymm31, $zmm0 - $zmm31, and
> $k0 - $k7 where they are available.
>
> It also enables reading the shadow stack pointer register $pl3_ssp (for
> executables marked compatible with CET shadow stack [1]), but modifying it
> seems to be restricted restricted by windows.
Nit: duplicate restricted
>
> After this patch the tests gdb.arch/i386-avx.exp and gdb.arch/i386-avx512.exp
> pass on windows.
Nit: let's add for on windows for Unix boardfile, or something like that.
So it's clear that gdbserver support is missing.
Did you run the tests for 32 bit, too ?
Christina
>
> [1] https://learn.microsoft.com/en-us/cpp/build/reference/cetcompat
> ---
> v2:
> - Extended commit message and NEWS entry
> - Remove PKRU support
> - Fixed context offset of $pl3_ssp
> ---
> gdb/NEWS | 6 +++
> gdb/x86-windows-nat.c | 108
> ++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 111 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 8f40ca5cb11..71ff5508d6d 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -116,6 +116,12 @@
> intent to remove it in a future release.
> The s390 64-bit target (s390x-*) remains supported.
>
> +* Support for Intel AVX registers on Windows.
> + Support displaying and modifying Intel AVX registers $ymm0 - $ymm31.
> + Support displaying and modifying Intel AVX-512 registers $zmm0 -
> +$zmm31
> + and $k0 - $k7.
> + Support displaying the shadow stack pointer register $pl3_ssp.
> +
> * Configure changes
>
> ** --with-babeltrace has been removed. The babeltrace library was diff --git
> a/gdb/x86-windows-nat.c b/gdb/x86-windows-nat.c index
> 3af5ef4dae0..270f9eae8e7 100644
> --- a/gdb/x86-windows-nat.c
> +++ b/gdb/x86-windows-nat.c
> @@ -27,6 +27,9 @@
>
> #include "i386-tdep.h"
> #include "i387-tdep.h"
> +#ifdef __x86_64__
> +#include "amd64-tdep.h"
> +#endif
>
> using namespace windows_nat;
>
> @@ -70,6 +73,8 @@ struct x86_windows_nat_target final : public
> x86_nat_target<windows_nat_target>
> windows_thread_info *th, int r) override;
>
> bool is_sw_breakpoint (const EXCEPTION_RECORD *er) const override;
> +
> + const struct target_desc *read_description () override;
> };
>
> /* The current process. */
> @@ -109,7 +114,31 @@ x86_windows_per_inferior::fill_thread_context
> (windows_thread_info *th)
> if (context->ContextFlags == 0)
> {
> context->ContextFlags = WindowsContext<decltype(context)>::all;
> + if (xstate_features != 0)
> + {
> + context->ContextFlags |= CONTEXT_XSTATE_FLAG;
> + set_xstate_features_mask (context, xstate_features);
> + }
> CHECK (get_thread_context (th->h, context));
> +
> + if (xstate_features != 0)
> + {
> + DWORD64 features = 0;
> + CHECK (get_xstate_features_mask (context, &features));
> + DWORD64 zeroed_features = xstate_features & ~features;
> +
> + for (int f = X86_XSTATE_AVX_ID; f <= X86_XSTATE_CET_U_ID; f++)
> + {
> + DWORD64 flag = 1ULL << f;
> + if ((zeroed_features & flag) != 0)
> + {
> + DWORD size = 0;
> + void *loc = locate_xstate_feature (context, f, &size);
> + if (loc != nullptr && size > 0)
> + memset (loc, 0, size);
> + }
> + }
> + }
> }
> });
> }
> @@ -198,6 +227,14 @@ x86_windows_nat_target::thread_context_continue
> (windows_thread_info *th,
> if (GetExitCodeThread (th->h, &ec)
> && ec == STILL_ACTIVE)
> {
> + DWORD debug_registers =
> WindowsContext<decltype(context)>::debug;
> + if (xstate_features != 0
> + && (context->ContextFlags & ~debug_registers) != 0)
> + {
> + context->ContextFlags |= CONTEXT_XSTATE_FLAG;
> + set_xstate_features_mask (context, xstate_features);
> + }
> +
> BOOL status = set_thread_context (th->h, context);
>
> if (!killed)
> @@ -227,7 +264,7 @@ x86_windows_nat_target::thread_context_step
> (windows_thread_info *th,
>
> template<typename Context>
> static char *
> -get_context_reg_ptr (Context *context, int r)
> +get_context_reg_ptr (Context *context, int r, i386_gdbarch_tdep *tdep)
> {
> const int *mappings;
> int mappings_count;
> @@ -247,6 +284,54 @@ get_context_reg_ptr (Context *context, int r)
> char *context_offset;
> if (r < mappings_count)
> context_offset = (char *) context + mappings[r];
> + else if (I387_ZMM0H_REGNUM (tdep) > 0 && r >= I387_ZMM0H_REGNUM
> (tdep)
> + && r < I387_ZMM16H_REGNUM (tdep) && r <
> I387_ZMMENDH_REGNUM (tdep))
> + {
> + context_offset = (char *) locate_xstate_feature
> + (context, X86_XSTATE_ZMM_H_ID, NULL);
> + context_offset += 32 * (r - I387_ZMM0H_REGNUM (tdep));
> + }
> + else if (I387_ZMM0H_REGNUM (tdep) > 0 && r >= I387_ZMM16H_REGNUM
> (tdep)
> + && r < I387_ZMMENDH_REGNUM (tdep))
> + {
> + context_offset = (char *) locate_xstate_feature
> + (context, X86_XSTATE_ZMM_ID, NULL);
> + context_offset += 32 + 64 * (r - I387_ZMM16H_REGNUM (tdep));
> + }
> + else if (I387_K0_REGNUM (tdep) > 0 && r >= I387_K0_REGNUM (tdep)
> + && r < I387_KEND_REGNUM (tdep))
> + {
> + context_offset = (char *) locate_xstate_feature
> + (context, X86_XSTATE_K_ID, NULL);
> + context_offset += 8 * (r - I387_K0_REGNUM (tdep));
> + }
> + else if (I387_YMM16H_REGNUM (tdep) > 0 && r >=
> I387_YMM16H_REGNUM (tdep)
> + && r < I387_YMMH_AVX512_END_REGNUM (tdep))
> + {
> + context_offset = (char *) locate_xstate_feature
> + (context, X86_XSTATE_ZMM_ID, NULL);
> + context_offset += 16 + 64 * (r - I387_YMM16H_REGNUM (tdep));
> + }
> + else if (I387_XMM16_REGNUM (tdep) > 0 && r >= I387_XMM16_REGNUM
> (tdep)
> + && r < I387_XMM_AVX512_END_REGNUM (tdep))
> + {
> + context_offset = (char *) locate_xstate_feature
> + (context, X86_XSTATE_ZMM_ID, NULL);
> + context_offset += 64 * (r - I387_XMM16_REGNUM (tdep));
> + }
> + else if (I387_YMM0H_REGNUM (tdep) > 0 && r >= I387_YMM0H_REGNUM
> (tdep)
> + && r < I387_YMMENDH_REGNUM (tdep))
> + {
> + context_offset = (char *) locate_xstate_feature
> + (context, X86_XSTATE_AVX_ID, NULL);
> + context_offset += 16 * (r - I387_YMM0H_REGNUM (tdep));
> + }
> + else if (tdep->ssp_regnum > 0 && r == tdep->ssp_regnum)
> + {
> + context_offset = (char *) locate_xstate_feature
> + (context, X86_XSTATE_CET_U_ID, NULL);
> + context_offset += 8;
> + }
> else
> gdb_assert_not_reached ("invalid register number %d", r);
>
> @@ -267,7 +352,7 @@ x86_windows_nat_target::fetch_one_register (struct
> regcache *regcache,
> char *context_offset
> = x86_windows_process.with_context (th, [&] (auto *context)
> {
> - return get_context_reg_ptr (context, r);
> + return get_context_reg_ptr (context, r, tdep);
> });
>
> gdb_assert (!gdbarch_read_pc_p (gdbarch)); @@ -333,7 +418,7 @@
> x86_windows_nat_target::store_one_register (const struct regcache
> *regcache,
> = x86_windows_process.with_context (th, [&] (auto *context)
> {
> gdb_assert (context->ContextFlags != 0);
> - return get_context_reg_ptr (context, r);
> + return get_context_reg_ptr (context, r, tdep);
> });
>
> /* GDB treats some registers as 32-bit, where they are in fact only @@ -
> 368,6 +453,23 @@ x86_windows_nat_target::is_sw_breakpoint (const
> EXCEPTION_RECORD *er) const
> || er->ExceptionCode == STATUS_WX86_BREAKPOINT); }
>
> +const struct target_desc *
> +x86_windows_nat_target::read_description () {
> + if (inferior_ptid == null_ptid)
> + return this->beneath ()->read_description ();
> +
> + if (xstate_features == 0)
> + return nullptr;
> +
> +#ifdef __x86_64__
> + if (!x86_windows_process.wow64_process)
> + return amd64_target_description (xstate_features, false);
> + else
> +#endif
> + return i386_target_description (xstate_features, false); }
> +
> /* Hardware watchpoint support, adapted from go32-nat.c code. */
>
> /* Pass the address ADDR to the inferior in the I'th debug register.
> --
> 2.54.0
>
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
next prev parent reply other threads:[~2026-08-26 14:29 UTC|newest]
Thread overview: 27+ 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-08-21 18:03 ` Tom Tromey
2026-08-21 18:37 ` Hannes Domani
2026-08-22 1:14 ` Tom Tromey
2026-07-27 17:42 ` [PATCH v2 3/8] Windows gdb: Remove mappings member from windows_per_inferior Hannes Domani
2026-08-21 18:06 ` Tom Tromey
2026-07-27 17:42 ` [PATCH v2 4/8] Windows gdb: Refactor getting pointer to register inside context Hannes Domani
2026-08-21 18:27 ` Tom Tromey
2026-07-27 17:42 ` [PATCH v2 5/8] Windows gdb: Prepare XState functions Hannes Domani
2026-08-21 18:22 ` Tom Tromey
2026-07-27 17:42 ` [PATCH v2 6/8] Windows gdb: Get available XState features Hannes Domani
2026-08-21 18:37 ` Tom Tromey
2026-07-27 17:42 ` [PATCH v2 7/8] Windows gdb: Implement XState (Intel AVX) support Hannes Domani
2026-08-10 17:25 ` Hannes Domani
2026-08-13 6:39 ` Joos, Christina
2026-08-26 14:28 ` Joos, Christina [this message]
2026-08-26 15:20 ` Hannes Domani
2026-08-27 10:42 ` Joos, Christina
2026-08-27 14:20 ` Hannes Domani
2026-08-27 15:17 ` Joos, Christina
2026-08-27 16:05 ` Hannes Domani
2026-08-27 16:30 ` Joos, Christina
2026-07-27 17:42 ` [PATCH v2 8/8] Windows gdbserver: " Hannes Domani
2026-08-12 22:00 ` [PATCH v2 1/8] gdb/testsuite: Add Windows replacement for aligned_alloc Luis
2026-08-12 22:08 ` Hannes Domani
2026-08-21 17:56 ` Tom Tromey
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=SN7PR11MB7638D75A111388607FC684BD89AE2@SN7PR11MB7638.namprd11.prod.outlook.com \
--to=christina.joos@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=ssbssa@yahoo.de \
/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