diff options
-rw-r--r-- | gdb/gdbserver/ChangeLog | 19 | ||||
-rw-r--r-- | gdb/gdbserver/remote-utils.c | 28 | ||||
-rw-r--r-- | gdb/gdbserver/server.h | 1 | ||||
-rw-r--r-- | gdb/gdbserver/win32-low.c | 49 |
4 files changed, 86 insertions, 11 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 028da2e864f..4ccec232a4e 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,4 +1,23 @@ 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, debug_registers_used, CONTEXT_EXTENDED_REGISTERS, diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 3c0e5e47282..505e37c907d 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -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 diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h index d433f308378..b1ff238f4d6 100644 --- a/gdb/gdbserver/server.h +++ b/gdb/gdbserver/server.h @@ -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); diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index 51b1915ee84..736d85e05b0 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -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_waitstatus *ourstatus) 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 = @@ -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 memaddr, const unsigned char *myaddr, 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_ops = { win32_read_inferior_memory, win32_write_inferior_memory, NULL, - NULL, + win32_request_interrupt, NULL, NULL, NULL, |