diff --git a/doc/api/debugger.markdown b/doc/api/debugger.markdown index bbde4f0f4b..2bbaf9049e 100644 --- a/doc/api/debugger.markdown +++ b/doc/api/debugger.markdown @@ -152,6 +152,7 @@ after) * `watchers` - List all watchers and their values (automatically listed on each breakpoint) * `repl` - Open debugger's repl for evaluation in debugging script's context +* `exec expr` - Execute an expression in debugging script's context ### Execution control diff --git a/lib/_debugger.js b/lib/_debugger.js index 2bb9b7834c..8a72121f60 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -142,7 +142,7 @@ Protocol.prototype.serialize = function(req) { const NO_FRAME = -1; function Client() { - net.Stream.call(this); + net.Socket.call(this); var protocol = this.protocol = new Protocol(this); this._reqCallbacks = []; var socket = this; @@ -161,7 +161,7 @@ function Client() { protocol.onResponse = (res) => this._onResponse(res); } -inherits(Client, net.Stream); +inherits(Client, net.Socket); exports.Client = Client; @@ -657,6 +657,7 @@ const commands = [ 'unwatch', 'watchers', 'repl', + 'exec', 'restart', 'kill', 'list', @@ -949,6 +950,12 @@ Interface.prototype.controlEval = function(code, context, filename, callback) { } } + // exec process.title => exec("process.title"); + var match = code.match(/^\s*exec\s+([^\n]*)/); + if (match) { + code = 'exec(' + JSON.stringify(match[1]) + ')'; + } + var result = vm.runInContext(code, context, filename); // Repl should not ask for next command @@ -1521,6 +1528,18 @@ Interface.prototype.pause_ = function() { }; +// execute expression +Interface.prototype.exec = function(code) { + this.debugEval(code, null, null, (err, result) => { + if (err) { + this.error(err); + } else { + this.print(util.inspect(result, {colors: true})); + } + }); +}; + + // Kill child process Interface.prototype.kill = function() { if (!this.child) return; @@ -1726,11 +1745,12 @@ Interface.prototype.trySpawn = function(cb) { client.connect(port, host); } - self.print('connecting to ' + host + ':' + port + ' ..', true); if (isRemote) { + self.print('connecting to ' + host + ':' + port + ' ..', true); attemptConnect(); } else { this.child.stderr.once('data', function() { + self.print('connecting to ' + host + ':' + port + ' ..', true); setImmediate(attemptConnect); }); } diff --git a/test/debugger/test-debugger-repl.js b/test/debugger/test-debugger-repl.js index f93570c501..4919955273 100644 --- a/test/debugger/test-debugger-repl.js +++ b/test/debugger/test-debugger-repl.js @@ -51,10 +51,20 @@ addTest('sb("setInterval()", "!(setInterval.flag++)")', [ // Continue addTest('c', [ - /break in node.js:\d+/, + /break in timers.js:\d+/, /\d/, /\d/, /\d/, /\d/, /\d/ ]); +// Execute +addTest('exec process.title', [ + /node/ +]); + +// Execute +addTest('exec exec process.title', [ + /SyntaxError: Unexpected identifier/ +]); + // REPL and process.env regression addTest('repl', [ /Ctrl/