}
+ 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);
+
+ if (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);
+
+ // Print out some information.
+ fprintf(stderr, "debugger listening on port %d\r\n", debug_port);
+ }
+
+
+ static void EnableDebug2(EV_P_ ev_async *watcher, int revents) {
+ assert(watcher == &enable_debug);
+ assert(revents == EV_ASYNC);
+ EnableDebug(false);
+ }
+
+
+#ifdef __POSIX__
+
static int RegisterSignalHandler(int signal, void (*handler)(int)) {
struct sigaction sa;
}
if (process.argv[1]) {
- // Load module
- if ('/\\'.indexOf(process.argv[1].charAt(0)) < 0
- && process.argv[1].charAt(1) != ':'
- && !(/^http:\/\//).exec(process.argv[1])) {
- process.argv[1] = path.join(cwd, process.argv[1]);
+
+ if (process.argv[1] == 'debug') {
+ // Start the debugger agent
+ var d = requireNative('_debugger');
+ d.start();
+
+ } else {
+ // Load module
- if (process.argv[1].charAt(0) != '/' &&
- !(/^http:\/\//).exec(process.argv[1])) {
++ if ('/\\'.indexOf(process.argv[1].charAt(0)) < 0
++ && process.argv[1].charAt(1) != ':'
++ && !(/^http:\/\//).exec(process.argv[1])) {
+ process.argv[1] = path.join(cwd, process.argv[1]);
+ }
+ // REMOVEME: nextTick should not be necessary. This hack to get
+ // test/simple/test-exception-handler2.js working.
+ process.nextTick(module.runMain);
}
- // REMOVEME: nextTick should not be necessary. This hack to get
- // test/simple/test-exception-handler2.js working.
- process.nextTick(module.runMain);
} else if (process._eval) {
// -e, --eval