diff --git a/src/node.cc b/src/node.cc index 05208b44b96..257b96e9eb9 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2471,11 +2471,35 @@ static void ParseArgs(int argc, char **argv) { static Isolate* node_isolate = NULL; static volatile bool debugger_running = false; + +static uv_async_t dispatch_debug_messages_async; + + +// Called from the main thread. +static void DispatchDebugMessagesAsyncCallback(uv_async_t* handle, int status) { + v8::Debug::ProcessDebugMessages(); +} + + +// Called from V8 Debug Agent TCP thread. +static void DispatchMessagesDebugAgentCallback() { + uv_async_send(&dispatch_debug_messages_async); +} + + static void EnableDebug(bool wait_connect) { // If we're called from another thread, make sure to enter the right // v8 isolate. node_isolate->Enter(); + v8::Debug::SetDebugMessageDispatchHandler(DispatchMessagesDebugAgentCallback, + false); + + uv_async_init(uv_default_loop(), + &dispatch_debug_messages_async, + DispatchDebugMessagesAsyncCallback); + uv_unref((uv_handle_t*) &dispatch_debug_messages_async); + // Start the debug thread and it's associated TCP server on port 5858. bool r = v8::Debug::EnableAgent("node " NODE_VERSION, debug_port,