[13/34] Windows gdb: Factor code out of windows_nat_target::windows_continue

Message ID 20240507234233.371123-14-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
  This factors some code out of windows_nat_target::windows_continue
into a new windows_continue_one function.  This will make the
following patch easier to read (as well as the resulting code itself).

Change-Id: I14a0386b1b8b03015e86273060af173b5130e375
---
 gdb/windows-nat.c | 137 ++++++++++++++++++++++++----------------------
 1 file changed, 72 insertions(+), 65 deletions(-)
  

Comments

Tom Tromey May 8, 2024, 3:18 p.m. UTC | #1
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> This factors some code out of windows_nat_target::windows_continue
Pedro> into a new windows_continue_one function.  This will make the
Pedro> following patch easier to read (as well as the resulting code itself).

Make sense.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 3993820ddab..fb14d8eb55f 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -114,6 +114,9 @@  struct windows_per_inferior : public windows_process_info
 
   void invalidate_context (windows_thread_info *th);
 
+  void continue_one_thread (windows_thread_info *th,
+			    windows_continue_flags cont_flags);
+
   int windows_initialization_done = 0;
 
   std::vector<std::unique_ptr<windows_thread_info>> thread_list;
@@ -1273,6 +1276,74 @@  windows_per_inferior::handle_access_violation
   return false;
 }
 
+void
+windows_per_inferior::continue_one_thread (windows_thread_info *th,
+					   windows_continue_flags cont_flags)
+{
+  struct x86_debug_reg_state *state = x86_debug_reg_state (process_id);
+
+#ifdef __x86_64__
+  if (wow64_process)
+    {
+      if (th->debug_registers_changed)
+	{
+	  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
+#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);
+
+	      if ((cont_flags & WCONT_KILLED) == 0)
+		CHECK (status);
+	    }
+	  th->context.ContextFlags = 0;
+	}
+    }
+  th->resume ();
+}
+
 /* Resume thread specified by ID, or all artificially suspended
    threads, if we are continuing execution.  See
    windows_continue_flags' description for CONT_FLAGS.  */
@@ -1294,71 +1365,7 @@  windows_nat_target::windows_continue (DWORD continue_status, int id,
 
   for (auto &th : windows_process.thread_list)
     if (id == -1 || id == (int) th->tid)
-      {
-	struct x86_debug_reg_state *state
-	  = x86_debug_reg_state (windows_process.process_id);
-
-#ifdef __x86_64__
-	if (windows_process.wow64_process)
-	  {
-	    if (th->debug_registers_changed)
-	      {
-		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
-#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);
-
-		    if ((cont_flags & WCONT_KILLED) == 0)
-		      CHECK (status);
-		  }
-		th->context.ContextFlags = 0;
-	      }
-	  }
-	th->resume ();
-      }
+      windows_process.continue_one_thread (th.get (), cont_flags);
 
   continue_last_debug_event_main_thread
     (_("Failed to resume program execution"), continue_status,