Skip to content

Commit 442a8bf

Browse files
committed
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.
1 parent 2f6986e commit 442a8bf

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

doc/api/debugger.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ after)
144144
* `watchers` - List all watchers and their values (automatically listed on each
145145
breakpoint)
146146
* `repl` - Open debugger's repl for evaluation in debugging script's context
147+
* `exec(expr)` - Execute expression in debugging script's context
147148

148149
### Execution control
149150

lib/_debugger.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,17 @@ Interface.prototype.repl = function() {
15751575
this.repl.displayPrompt();
15761576
};
15771577

1578+
Interface.prototype.exec = function(code) {
1579+
var self = this;
1580+
this.debugEval(code, null, null, function (err, result) {
1581+
if (err) {
1582+
self.error(err);
1583+
} else {
1584+
self.print(result);
1585+
}
1586+
});
1587+
};
1588+
15781589

15791590
// Exit debug repl
15801591
Interface.prototype.exitRepl = function() {
@@ -1717,11 +1728,12 @@ Interface.prototype.trySpawn = function(cb) {
17171728
client.connect(port, host);
17181729
}
17191730

1720-
self.print('connecting to ' + host + ':' + port + ' ..', true);
17211731
if (isRemote) {
1732+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17221733
attemptConnect();
17231734
} else {
17241735
this.child.stderr.once('data', function() {
1736+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17251737
setImmediate(attemptConnect);
17261738
});
17271739
}

test/debugger/test-debugger-repl.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ addTest('sb("setInterval()", "!(setInterval.flag++)")', [
4949

5050
// Continue
5151
addTest('c', [
52-
/break in node.js:\d+/,
52+
/break in timers.js:\d+/,
5353
/\d/, /\d/, /\d/, /\d/, /\d/
5454
]);
5555

56+
// Execute
57+
addTest('exec("process.title")', [
58+
/iojs/
59+
]);
60+
5661
// REPL and process.env regression
5762
addTest('repl', [
5863
/Ctrl/

0 commit comments

Comments
 (0)