diff options
author | Bert Belder <bertbelder@gmail.com> | 2011-01-05 02:41:59 +0300 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2011-01-05 02:41:59 +0300 |
commit | 3c330b05b10ffabe1b45d06efadc1f4e49830dc7 (patch) | |
tree | fd000a35785793332a3b9490ae55c50b4d91ba3a /src | |
parent | c3ffbf219ca8049c901ec58d4d4b3df5b96c5097 (diff) | |
parent | 131546e7339d6960ea91629915468c6f04a33cf7 (diff) |
Merge branch 'master' of git://github.com/ry/node
Conflicts:
src/node.cc
src/node.js
Diffstat (limited to 'src')
-rw-r--r-- | src/node.cc | 86 | ||||
-rw-r--r-- | src/node.js | 30 | ||||
-rw-r--r-- | src/node_stdio.cc | 4 | ||||
-rw-r--r-- | src/node_version.h | 2 |
4 files changed, 80 insertions, 42 deletions
diff --git a/src/node.cc b/src/node.cc index f42c82481e9..1c0ad34fd4d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -93,6 +93,7 @@ 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; @@ -1909,7 +1910,42 @@ 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); + + 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; @@ -2022,37 +2058,31 @@ int Start(int argc, char *argv[]) { V8::SetFatalErrorHandler(node::OnFatalError); + + // Initialize the async watcher for receiving messages from the debug + // thread and marshal it into the main thread. DebugMessageCallback() + // is called from the main thread to execute a random bit of javascript + // - which will give V8 control so it can handle whatever new message + // had been received on the debug thread. + ev_async_init(&node::debug_watcher, node::DebugMessageCallback); + ev_set_priority(&node::debug_watcher, EV_MAXPRI); + // Set the callback DebugMessageDispatch which is called from the debug + // thread. + Debug::SetDebugMessageDispatchHandler(node::DebugMessageDispatch); + // Start the async watcher. + ev_async_start(EV_DEFAULT_UC_ &node::debug_watcher); + // unref it so that we exit the event loop despite it being active. + ev_unref(EV_DEFAULT_UC); + + // If the --debug flag was specified then initialize the debug thread. if (node::use_debug_agent) { - // Initialize the async watcher for receiving messages from the debug - // thread and marshal it into the main thread. DebugMessageCallback() - // is called from the main thread to execute a random bit of javascript - // - which will give V8 control so it can handle whatever new message - // had been received on the debug thread. - ev_async_init(&node::debug_watcher, node::DebugMessageCallback); - ev_set_priority(&node::debug_watcher, EV_MAXPRI); - // Set the callback DebugMessageDispatch which is called from the debug - // thread. - Debug::SetDebugMessageDispatchHandler(node::DebugMessageDispatch); - // Start the async watcher. - ev_async_start(EV_DEFAULT_UC_ &node::debug_watcher); - // unref it so that we exit the event loop despite it being active. + EnableDebug(debug_wait_connect); + } else { + RegisterSignalHandler(SIGUSR1, EnableDebugSignalHandler); + ev_async_init(&enable_debug, EnableDebug2); + ev_async_start(EV_DEFAULT_UC_ &enable_debug); ev_unref(EV_DEFAULT_UC); - - // 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); - // Print out some information. - printf("debugger listening on port %d\n", node::debug_port); } // Create the one and only Context. diff --git a/src/node.js b/src/node.js index f017d3ab80a..368cc08a95b 100644 --- a/src/node.js +++ b/src/node.js @@ -123,9 +123,8 @@ // Modules - var debugLevel = parseInt(process.env['NODE_DEBUG'], 16); var debug; - if (debugLevel & 1) { + if (process.env.NODE_DEBUG && /module/.test(process.env.NODE_DEBUG)) { debug = function(x) { console.error(x); }; } else { debug = function() { }; @@ -170,7 +169,7 @@ try { var stats = fs.statSync(requestPath); if (stats && !stats.isDirectory()) { - return requestPath; + return fs.realpathSync(requestPath); } } catch (e) {} return false; @@ -278,6 +277,7 @@ if (!filename) { throw new Error("Cannot find module '" + request + "'"); } + id = filename; return [id, filename]; } @@ -545,15 +545,23 @@ } 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 ('/\\'.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 diff --git a/src/node_stdio.cc b/src/node_stdio.cc index c2f5cbb4caa..9c87dc1fb67 100644 --- a/src/node_stdio.cc +++ b/src/node_stdio.cc @@ -49,8 +49,8 @@ static int EnableRawMode(int fd) { /* input modes: no break, no CR to NL, no parity check, no strip char, * no start/stop output control. */ raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); - /* output modes - disable post processing */ - raw.c_oflag &= ~(OPOST); + /* output modes */ + raw.c_oflag |= (ONLCR); /* control modes - set 8 bit chars */ raw.c_cflag |= (CS8); /* local modes - choing off, canonical off, no extended functions, diff --git a/src/node_version.h b/src/node_version.h index 51798bc6a5c..70bd4be74b2 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -6,7 +6,7 @@ #define NODE_MAJOR_VERSION 0 #define NODE_MINOR_VERSION 3 -#define NODE_PATCH_VERSION 3 +#define NODE_PATCH_VERSION 4 #define NODE_VERSION_IS_RELEASE 0 #ifndef NODE_STRINGIFY |