]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Windows gdb: Introduce continue_last_debug_event_main_thread
authorPedro Alves <pedro@palves.net>
Thu, 21 Oct 2021 17:16:58 +0000 (18:16 +0100)
committerPedro Alves <pedro@palves.net>
Fri, 24 Apr 2026 20:28:44 +0000 (21:28 +0100)
We have code using do_synchronously to call continue_last_debug_event,
and later patches in the series would need to add the same code in few
more places.  Factor it out to a continue_last_debug_event_main_thread
function so these other places in future patches can just call it.

Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I945e668d2b3daeb9de968219925a7b3c7c7ce9ed
commit-id:ee04461a

gdb/windows-nat.c
gdb/windows-nat.h

index 468f451595d230b3ac377147969b823e4fa0eefd..174b54eda78c2307e14fc1836f67fd8bdb10a0a3 100644 (file)
@@ -261,6 +261,28 @@ windows_nat_target::wait_for_debug_event_main_thread (DEBUG_EVENT *event)
   m_continued = false;
 }
 
+void
+windows_nat_target::continue_last_debug_event_main_thread
+  (const char *context_str, DWORD continue_status, bool last_call)
+{
+  std::optional<unsigned> err;
+  do_synchronously ([&] ()
+    {
+      if (!continue_last_debug_event (continue_status, debug_events))
+       err = (unsigned) GetLastError ();
+
+      /* On the last call, do not block waiting for an event that will
+        never come.  */
+      return !last_call;
+    });
+  if (err.has_value ())
+    throw_winerror_with_name (string_printf (_("ContinueDebugEvent failed: %s"),
+                                            context_str).c_str (),
+                             *err);
+
+  m_continued = !last_call;
+}
+
 /* See nat/windows-nat.h.  */
 
 windows_thread_info *
@@ -711,22 +733,9 @@ windows_nat_target::windows_continue (DWORD continue_status, int id,
        th->resume ();
       }
 
-  std::optional<unsigned> err;
-  do_synchronously ([&] ()
-    {
-      if (!continue_last_debug_event (continue_status, debug_events))
-       err = (unsigned) GetLastError ();
-      /* On the last call, do not block waiting for an event that will
-        never come.  */
-      return !last_call;
-    });
-
-  if (err.has_value ())
-    throw_winerror_with_name (_("Failed to resume program execution"
-                               " - ContinueDebugEvent failed"),
-                             *err);
-
-  m_continued = !last_call;
+  continue_last_debug_event_main_thread
+    (_("Failed to resume program execution"), continue_status,
+     last_call);
 
   return TRUE;
 }
@@ -1188,7 +1197,7 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 
              /* All-stop, suspend all threads until they are
                 explicitly resumed.  */
-             for (auto &thr : windows_process.thread_list)
+             for (auto &thr : windows_process->thread_list)
                thr->suspend ();
            }
 
index 2907d97d6550dd8fa02fb954c5c3b845dbb69622..8866408567ce8648a39663ddc30bc9807ba28b3f 100644 (file)
@@ -249,6 +249,12 @@ private:
      needed.  */
   void wait_for_debug_event_main_thread (DEBUG_EVENT *event);
 
+  /* This continues the last debug event, dispatching to the worker
+     thread as needed.  */
+  void continue_last_debug_event_main_thread (const char *context_str,
+                                             DWORD continue_status,
+                                             bool last_call = false);
+
   /* Force the process_thread thread to return from WaitForDebugEvent.
      PROCESS_ALIVE is set to false if the inferior process exits while
      we're trying to break out the process_thread thread.  This can