Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugger: introduce exec method for debugger #1491

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/debugger.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,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

Expand Down
26 changes: 23 additions & 3 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -161,7 +161,7 @@ function Client() {

protocol.onResponse = this._onResponse.bind(this);
}
inherits(Client, net.Stream);
inherits(Client, net.Socket);
exports.Client = Client;


Expand Down Expand Up @@ -657,6 +657,7 @@ const commands = [
'unwatch',
'watchers',
'repl',
'exec',
'restart',
'kill',
'list',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1527,6 +1534,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;
Expand Down Expand Up @@ -1730,11 +1749,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);
});
}
Expand Down
12 changes: 11 additions & 1 deletion test/debugger/test-debugger-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down