Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Cortell2010-04-30 10:22:34 -0400
committerJohn Cortell2010-04-30 10:22:34 -0400
commitd76884f42a7c0b041f2dd7f75f3f74d5a0bd6380 (patch)
treefa2092366e20d6d542e98bcdeaa5a99053951a7a /core/org.eclipse.cdt.core.win32/library
parentedf08beb2de3ee7b0d868549f088f0c1fe7d1fa5 (diff)
downloadorg.eclipse.cdt-d76884f42a7c0b041f2dd7f75f3f74d5a0bd6380.tar.gz
org.eclipse.cdt-d76884f42a7c0b041f2dd7f75f3f74d5a0bd6380.tar.xz
org.eclipse.cdt-d76884f42a7c0b041f2dd7f75f3f74d5a0bd6380.zip
Bug 311182: Enhance Spawner JNI code to use DebugBreakProcess when running on >= XP
Diffstat (limited to 'core/org.eclipse.cdt.core.win32/library')
-rw-r--r--core/org.eclipse.cdt.core.win32/library/raise.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.core.win32/library/raise.c b/core/org.eclipse.cdt.core.win32/library/raise.c
index 7ec280960c..20f34d37eb 100644
--- a/core/org.eclipse.cdt.core.win32/library/raise.c
+++ b/core/org.eclipse.cdt.core.win32/library/raise.c
@@ -54,21 +54,55 @@ find_child_console (HWND hwnd, LPARAM arg)
return TRUE;
}
+// Need to declare this Win32 prototype ourselves. _WIN32_WINNT is getting
+// defined to a Windows NT value, thus we don't get this. Can't assume
+// we're running on XP, anyway (or can we by now?)
+#if (_WIN32_WINNT < 0x0501)
+typedef BOOL (WINAPI *DebugBreakProcessFunc)(HANDLE);
+#endif
/////////////////////////////////////////////////////////////////////////////////////
-// Function implements interrupt process (Ctrl-C emulation)
+// Called to interrupt a process that we didn't launch (and thus does not share our
+// console). Windows XP introduced the function 'DebugBreakProcess', which allows
+// a process to interrupt another process even if if the two do not share a console.
+// If we're running on 2000 or earlier, we have to resort to simulating a CTRL-C
+// in the console by firing keyboard events. This will work only if the process
+// has its own console. That means, e.g., the process should have been started at
+// the cmdline with 'start myprogram.exe' instead of 'myprogram.exe'.
+//
// Arguments:
// pid - process' pid
// Return : 0 if OK or error code
/////////////////////////////////////////////////////////////////////////////////////
int interruptProcess(int pid)
{
+ // See if DebugBreakProcess is available (XP and beyond)
+ HMODULE hmod = LoadLibrary(L"Kernel32.dll");
+ if (hmod != NULL)
+ {
+ BOOL success = FALSE;
+ FARPROC procaddr = GetProcAddress(hmod, "DebugBreakProcess");
+ if (procaddr != NULL)
+ {
+ HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
+ if (proc != NULL)
+ {
+ DebugBreakProcessFunc pDebugBreakProcess = (DebugBreakProcessFunc)procaddr;
+ success = (*pDebugBreakProcess)(proc);
+ CloseHandle(proc);
+ }
+ }
+ FreeLibrary(hmod);
+ hmod = NULL;
+
+ if (success == TRUE)
+ return 0; // 0 == OK; if not, try old-school way
+ }
+
#ifdef DEBUG_MONITOR
_TCHAR buffer[1000];
#endif
- int rc;
- // Try another method
- rc = 0;
+ int rc = 0;
consoleHWND = NULL;
#ifdef DEBUG_MONITOR

Back to the top