Skip to content

Commit

Permalink
debugger: introduce exec method for debugger
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JacksonTian committed Apr 21, 2015
1 parent 2f6986e commit 442a8bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/api/debugger.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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 expression in debugging script's context

### Execution control

Expand Down
14 changes: 13 additions & 1 deletion lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,17 @@ Interface.prototype.repl = function() {
this.repl.displayPrompt();
};

Interface.prototype.exec = function(code) {
var self = this;
this.debugEval(code, null, null, function (err, result) {
if (err) {
self.error(err);
} else {
self.print(result);
}
});
};


// Exit debug repl
Interface.prototype.exitRepl = function() {
Expand Down Expand Up @@ -1717,11 +1728,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
7 changes: 6 additions & 1 deletion test/debugger/test-debugger-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ 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")', [
/iojs/
]);

// REPL and process.env regression
addTest('repl', [
/Ctrl/
Expand Down

0 comments on commit 442a8bf

Please sign in to comment.