* Re: [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
2026-07-22 15:32 ` [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags Hannes Domani
@ 2026-08-06 16:36 ` Hannes Domani
2026-08-12 19:46 ` Tom Tromey
2026-08-17 0:32 ` Pedro Alves
2 siblings, 0 replies; 7+ messages in thread
From: Hannes Domani @ 2026-08-06 16:36 UTC (permalink / raw)
To: gdb-patches, Pedro Alves
Ping.
Am Mittwoch, 22. Juli 2026 um 17:34:52 MESZ hat Hannes Domani <ssbssa@yahoo.de> Folgendes geschrieben:
> The CONTEXT_DEBUG_REGISTERS also includes the arch-specific bit
> (CONTEXT_i386 or CONTEXT_AMD64) which is included in all CONTEXT_*
> defines.
>
> So this basically just checks if any CONTEXT_* define is set:
> if ((context->ContextFlags & CONTEXT_DEBUG_REGISTERS) != 0)
>
> And similarly, unsetting CONTEXT_DEBUG_REGISTERS removes the
> arch-specific bit as well.
>
> This isn't a problem per-se, since Windows seems to just ignore the
> arch-specific bit anyways in SetThreadContext.
> But it also creates inconsistent behavior for WOW64, because it uses
> the wrong arch-specific bit there.
>
> So this creates a CONTEXT_DEBUG_REG_FLAG define with just the
> debug-registers bit, and uses it in these problematic locations.
> ---
> v2:
> - updated commit message
> - changed CONTEXT_DEBUG_REG_FLAG define to avoid hardcoded number
> ---
> gdb/x86-windows-nat.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/x86-windows-nat.c b/gdb/x86-windows-nat.c
> index 27adeb1f154..2f556e47b39 100644
> --- a/gdb/x86-windows-nat.c
> +++ b/gdb/x86-windows-nat.c
> @@ -42,6 +42,10 @@ enum
>
> #define DR6_CLEAR_VALUE 0xffff0ff0
>
> +/* The CONTEXT_DEBUG_REGISTERS define without the arch-specific bit
> + (CONTEXT_i386 or CONTEXT_AMD64). */
> +#define CONTEXT_DEBUG_REG_FLAG (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_CONTROL)
> +
> struct x86_windows_per_inferior : public windows_per_inferior
> {
> /* The function to use in order to determine whether a register is
> @@ -142,7 +146,7 @@ x86_windows_nat_target::thread_context_continue (windows_thread_info *th,
> {
> windows_process->fill_thread_context (th);
>
> - gdb_assert ((context->ContextFlags & CONTEXT_DEBUG_REGISTERS) != 0);
> + gdb_assert ((context->ContextFlags & CONTEXT_DEBUG_REG_FLAG) != 0);
>
> /* Check whether the thread has Dr6 set indicating a
> watchpoint hit, and we haven't seen the watchpoint event
> @@ -173,13 +177,13 @@ x86_windows_nat_target::thread_context_continue (windows_thread_info *th,
> update the debug registers later when the thread
> is re-resumed by the core after the watchpoint
> event. */
> - context->ContextFlags &= ~CONTEXT_DEBUG_REGISTERS;
> + context->ContextFlags &= ~CONTEXT_DEBUG_REG_FLAG;
> }
> }
> else
> DEBUG_EVENTS ("0x%x has no dr6 set", th->tid);
>
> - if ((context->ContextFlags & CONTEXT_DEBUG_REGISTERS) != 0)
> + if ((context->ContextFlags & CONTEXT_DEBUG_REG_FLAG) != 0)
> {
> DEBUG_EVENTS ("0x%x changing dregs", th->tid);
> context->Dr0 = state->dr_mirror[0];
> --
> 2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
2026-07-22 15:32 ` [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags Hannes Domani
2026-08-06 16:36 ` Hannes Domani
@ 2026-08-12 19:46 ` Tom Tromey
2026-08-12 20:16 ` Hannes Domani
2026-08-17 0:32 ` Pedro Alves
2 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2026-08-12 19:46 UTC (permalink / raw)
To: Hannes Domani; +Cc: gdb-patches
>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
Hannes> So this creates a CONTEXT_DEBUG_REG_FLAG define with just the
Hannes> debug-registers bit, and uses it in these problematic locations.
Looks reasonable to me and I believe it addresses the comments in the
previous review.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
2026-08-12 19:46 ` Tom Tromey
@ 2026-08-12 20:16 ` Hannes Domani
2026-08-13 17:04 ` Tom Tromey
0 siblings, 1 reply; 7+ messages in thread
From: Hannes Domani @ 2026-08-12 20:16 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Am Mittwoch, 12. August 2026 um 21:46:14 MESZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
> >>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
> >
> >Hannes> So this creates a CONTEXT_DEBUG_REG_FLAG define with just the
> >Hannes> debug-registers bit, and uses it in these problematic locations.
> >
> >Looks reasonable to me and I believe it addresses the comments in the
> >previous review.
> >Approved-By: Tom Tromey <tom@tromey.com>
Thanks.
I wonder if it would also be fine for gdb-18.
Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
2026-08-12 20:16 ` Hannes Domani
@ 2026-08-13 17:04 ` Tom Tromey
2026-08-14 11:30 ` Hannes Domani
0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2026-08-13 17:04 UTC (permalink / raw)
To: Hannes Domani; +Cc: Tom Tromey, gdb-patches
>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
Hannes> Am Mittwoch, 12. August 2026 um 21:46:14 MESZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
>> >>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>> >
>> >Hannes> So this creates a CONTEXT_DEBUG_REG_FLAG define with just the
>> >Hannes> debug-registers bit, and uses it in these problematic locations.
>> >
>> >Looks reasonable to me and I believe it addresses the comments in the
>> >previous review.
>> >Approved-By: Tom Tromey <tom@tromey.com>
Hannes> Thanks.
Hannes> I wonder if it would also be fine for gdb-18.
I think it's fine. Thanks.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
2026-08-13 17:04 ` Tom Tromey
@ 2026-08-14 11:30 ` Hannes Domani
0 siblings, 0 replies; 7+ messages in thread
From: Hannes Domani @ 2026-08-14 11:30 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Am Donnerstag, 13. August 2026 um 19:04:34 MESZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
> >>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>
> Hannes> Am Mittwoch, 12. August 2026 um 21:46:14 MESZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
> >> >>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
> >> >
> >> >Hannes> So this creates a CONTEXT_DEBUG_REG_FLAG define with just the
> >> >Hannes> debug-registers bit, and uses it in these problematic locations.
> >> >
> >> >Looks reasonable to me and I believe it addresses the comments in the
> >> >previous review.
> >> >Approved-By: Tom Tromey <tom@tromey.com>
>
> Hannes> Thanks.
> Hannes> I wonder if it would also be fine for gdb-18.
>
> I think it's fine. Thanks.
Pushed to both master and gdb-18-branch, thanks.
Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
2026-07-22 15:32 ` [PATCH v2] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags Hannes Domani
2026-08-06 16:36 ` Hannes Domani
2026-08-12 19:46 ` Tom Tromey
@ 2026-08-17 0:32 ` Pedro Alves
2 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2026-08-17 0:32 UTC (permalink / raw)
To: Hannes Domani, gdb-patches
Sorry for the delay. I'm traveling this week, and last week I thought I would manage to take
a look at this before leaving but something came up that prevented it.
FWIW, this version looks good to me. The note about WOW64 in the commit log is exactly
the sort of thing that we were missing before. Thank you.
Pedro Alves
On 2026-07-22 16:32, Hannes Domani wrote:
> The CONTEXT_DEBUG_REGISTERS also includes the arch-specific bit
> (CONTEXT_i386 or CONTEXT_AMD64) which is included in all CONTEXT_*
> defines.
>
> So this basically just checks if any CONTEXT_* define is set:
> if ((context->ContextFlags & CONTEXT_DEBUG_REGISTERS) != 0)
>
> And similarly, unsetting CONTEXT_DEBUG_REGISTERS removes the
> arch-specific bit as well.
>
> This isn't a problem per-se, since Windows seems to just ignore the
> arch-specific bit anyways in SetThreadContext.
> But it also creates inconsistent behavior for WOW64, because it uses
> the wrong arch-specific bit there.
>
> So this creates a CONTEXT_DEBUG_REG_FLAG define with just the
> debug-registers bit, and uses it in these problematic locations.
> ---
> v2:
> - updated commit message
> - changed CONTEXT_DEBUG_REG_FLAG define to avoid hardcoded number
> ---
> gdb/x86-windows-nat.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/x86-windows-nat.c b/gdb/x86-windows-nat.c
> index 27adeb1f154..2f556e47b39 100644
> --- a/gdb/x86-windows-nat.c
> +++ b/gdb/x86-windows-nat.c
> @@ -42,6 +42,10 @@ enum
>
> #define DR6_CLEAR_VALUE 0xffff0ff0
>
> +/* The CONTEXT_DEBUG_REGISTERS define without the arch-specific bit
> + (CONTEXT_i386 or CONTEXT_AMD64). */
> +#define CONTEXT_DEBUG_REG_FLAG (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_CONTROL)
> +
> struct x86_windows_per_inferior : public windows_per_inferior
> {
> /* The function to use in order to determine whether a register is
> @@ -142,7 +146,7 @@ x86_windows_nat_target::thread_context_continue (windows_thread_info *th,
> {
> windows_process->fill_thread_context (th);
>
> - gdb_assert ((context->ContextFlags & CONTEXT_DEBUG_REGISTERS) != 0);
> + gdb_assert ((context->ContextFlags & CONTEXT_DEBUG_REG_FLAG) != 0);
>
> /* Check whether the thread has Dr6 set indicating a
> watchpoint hit, and we haven't seen the watchpoint event
> @@ -173,13 +177,13 @@ x86_windows_nat_target::thread_context_continue (windows_thread_info *th,
> update the debug registers later when the thread
> is re-resumed by the core after the watchpoint
> event. */
> - context->ContextFlags &= ~CONTEXT_DEBUG_REGISTERS;
> + context->ContextFlags &= ~CONTEXT_DEBUG_REG_FLAG;
> }
> }
> else
> DEBUG_EVENTS ("0x%x has no dr6 set", th->tid);
>
> - if ((context->ContextFlags & CONTEXT_DEBUG_REGISTERS) != 0)
> + if ((context->ContextFlags & CONTEXT_DEBUG_REG_FLAG) != 0)
> {
> DEBUG_EVENTS ("0x%x changing dregs", th->tid);
> context->Dr0 = state->dr_mirror[0];
^ permalink raw reply [flat|nested] 7+ messages in thread