[binutils-gdb/gdb-18-branch] Windows gdb: Fix resetting of the debug-registers bit in ContextFlags

Hannes Domani via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8133bec44fc622bb8f7979441c7be7b24321b6b1

commit 8133bec44fc622bb8f7979441c7be7b24321b6b1
Author: Hannes Domani <[email protected]>
Date:   Thu Jun 25 14:20:51 2026 +0200

    Windows gdb: Fix resetting of the debug-registers bit in ContextFlags
    
    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.
    
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 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];
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.