Permalink
Browse files

SIGUSR1 should break the VM without delay

  • Loading branch information...
1 parent 5f95d9a commit 4ab5476e89266194d82215214a1a870c9b79e295 @ry ry committed Mar 1, 2011
Showing with 18 additions and 15 deletions.
  1. +18 −15 src/node.cc
View
@@ -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__
}

0 comments on commit 4ab5476

Please sign in to comment.