+2007-05-10 Pedro Alves <pedro_alves@portugalmail.pt>
+ Leo Zayas <lerele@champenstudios@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.
+
2007-05-10 Pedro Alves <pedro_alves@portugalmail.pt>
* win32-low.c (debug_registers_changed,
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
{
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;
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
{
int cc;
char c = 0;
-
+
cc = read (remote_desc, &c, 1);
if (cc != 1 || c != '\003')
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
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;
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,
};
last_sig = TARGET_SIGNAL_0;
ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
- if (!(debug_event = WaitForDebugEvent (¤t_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 (¤t_event, 250)))
return;
current_inferior =
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)
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)
{
win32_read_inferior_memory,
win32_write_inferior_memory,
NULL,
- NULL,
+ win32_request_interrupt,
NULL,
NULL,
NULL,