]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Windows gdb: Factor code out of windows_nat_target::windows_continue
authorPedro Alves <pedro@palves.net>
Tue, 9 May 2023 19:34:50 +0000 (20:34 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 9 Jun 2025 17:09:13 +0000 (18:09 +0100)
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).

Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I14a0386b1b8b03015e86273060af173b5130e375

gdb/windows-nat.c

index f3c05067a7463a9edbf0487c7052c647b9a38087..f954048dffe91a8227a7548c6120eda575f1145c 100644 (file)
@@ -116,6 +116,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;
@@ -1217,6 +1220,44 @@ 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);
+
+  windows_process.with_context (th, [&] (auto *context)
+    {
+      if (th->debug_registers_changed)
+       {
+         context->ContextFlags |= WindowsContext<decltype(context)>::debug;
+         context->Dr0 = state->dr_mirror[0];
+         context->Dr1 = state->dr_mirror[1];
+         context->Dr2 = state->dr_mirror[2];
+         context->Dr3 = state->dr_mirror[3];
+         context->Dr6 = DR6_CLEAR_VALUE;
+         context->Dr7 = state->dr_control_mirror;
+         th->debug_registers_changed = false;
+       }
+      if (context->ContextFlags)
+       {
+         DWORD ec = 0;
+
+         if (GetExitCodeThread (th->h, &ec)
+             && ec == STILL_ACTIVE)
+           {
+             BOOL status = set_thread_context (th->h, context);
+
+             if ((cont_flags & WCONT_KILLED) == 0)
+               CHECK (status);
+           }
+         context->ContextFlags = 0;
+       }
+    });
+
+  th->resume ();
+}
+
 /* Resume thread specified by ID, or all artificially suspended
    threads, if we are continuing execution.  See description of
    windows_continue_flags for CONT_FLAGS.  */
@@ -1238,42 +1279,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);
-
-       windows_process.with_context (th.get (), [&] (auto *context)
-         {
-           if (th->debug_registers_changed)
-             {
-               context->ContextFlags
-                 |= WindowsContext<decltype(context)>::debug;
-               context->Dr0 = state->dr_mirror[0];
-               context->Dr1 = state->dr_mirror[1];
-               context->Dr2 = state->dr_mirror[2];
-               context->Dr3 = state->dr_mirror[3];
-               context->Dr6 = DR6_CLEAR_VALUE;
-               context->Dr7 = state->dr_control_mirror;
-               th->debug_registers_changed = false;
-             }
-           if (context->ContextFlags)
-             {
-               DWORD ec = 0;
-
-               if (GetExitCodeThread (th->h, &ec)
-                   && ec == STILL_ACTIVE)
-                 {
-                   BOOL status = set_thread_context (th->h, context);
-
-                   if ((cont_flags & WCONT_KILLED) == 0)
-                     CHECK (status);
-                 }
-               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,