[review] Share some inferior-related Windows code

Tom Tromey (Code Review) gerrit@gnutoolchain-gerrit.osci.io
Tue Nov 26 17:12:00 GMT 2019


Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/717
......................................................................

Share some inferior-related Windows code

This adds a couple of functions to nat/windows-nat.c and changes gdb
and gdbserver to use them.  One function checks the list of pending
stops for a match (not yet used by gdbserver, but will be in a
subsequent patch); and the other is a wrapper for ContinueDebugEvent
that always uses the last "real" stop event.

2019-11-26  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_continue): Use matching_pending_stop and
	continue_last_debug_event.
	* nat/windows-nat.h (matching_pending_stop)
	(continue_last_debug_event): Declare.
	* nat/windows-nat.c (DEBUG_EVENTS): New define.
	(matching_pending_stop, continue_last_debug_event): New
	functions.

gdb/gdbserver/ChangeLog
2019-11-26  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (child_continue): Call continue_last_debug_event.

Change-Id: I5b1d1c89483153891b547de2bc14aa75748b50a4
---
M gdb/ChangeLog
M gdb/gdbserver/ChangeLog
M gdb/gdbserver/win32-low.c
M gdb/nat/windows-nat.c
M gdb/nat/windows-nat.h
M gdb/windows-nat.c
6 files changed, 74 insertions(+), 31 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d2caa25..c4e5f2b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
 2019-11-26  Tom Tromey  <tromey@adacore.com>
 
+	* windows-nat.c (windows_continue): Use matching_pending_stop and
+	continue_last_debug_event.
+	* nat/windows-nat.h (matching_pending_stop)
+	(continue_last_debug_event): Declare.
+	* nat/windows-nat.c (DEBUG_EVENTS): New define.
+	(matching_pending_stop, continue_last_debug_event): New
+	functions.
+
+2019-11-26  Tom Tromey  <tromey@adacore.com>
+
 	* windows-nat.c (MS_VC_EXCEPTION): Move to nat/windows-nat.c.
 	(handle_exception_result): Move to nat/windows-nat.h.
 	(DEBUG_EXCEPTION_SIMPLE): Remove.
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 8ca754b..b31abf1 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,9 @@
 2019-11-26  Tom Tromey  <tromey@adacore.com>
 
+	* win32-low.c (child_continue): Call continue_last_debug_event.
+
+2019-11-26  Tom Tromey  <tromey@adacore.com>
+
 	* win32-low.c (handle_exception): Remove.
 	(windows_nat::handle_ms_vc_exception): New function.
 	(get_child_debug_event): Add "continue_status" parameter.
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index ba49dd9..d41e0e0 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -433,12 +433,7 @@
     });
   faked_breakpoint = 0;
 
-  if (!ContinueDebugEvent (current_event.dwProcessId,
-			   current_event.dwThreadId,
-			   continue_status))
-    return FALSE;
-
-  return TRUE;
+  return continue_last_debug_event (continue_status, debug_threads);
 }
 
 /* Fetch register(s) from the current thread context.  */
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index 1d76f37..81663df 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -33,6 +33,9 @@
 DWORD desired_stop_thread_id = -1;
 std::vector<pending_stop> pending_stops;
 
+/* Note that 'debug_events' must be locally defined in the relevant
+   functions.  */
+#define DEBUG_EVENTS(x)	if (debug_events) debug_printf x
 
 windows_thread_info::~windows_thread_info ()
 {
@@ -293,4 +296,46 @@
 #undef DEBUG_EXCEPTION_SIMPLE
 }
 
+/* See nat/windows-nat.h.  */
+
+bool
+matching_pending_stop (bool debug_events)
+{
+  /* If there are pending stops, and we might plausibly hit one of
+     them, we don't want to actually continue the inferior -- we just
+     want to report the stop.  In this case, we just pretend to
+     continue.  See the comment by the definition of "pending_stops"
+     for details on why this is needed.  */
+  for (const auto &item : pending_stops)
+    {
+      if (desired_stop_thread_id == -1
+	  || desired_stop_thread_id == item.thread_id)
+	{
+	  DEBUG_EVENTS (("windows_continue - pending stop anticipated, "
+			 "desired=0x%x, item=0x%x\n",
+			 desired_stop_thread_id, item.thread_id));
+	  return true;
+	}
+    }
+
+  return false;
+}
+
+/* See nat/windows-nat.h.  */
+
+BOOL
+continue_last_debug_event (DWORD continue_status, bool debug_events)
+{
+  DEBUG_EVENTS (("ContinueDebugEvent (cpid=%d, ctid=0x%x, %s);\n",
+		  (unsigned) last_wait_event.dwProcessId,
+		  (unsigned) last_wait_event.dwThreadId,
+		  continue_status == DBG_CONTINUE ?
+		  "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED"));
+
+  return ContinueDebugEvent (last_wait_event.dwProcessId,
+			     last_wait_event.dwThreadId,
+			     continue_status);
+}
+
+
 }
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 5fd6174..1427885 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -213,6 +213,17 @@
 extern handle_exception_result handle_exception
   (struct target_waitstatus *ourstatus, bool debug_exceptions);
 
+/* Return true if there is a pending stop matching
+   desired_stop_thread_id.  */
+
+extern bool matching_pending_stop (bool debug_events);
+
+/* A simple wrapper for ContinueDebugEvent that continues the last
+   waited-for event.  */
+
+extern BOOL continue_last_debug_event (DWORD continue_status,
+				       bool debug_events);
+
 }
 
 #endif
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 8c690b6..45ba15e 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1106,28 +1106,8 @@
 
   desired_stop_thread_id = id;
 
-  /* If there are pending stops, and we might plausibly hit one of
-     them, we don't want to actually continue the inferior -- we just
-     want to report the stop.  In this case, we just pretend to
-     continue.  See the comment by the definition of "pending_stops"
-     for details on why this is needed.  */
-  for (const auto &item : pending_stops)
-    {
-      if (desired_stop_thread_id == -1
-	  || desired_stop_thread_id == item.thread_id)
-	{
-	  DEBUG_EVENTS (("windows_continue - pending stop anticipated, "
-			 "desired=0x%x, item=0x%x\n",
-			 desired_stop_thread_id, item.thread_id));
-	  return TRUE;
-	}
-    }
-
-  DEBUG_EVENTS (("ContinueDebugEvent (cpid=%d, ctid=0x%x, %s);\n",
-		  (unsigned) last_wait_event.dwProcessId,
-		  (unsigned) last_wait_event.dwThreadId,
-		  continue_status == DBG_CONTINUE ?
-		  "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED"));
+  if (matching_pending_stop (debug_events))
+    return TRUE;
 
   for (windows_thread_info *th : thread_list)
     if (id == -1 || id == (int) th->tid)
@@ -1167,9 +1147,7 @@
 	th->suspend ();
       }
 
-  res = ContinueDebugEvent (last_wait_event.dwProcessId,
-			    last_wait_event.dwThreadId,
-			    continue_status);
+  res = continue_last_debug_event (continue_status, debug_events);
 
   if (!res)
     error (_("Failed to resume program execution"

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I5b1d1c89483153891b547de2bc14aa75748b50a4
Gerrit-Change-Number: 717
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newchange



More information about the Gdb-patches mailing list