[11/34] Windows gdb: Introduce continue_last_debug_event_main_thread

Message ID 20240507234233.371123-12-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
  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.

Change-Id: I945e668d2b3daeb9de968219925a7b3c7c7ce9ed
---
 gdb/windows-nat.c | 46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)
  

Comments

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

Pedro> We have code using do_synchronously to call continue_last_debug_event,
Pedro> and later patches in the series would need to add the same code in few
Pedro> more places.  Factor it out to a continue_last_debug_event_main_thread
Pedro> function so these other places in future patches can just call it.

This seems reasonable but I noticed:

Pedro> +void
Pedro> +windows_nat_target::continue_last_debug_event_main_thread
Pedro> +  (const char *context_str, DWORD continue_status, bool last_call)
Pedro> +{
...
Pedro> +  if (err.has_value ())
Pedro> +    throw_winerror_with_name (_("ContinueDebugEvent failed"),
Pedro> +			      *err);

context_str isn't used in the body of the method.

Tom
  

Patch

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index aa531c4208a..93ba7850c88 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -354,6 +354,12 @@  struct windows_nat_target final : public x86_nat_target<inf_child_target>
      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
@@ -512,6 +518,27 @@  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 (_("ContinueDebugEvent failed"),
+			      *err);
+
+  m_continued = !last_call;
+}
+
 /* See nat/windows-nat.h.  */
 
 windows_thread_info *
@@ -1319,22 +1346,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;
 }