Browse Source

debugger: introduce exec method for debugger

In debugger, the usage of `repl` very ugly. I'd like there is a `p`
like gdb. So the `exec` is coming.

Usage:

```
$ ./iojs debug ~/git/node_research/server.js
< Debugger listening on port 5858
connecting to 127.0.0.1:5858 ... ok
break in /Users/jacksontian/git/node_research/server.js:1
> 1 var http = require('http');
  2
  3 http.createServer(function (req, res) {
debug> exec process.title
/Users/jacksontian/git/io.js/out/Release/iojs
debug>
```

And the `repl`:

```
debug> repl
Press Ctrl + C to leave debug repl
> process.title
'/Users/jacksontian/git/io.js/out/Release/iojs'
debug>
(^C again to quit)
```

The enter and leave debug repl is superfluous.

R-URL: https://github.com/nodejs/node/pull/1491
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
process-exit-stdio-flushing
Jackson Tian 10 years ago
committed by James M Snell
parent
commit
b33e9da8f9
  1. 1
      doc/api/debugger.markdown
  2. 26
      lib/_debugger.js
  3. 12
      test/debugger/test-debugger-repl.js

1
doc/api/debugger.markdown

@ -143,6 +143,7 @@ after)
* `watchers` - List all watchers and their values (automatically listed on each * `watchers` - List all watchers and their values (automatically listed on each
breakpoint) breakpoint)
* `repl` - Open debugger's repl for evaluation in debugging script's context * `repl` - Open debugger's repl for evaluation in debugging script's context
* `exec expr` - Execute an expression in debugging script's context
### Execution control ### Execution control

26
lib/_debugger.js

@ -142,7 +142,7 @@ Protocol.prototype.serialize = function(req) {
const NO_FRAME = -1; const NO_FRAME = -1;
function Client() { function Client() {
net.Stream.call(this); net.Socket.call(this);
var protocol = this.protocol = new Protocol(this); var protocol = this.protocol = new Protocol(this);
this._reqCallbacks = []; this._reqCallbacks = [];
var socket = this; var socket = this;
@ -161,7 +161,7 @@ function Client() {
protocol.onResponse = this._onResponse.bind(this); protocol.onResponse = this._onResponse.bind(this);
} }
inherits(Client, net.Stream); inherits(Client, net.Socket);
exports.Client = Client; exports.Client = Client;
@ -657,6 +657,7 @@ const commands = [
'unwatch', 'unwatch',
'watchers', 'watchers',
'repl', 'repl',
'exec',
'restart', 'restart',
'kill', 'kill',
'list', '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); var result = vm.runInContext(code, context, filename);
// Repl should not ask for next command // Repl should not ask for next command
@ -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 // Kill child process
Interface.prototype.kill = function() { Interface.prototype.kill = function() {
if (!this.child) return; if (!this.child) return;
@ -1730,11 +1749,12 @@ Interface.prototype.trySpawn = function(cb) {
client.connect(port, host); client.connect(port, host);
} }
self.print('connecting to ' + host + ':' + port + ' ..', true);
if (isRemote) { if (isRemote) {
self.print('connecting to ' + host + ':' + port + ' ..', true);
attemptConnect(); attemptConnect();
} else { } else {
this.child.stderr.once('data', function() { this.child.stderr.once('data', function() {
self.print('connecting to ' + host + ':' + port + ' ..', true);
setImmediate(attemptConnect); setImmediate(attemptConnect);
}); });
} }

12
test/debugger/test-debugger-repl.js

@ -51,10 +51,20 @@ addTest('sb("setInterval()", "!(setInterval.flag++)")', [
// Continue // Continue
addTest('c', [ addTest('c', [
/break in node.js:\d+/, /break in timers.js:\d+/,
/\d/, /\d/, /\d/, /\d/, /\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 // REPL and process.env regression
addTest('repl', [ addTest('repl', [
/Ctrl/ /Ctrl/

Loading…
Cancel
Save