debugger: wake up the event loop when a debugger command is dispatched

When the event loop was blocked in epoll / kqueue or similar, debugger
commands wouldn't be processed. This patch fixes that by adding an
uv_async handle which is triggered when a debugger command is
dispatched. The async handle's callback makes sure that V8 is entered.

Closes GH-3626
Closes GH-3718
pull/24503/head
Peter Rybin 2012-07-03 23:21:37 +04:00 committed by Bert Belder
parent e06b5d7af7
commit 688859afc0
1 changed files with 24 additions and 0 deletions

View File

@ -2471,11 +2471,35 @@ static void ParseArgs(int argc, char **argv) {
static Isolate* node_isolate = NULL; static Isolate* node_isolate = NULL;
static volatile bool debugger_running = false; 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) { static void EnableDebug(bool wait_connect) {
// If we're called from another thread, make sure to enter the right // If we're called from another thread, make sure to enter the right
// v8 isolate. // v8 isolate.
node_isolate->Enter(); 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. // Start the debug thread and it's associated TCP server on port 5858.
bool r = v8::Debug::EnableAgent("node " NODE_VERSION, bool r = v8::Debug::EnableAgent("node " NODE_VERSION,
debug_port, debug_port,