Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@yahoo.de>
To: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>,
	 Pedro Alves <pedro@palves.net>
Subject: Re: [PATCH] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
Date: Mon, 6 Jul 2026 15:01:49 +0000 (UTC)	[thread overview]
Message-ID: <1448496673.3144402.1783350109140@mail.yahoo.com> (raw)
In-Reply-To: <96f2bcf2-96e5-46ea-9931-c9203415a9df () palves ! net>

 It's just great that all your mails are blocked by yahoo...


Am Mittwoch, 1. Juli 2026 um 21:03:09 MESZ hat Pedro Alves <pedro () palves ! net> Folgendes geschrieben:

> On 2026-06-27 15:27, 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 similarily, unsetting CONTEXT_DEBUG_REGISTERS removes the
> 
> similarily => similarly

Right.


> > arch-specific bit as well.
> >
> > So this creates a CONTEXT_DEBUG_REG_FLAG define with just the
> > debug-registers bit, and uses it in these problematic locations.
> 
> How did you notice this?  Like, GDB was misbehaving and you found the
> issue, was it by inspection?  I'd be good to have that info in the commit log.

I noticed because I was doing some changes in that function, and
CONTEXT_DEBUG_REGISTERS stood out to me very quickly, because for WOW64 I
would expect WindowsContext<decltype(context)>::debug to be used instead.


> > ---
> >  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..3368814ed96 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 0x10
> > +
> 
> Did you consider avoiding harcoding numbers, like:
> 
> #ifdef __x86_64__
> # define CONTEXT_ARCH_BIT CONTEXT_AMD64
> #else
> # define CONTEXT_ARCH_BIT CONTEXT_i386
> #endif
> 
> #define CONTEXT_DEBUG_REG_FLAG (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_ARCH_BIT)

I did consider this:

#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;
> 
> My bad, I suppose...
> 
> Does clearing the arch bit make the context be basically as if it was fully zeroed?
> 
> So if we notice we had a pending watchpoint hit, we were not writing _any_ register?
> 
> That was not the original intention, for sure.
> 
> But OTOH, looking back at this, I'm wondering whether that wasn't really the right thing to do.
> If we e.g., change the PC to point elsewhere, and then process the pending watchpoint, we'd want
> to see the PC as it was when the watchpoint triggered, not what it was modified to.  Same for
> other registers, as the watchpoint's value will very likely depend on the state of registers.
> 
> Right?
> 
> OTOH, if e.g., the user did an infcall on a thread that has a pending watchpoint, and we don't
> modify registers, and then the watchpoint doesn't cause a stop, not writing registers means
> we'll not really do the infcall, and the inferior proceeds as if we had done a "continue"...
> Not great either.
> 
> OK, let's just do what you're suggesting until we come up with a better way, as it was the
> original intention.  I'm just curious for more details.

I did some experiments, and it looks like SetThreadContext doesn't care at
all about the arch bit, so it is working like your original intention.
I thought it would fail in the arch bit is missing, but I was wrong about that.


Hannes

       reply	other threads:[~2026-07-06 15:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <96f2bcf2-96e5-46ea-9931-c9203415a9df () palves ! net>
2026-07-06 15:01 ` Hannes Domani [this message]
2026-07-21 15:02   ` Hannes Domani
2026-07-21 16:51     ` Tom Tromey
2026-07-22 12:24       ` Pedro Alves
2026-07-22 13:40         ` Tom Tromey
     [not found] <1310341683.1974283.1784737131422.ref@mail.yahoo.com>
2026-07-22 16:18 ` Hannes Domani
2026-07-23 19:04   ` Pedro Alves
     [not found] <590795675.1923429.1784732125709.ref@mail.yahoo.com>
2026-07-22 14:55 ` Hannes Domani
2026-07-22 15:55   ` Pedro Alves
     [not found] <20260627142740.3995235-1-ssbssa.ref@yahoo.de>
2026-06-27 14:27 ` Hannes Domani
2026-07-01 19:03   ` Pedro Alves

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=1448496673.3144402.1783350109140@mail.yahoo.com \
    --to=ssbssa@yahoo.de \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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