SIGUSR1 should break the VM without delay
authorRyan Dahl <ry@tinyclouds.org>
Tue, 1 Mar 2011 17:59:17 +0000 (09:59 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Tue, 1 Mar 2011 17:59:17 +0000 (09:59 -0800)
src/node.cc

index 01bd561..b05e9ac 100644 (file)
@@ -96,7 +96,6 @@ static ev_idle tick_spinner;
 static bool need_tick_cb;
 static Persistent<String> tick_callback_sym;
 
-static ev_async enable_debug;
 static ev_async eio_want_poll_notifier;
 static ev_async eio_done_poll_notifier;
 static ev_idle  eio_poller;
@@ -1746,6 +1745,7 @@ static void DebugBreakMessageHandler(const Debug::Message& message) {
   // debug-agent.cc of v8/src when a new session is created
 }
 
+
 Persistent<Object> binding_cache;
 
 static Handle<Value> Binding(const Arguments& args) {
@@ -2174,13 +2174,6 @@ static void SignalExit(int signal) {
 }
 
 
-static void EnableDebugSignalHandler(int signal) {
-  // can't do much here, marshal this back into the main thread where we'll
-  // enable the debugger.
-  ev_async_send(EV_DEFAULT_UC_ &enable_debug);
-}
-
-
 static void EnableDebug(bool wait_connect) {
   // Start the debug thread and it's associated TCP server on port 5858.
   bool r = Debug::EnableAgent("node " NODE_VERSION, debug_port);
@@ -2201,10 +2194,22 @@ static void EnableDebug(bool wait_connect) {
 }
 
 
-static void EnableDebug2(EV_P_ ev_async *watcher, int revents) {
-  assert(watcher == &enable_debug);
-  assert(revents == EV_ASYNC);
-  EnableDebug(false);
+static volatile bool hit_signal;
+
+
+static void EnableDebugSignalHandler(int signal) {
+  // This is signal safe.
+  hit_signal = true;
+  v8::Debug::DebugBreak();
+}
+
+
+static void DebugSignalCB(const Debug::EventDetails& details) {
+  if (hit_signal && details.GetEvent() == v8::Break) {
+    hit_signal = false;
+    fprintf(stderr, "Hit SIGUSR1 - starting debugger agent.\n");
+    EnableDebug(false);
+  }
 }
 
 
@@ -2345,9 +2350,7 @@ int Start(int argc, char *argv[]) {
   } else {
 #ifdef __POSIX__
     RegisterSignalHandler(SIGUSR1, EnableDebugSignalHandler);
-    ev_async_init(&enable_debug, EnableDebug2);
-    ev_async_start(EV_DEFAULT_UC_ &enable_debug);
-    ev_unref(EV_DEFAULT_UC);
+    Debug::SetDebugEventListener2(DebugSignalCB);
 #endif // __POSIX__
   }