From dc8c079d904abc6d01357e70d72c9de7bacd7c1a Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Sun, 1 Aug 2010 16:46:48 -0600 Subject: [PATCH] remove node::CheckBreak in favor of using the v8 debugger js object --- lib/module.js | 4 +++- src/node.cc | 67 ++++++++++++++++++++++------------------------------------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/lib/module.js b/lib/module.js index 3e005f4..72814a7 100644 --- a/lib/module.js +++ b/lib/module.js @@ -420,7 +420,9 @@ Module.prototype._compile = function (content, filename) { + "\n});"; var compiledWrapper = process.compile(wrapper, filename); - if (filename === process.argv[1]) process.checkBreak(); + if (filename === process.argv[1] && global.v8debug) { + global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0); + } compiledWrapper.apply(self.exports, [self.exports, require, self, filename, dirname]); } else { self.exports = content; diff --git a/src/node.cc b/src/node.cc index 81c8fb8..aae8a05 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1426,7 +1426,6 @@ void FatalException(TryCatch &try_catch) { static ev_async debug_watcher; -volatile static bool debugger_msg_pending = false; static void DebugMessageCallback(EV_P_ ev_async *watcher, int revents) { HandleScope scope; @@ -1441,48 +1440,13 @@ static void DebugMessageDispatch(void) { // Send a signal to our main thread saying that it should enter V8 to // handle the message. - debugger_msg_pending = true; ev_async_send(EV_DEFAULT_UC_ &debug_watcher); } -static Handle CheckBreak(const Arguments& args) { - HandleScope scope; - assert(args.Length() == 0); - - // TODO FIXME This function is a hack to wait until V8 is ready to accept - // commands. There seems to be a bug in EnableAgent( _ , _ , true) which - // makes it unusable here. Ideally we'd be able to bind EnableAgent and - // get it to halt until Eclipse connects. - - if (!debug_wait_connect) - return Undefined(); - - printf("Waiting for remote debugger connection...\n"); - - const int halfSecond = 50; - const int tenMs=10000; - debugger_msg_pending = false; - for (;;) { - if (debugger_msg_pending) { - Debug::DebugBreak(); - Debug::ProcessDebugMessages(); - debugger_msg_pending = false; - - // wait for 500 msec of silence from remote debugger - int cnt = halfSecond; - while (cnt --) { - debugger_msg_pending = false; - usleep(tenMs); - if (debugger_msg_pending) { - debugger_msg_pending = false; - cnt = halfSecond; - } - } - break; - } - usleep(tenMs); - } - return Undefined(); +static void DebugBreakMessageHandler(const Debug::Message& message) { + // do nothing with debug messages. + // The message handler will get changed by DebuggerAgent::CreateSession in + // debug-agent.cc of v8/src when a new session is created } Persistent binding_cache; @@ -1626,7 +1590,6 @@ static void Load(int argc, char *argv[]) { NODE_SET_METHOD(process, "dlopen", DLOpen); NODE_SET_METHOD(process, "kill", Kill); NODE_SET_METHOD(process, "memoryUsage", MemoryUsage); - NODE_SET_METHOD(process, "checkBreak", CheckBreak); NODE_SET_METHOD(process, "binding", Binding); @@ -1775,7 +1738,20 @@ int main(int argc, char *argv[]) { node::ParseArgs(&argc, argv); // Parse the rest of the args (up to the 'option_end_index' (where '--' was // in the command line)) - V8::SetFlagsFromCommandLine(&node::option_end_index, argv, false); + int v8argc = node::option_end_index; + char **v8argv = argv; + + if (node::debug_wait_connect) { + // v8argv is a copy of argv up to the script file argument +2 if --debug-brk + // to expose the v8 debugger js object so that module.js can set + // a breakpoint on the first line of the startup script + v8argc += 2; + v8argv = new char*[v8argc]; + memcpy(v8argv, argv, sizeof(argv) * node::option_end_index); + v8argv[node::option_end_index] = const_cast("--expose_debug_as"); + v8argv[node::option_end_index + 1] = const_cast("v8debug"); + } + V8::SetFlagsFromCommandLine(&v8argc, v8argv, false); // Ignore SIGPIPE struct sigaction sa; @@ -1851,6 +1827,13 @@ int main(int argc, char *argv[]) { // Start the debug thread and it's associated TCP server on port 5858. bool r = Debug::EnableAgent("node " NODE_VERSION, node::debug_port); + if (node::debug_wait_connect) { + // Set up an empty handler so v8 will not continue until a debugger + // attaches. This is the same behavior as Debug::EnableAgent(_,_,true) + // except we don't break at the beginning of the script. + // see Debugger::StartAgent in debug.cc of v8/src + Debug::SetMessageHandler2(node::DebugBreakMessageHandler); + } // Crappy check that everything went well. FIXME assert(r); -- 2.7.4