[29/34] windows_per_inferior::continue_one_thread, unify WoW64/non-WoW64 paths

Message ID 20240507234233.371123-30-pedro@palves.net
State New
Headers
Series Windows non-stop mode |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Pedro Alves May 7, 2024, 11:42 p.m. UTC
  Consolidate the WoW64 & non-WoW64 paths in
windows_per_inferior::continue_one_thread to avoid code duplication.

The next patch will add more code to this function, and this
unification avoids writing that new code twice.

Change-Id: I794aadb412a3b8081212e4acf2af80d3edba7392
---
 gdb/windows-nat.c | 68 ++++++++++++++++++++++-------------------------
 1 file changed, 32 insertions(+), 36 deletions(-)
  

Patch

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 6e72f99c3f5..5500d8b8c87 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1288,64 +1288,60 @@  windows_per_inferior::continue_one_thread (windows_thread_info *th,
   struct x86_debug_reg_state *state = x86_debug_reg_state (process_id);
 
 #ifdef __x86_64__
-  if (wow64_process)
+  DWORD &context_flags_ref = (wow64_process
+			      ? th->wow64_context.ContextFlags
+			      : th->context.ContextFlags);
+#else
+  DWORD &context_flags_ref = th->context.ContextFlags;
+#endif
+
+  if (th->debug_registers_changed)
     {
-      if (th->debug_registers_changed)
+      context_flags_ref |= CONTEXT_DEBUG_REGISTERS;
+#ifdef __x86_64__
+      if (wow64_process)
 	{
-	  th->wow64_context.ContextFlags |= CONTEXT_DEBUG_REGISTERS;
 	  th->wow64_context.Dr0 = state->dr_mirror[0];
 	  th->wow64_context.Dr1 = state->dr_mirror[1];
 	  th->wow64_context.Dr2 = state->dr_mirror[2];
 	  th->wow64_context.Dr3 = state->dr_mirror[3];
 	  th->wow64_context.Dr6 = DR6_CLEAR_VALUE;
 	  th->wow64_context.Dr7 = state->dr_control_mirror;
-	  th->debug_registers_changed = false;
 	}
-      if (th->wow64_context.ContextFlags)
-	{
-	  DWORD ec = 0;
-
-	  if (GetExitCodeThread (th->h, &ec)
-	      && ec == STILL_ACTIVE)
-	    {
-	      BOOL status = Wow64SetThreadContext (th->h,
-						   &th->wow64_context);
-
-	      if ((cont_flags & WCONT_KILLED) == 0)
-		CHECK (status);
-	    }
-	  th->wow64_context.ContextFlags = 0;
-	}
-    }
-  else
+      else
 #endif
-    {
-      if (th->debug_registers_changed)
 	{
-	  th->context.ContextFlags |= CONTEXT_DEBUG_REGISTERS;
 	  th->context.Dr0 = state->dr_mirror[0];
 	  th->context.Dr1 = state->dr_mirror[1];
 	  th->context.Dr2 = state->dr_mirror[2];
 	  th->context.Dr3 = state->dr_mirror[3];
 	  th->context.Dr6 = DR6_CLEAR_VALUE;
 	  th->context.Dr7 = state->dr_control_mirror;
-	  th->debug_registers_changed = false;
 	}
-      if (th->context.ContextFlags)
-	{
-	  DWORD ec = 0;
 
-	  if (GetExitCodeThread (th->h, &ec)
-	      && ec == STILL_ACTIVE)
-	    {
-	      BOOL status = SetThreadContext (th->h, &th->context);
+      th->debug_registers_changed = false;
+    }
+  if (context_flags_ref != 0)
+    {
+      DWORD ec = 0;
 
-	      if ((cont_flags & WCONT_KILLED) == 0)
-		CHECK (status);
-	    }
-	  th->context.ContextFlags = 0;
+      if (GetExitCodeThread (th->h, &ec)
+	  && ec == STILL_ACTIVE)
+	{
+	  BOOL status;
+#ifdef __x86_64__
+	  if (wow64_process)
+	    status = Wow64SetThreadContext (th->h, &th->wow64_context);
+	  else
+#endif
+	    status = SetThreadContext (th->h, &th->context);
+
+	  if ((cont_flags & WCONT_KILLED) == 0)
+	    CHECK (status);
 	}
+      context_flags_ref = 0;
     }
+
   th->resume ();
   th->last_sig = GDB_SIGNAL_0;
 }