Permalink
Browse files

debugger: export `debug_port` to `process`

`process.debug_port` is useful for changing debugger port in runtime,
before starting it (via SIGUSR1).

Using `--port=` argument for debugger repl, tests will run debugger
server on a `common.PORT` (as it usually does for any other servers).

`process._debugEnd()` stops debugger and it's server.

* debugger: implemented process._debugEnd(), `node debug --port=5858 app.js`
* test: start debugger repl on common.PORT
* fixes #2613
* fixes #2614
  • Loading branch information...
1 parent 8a6576f commit 2d251490cdf4b2988a644420bd6acfbeb6c8e256 @indutny committed Feb 12, 2012
Showing with 46 additions and 6 deletions.
  1. +11 −2 lib/_debugger.js
  2. +31 −0 src/node.cc
  3. +2 −2 test/simple/test-debugger-repl-utf8.js
  4. +2 −2 test/simple/test-debugger-repl.js
View
13 lib/_debugger.js
@@ -1570,11 +1570,12 @@ Interface.prototype.trySpawn = function(cb) {
this.killChild();
- // Connecting to remote debugger
- // `node debug localhost:5858`
if (this.args.length === 2) {
var match = this.args[1].match(/^([^:]+):(\d+)$/);
+
if (match) {
+ // Connecting to remote debugger
+ // `node debug localhost:5858`
host = match[1];
port = parseInt(match[2], 10);
this.child = {
@@ -1592,6 +1593,14 @@ Interface.prototype.trySpawn = function(cb) {
}
};
process._debugProcess(parseInt(this.args[2], 10));
+ } else {
+ var match = this.args[1].match(/^--port=(\d+)$/);
+ if (match) {
+ // Start debugger on custom port
+ // `node debug --port=5858 app.js`
+ port = parseInt(match[1], 10);
+ this.args.splice(0, 2, '--debug-brk=' + port);
+ }
}
}
View
31 src/node.cc
@@ -1996,8 +1996,24 @@ static Handle<Object> GetFeatures() {
}
+static Handle<Value> DebugPortGetter(Local<String> property,
+ const AccessorInfo& info) {
+ HandleScope scope;
+ return scope.Close(Integer::NewFromUnsigned(debug_port));
+}
+
+
+static void DebugPortSetter(Local<String> property,
+ Local<Value> value,
+ const AccessorInfo& info) {
+ HandleScope scope;
+ debug_port = value->NumberValue();
+}
+
+
static Handle<Value> DebugProcess(const Arguments& args);
static Handle<Value> DebugPause(const Arguments& args);
+static Handle<Value> DebugEnd(const Arguments& args);
Handle<Object> SetupProcessObject(int argc, char *argv[]) {
HandleScope scope;
@@ -2099,6 +2115,10 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
}
delete [] execPath;
+ process->SetAccessor(String::New("debug_port"),
+ DebugPortGetter,
+ DebugPortSetter);
+
// define various internal methods
NODE_SET_METHOD(process, "_needTickCallback", NeedTickCallback);
@@ -2125,6 +2145,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
NODE_SET_METHOD(process, "_debugProcess", DebugProcess);
NODE_SET_METHOD(process, "_debugPause", DebugPause);
+ NODE_SET_METHOD(process, "_debugEnd", DebugEnd);
NODE_SET_METHOD(process, "dlopen", DLOpen);
@@ -2537,6 +2558,16 @@ static Handle<Value> DebugPause(const Arguments& args) {
}
+static Handle<Value> DebugEnd(const Arguments& args) {
+ if (debugger_running) {
+ v8::Debug::DisableAgent();
+ debugger_running = false;
+ }
+
+ return Undefined();
+}
+
+
char** Init(int argc, char *argv[]) {
// Initialize prog_start_time to get relative uptime.
uv_uptime(&prog_start_time);
View
4 test/simple/test-debugger-repl-utf8.js
@@ -27,7 +27,7 @@ var debug = require('_debugger');
var script = common.fixturesDir + '/breakpoints_utf8.js';
-var child = spawn(process.execPath, ['debug', script]);
+var child = spawn(process.execPath, ['debug', '--port=' + common.PORT, script]);
var buffer = '';
child.stdout.setEncoding('utf-8');
@@ -77,7 +77,7 @@ function addTest(input, output) {
// Initial lines
addTest(null, [
- /listening on port 5858/,
+ /listening on port \d+/,
/connecting... ok/,
/break in .*:1/,
/1/, /2/, /3/
View
4 test/simple/test-debugger-repl.js
@@ -27,7 +27,7 @@ var debug = require('_debugger');
var script = common.fixturesDir + '/breakpoints.js';
-var child = spawn(process.execPath, ['debug', script]);
+var child = spawn(process.execPath, ['debug', '--port=' + common.PORT, script]);
var buffer = '';
child.stdout.setEncoding('utf-8');
@@ -82,7 +82,7 @@ function addTest(input, output) {
// Initial lines
addTest(null, [
- /listening on port 5858/,
+ /listening on port \d+/,
/connecting... ok/,
/break in .*:1/,
/1/, /2/, /3/

0 comments on commit 2d25149

Please sign in to comment.