This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gdbserver/win32] Interrupt support.


Hi all,

This patch is in essence the same patch Leo Zayas sent a few months ago,
updated to current cvs, and should be applied on top of the other patches
I just sent before.

Leo, I just moved the 'valid socket' test into
check_remote_input_interrupt_request, and munged win32_request_interrupt
to make it easier to add alternative interruption methods at the bottom
later on.

OK?

Cheers,
Pedro Alves


2007-04-05  Pedro Alves  <pedro_alves@portugalmail.pt>
	    Leo Zayas  <lerele ta champenstudios tod com>

	* server.h (check_remote_input_interrupt_request): New function.
	* remote_utils.c (INVALID_DESCRIPTOR): New define.
	(remote_desc): Initialize with INVALID_DESCRIPTOR.
	(input_interrupt): Expose on USE_WIN32API too.  Fix whitespace.
	(check_remote_input_interrupt_request): New function.
	* server.h (check_remote_input_interrupt_request): Declare.

	* win32-low.(winapi_DebugBreakProcess,
	winapi_GenerateConsoleCtrlEvent): New typedefs.
	(get_child_debug_event): Lower Win32 debug event polling from 1 sec
	to 250 ms.
	(win32_wait): Check for remote interrupt request
	with check_remote_input_interrupt_request.
	(win32_request_interrupt): New function.
	(win32_target_op): Set request_interrupt to win32_request_interrupt.

---
 gdb/gdbserver/remote-utils.c |   28 +++++++++++++++++++-----
 gdb/gdbserver/server.h       |    1 
 gdb/gdbserver/win32-low.c    |   49 ++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 67 insertions(+), 11 deletions(-)

Index: src/gdb/gdbserver/remote-utils.c
===================================================================
--- src.orig/gdb/gdbserver/remote-utils.c	2007-05-08 02:22:48.000000000 +0100
+++ src/gdb/gdbserver/remote-utils.c	2007-05-08 02:57:24.000000000 +0100
@@ -70,6 +70,12 @@
 typedef int socklen_t;
 #endif
 
+#if USE_WIN32API
+# define INVALID_DESCRIPTOR INVALID_SOCKET
+#else
+# define INVALID_DESCRIPTOR -1
+#endif
+
 /* A cache entry for a successfully looked-up symbol.  */
 struct sym_cache
 {
@@ -88,7 +94,7 @@ int all_symbols_looked_up;
 int remote_debug = 0;
 struct ui_file *gdb_stdlog;
 
-static int remote_desc;
+static int remote_desc = INVALID_DESCRIPTOR;
 
 /* FIXME headerize? */
 extern int using_threads;
@@ -588,8 +594,6 @@ putpkt (char *buf)
   return putpkt_binary (buf, strlen (buf));
 }
 
-#ifndef USE_WIN32API
-
 /* Come here when we get an input interrupt from the remote side.  This
    interrupt should only be active while we are waiting for the child to do
    something.  About the only thing that should come through is a ^C, which
@@ -610,7 +614,7 @@ input_interrupt (int unused)
     {
       int cc;
       char c = 0;
-      
+
       cc = read (remote_desc, &c, 1);
 
       if (cc != 1 || c != '\003')
@@ -619,11 +623,23 @@ input_interrupt (int unused)
 		   cc, c, c);
 	  return;
 	}
-      
+
       (*the_target->request_interrupt) ();
     }
 }
-#endif
+
+/* Check if the remote side sent us an interrupt request (^C).  */
+void
+check_remote_input_interrupt_request (void)
+{
+  /* This function may be called before establishing communications,
+     therefore we need to validate the remote descriptor.  */
+
+  if (remote_desc == INVALID_DESCRIPTOR)
+    return;
+
+  input_interrupt (0);
+}
 
 /* Asynchronous I/O support.  SIGIO must be enabled when waiting, in order to
    accept Control-C from the client, and must be disabled when talking to
Index: src/gdb/gdbserver/server.h
===================================================================
--- src.orig/gdb/gdbserver/server.h	2007-05-08 02:22:48.000000000 +0100
+++ src/gdb/gdbserver/server.h	2007-05-08 02:57:24.000000000 +0100
@@ -161,6 +161,7 @@ void enable_async_io (void);
 void disable_async_io (void);
 void unblock_async_io (void);
 void block_async_io (void);
+void check_remote_input_interrupt_request (void);
 void convert_ascii_to_int (char *from, unsigned char *to, int n);
 void convert_int_to_ascii (unsigned char *from, char *to, int n);
 void new_thread_notify (int id);
Index: src/gdb/gdbserver/win32-low.c
===================================================================
--- src.orig/gdb/gdbserver/win32-low.c	2007-05-08 02:28:16.000000000 +0100
+++ src/gdb/gdbserver/win32-low.c	2007-05-08 02:57:24.000000000 +0100
@@ -77,6 +77,8 @@ static DEBUG_EVENT current_event;
 
 typedef BOOL WINAPI (*winapi_DebugActiveProcessStop) (DWORD dwProcessId);
 typedef BOOL WINAPI (*winapi_DebugSetProcessKillOnExit) (BOOL KillOnExit);
+typedef BOOL WINAPI (*winapi_DebugBreakProcess) (HANDLE);
+typedef BOOL WINAPI (*winapi_GenerateConsoleCtrlEvent) (DWORD, DWORD);
 
 static DWORD main_thread_id = 0;
 
@@ -208,9 +210,8 @@ enum target_waitkind
      pathname is pointed to by value.execd_pathname.  */
   TARGET_WAITKIND_EXECD,
 
-  /* Nothing happened, but we stopped anyway.  This perhaps should be handled
-     within target_wait, but I'm not sure target_wait should be resuming the
-     inferior.  */
+  /* Nothing interesting happened, but we stopped anyway.  We take the
+     chance to check if GDB requested an interrupt.  */
   TARGET_WAITKIND_SPURIOUS,
 };
 
@@ -879,7 +880,9 @@ get_child_debug_event (struct target_wai
   last_sig = TARGET_SIGNAL_0;
   ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
 
-  if (!(debug_event = WaitForDebugEvent (&current_event, 1000)))
+  /* Keep the wait time low enough for confortable remote interruption,
+     but high enough so gdbserver doesn't become a bottleneck.  */
+  if (!(debug_event = WaitForDebugEvent (&current_event, 250)))
     return;
 
   current_inferior =
@@ -1007,6 +1010,9 @@ win32_wait (char *status)
 
   while (1)
     {
+      /* Check if GDB sent us an interrupt request.  */
+      check_remote_input_interrupt_request ();
+
       get_child_debug_event (&our_status);
 
       switch (our_status.kind)
@@ -1078,6 +1084,39 @@ win32_write_inferior_memory (CORE_ADDR m
   return child_xfer_memory (memaddr, (char *) myaddr, len, 1, 0) != len;
 }
 
+/* Send an interrupt request to the inferior process. */
+static void
+win32_request_interrupt (void)
+{
+  winapi_DebugBreakProcess DebugBreakProcess;
+  winapi_GenerateConsoleCtrlEvent GenerateConsoleCtrlEvent;
+
+#ifdef _WIN32_WCE
+  HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
+#else
+  HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
+#endif
+
+  GenerateConsoleCtrlEvent = GETPROCADDRESS (dll, GenerateConsoleCtrlEvent);
+
+  if (GenerateConsoleCtrlEvent != NULL
+      && GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, current_process_id))
+    return;
+
+  /* GenerateConsoleCtrlEvent can fail if process id being debugged is
+     not a process group id.
+     Fallback to XP/Vista 'DebugBreakProcess', which generates a
+     breakpoint exception in the interior process.  */
+
+  DebugBreakProcess = GETPROCADDRESS (dll, DebugBreakProcess);
+
+  if (DebugBreakProcess != NULL
+      && DebugBreakProcess (current_process_handle))
+    return;
+
+  OUTMSG (("Could not interrupt process.\n"));
+}
+
 static const char *
 win32_arch_string (void)
 {
@@ -1098,7 +1137,7 @@ static struct target_ops win32_target_op
   win32_read_inferior_memory,
   win32_write_inferior_memory,
   NULL,
-  NULL,
+  win32_request_interrupt,
   NULL,
   NULL,
   NULL,



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]