Ctrl+Break on windows starts debugger server
authorFedor Indutny <fedor.indutny@gmail.com>
Sat, 24 Sep 2011 13:51:59 +0000 (20:51 +0700)
committerRyan Dahl <ry@tinyclouds.org>
Sun, 25 Sep 2011 18:58:23 +0000 (11:58 -0700)
src/node.cc

index f7fa133..4933c0c 100644 (file)
@@ -2362,6 +2362,7 @@ static void EnableDebug(bool wait_connect) {
 }
 
 
+#ifdef __POSIX__
 static void EnableDebugSignalHandler(int signal) {
   // Break once process will return execution to v8
   v8::Debug::DebugBreak();
@@ -2371,6 +2372,23 @@ static void EnableDebugSignalHandler(int signal) {
     EnableDebug(false);
   }
 }
+#endif // __POSIX__
+
+#if defined(__MINGW32__) || defined(_MSC_VER)
+static bool EnableDebugSignalHandler(DWORD signal) {
+  if (signal != CTRL_BREAK_EVENT) return false;
+
+  // Break once process will return execution to v8
+  v8::Debug::DebugBreak();
+
+  if (!debugger_running) {
+    fprintf(stderr, "Hit Ctrl+Break - starting debugger agent.\n");
+    EnableDebug(false);
+  }
+
+  return true;
+}
+#endif
 
 
 #ifdef __POSIX__
@@ -2474,6 +2492,9 @@ char** Init(int argc, char *argv[]) {
 #ifdef __POSIX__
     RegisterSignalHandler(SIGUSR1, EnableDebugSignalHandler);
 #endif // __POSIX__
+#if defined(__MINGW32__) || defined(_MSC_VER)
+    SetConsoleCtrlHandler((PHANDLER_ROUTINE) EnableDebugSignalHandler, TRUE);
+#endif
   }
 
   return argv;