Skip to content

Commit a358dee

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 2632775 commit a358dee

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
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: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Protocol.prototype.serialize = function(req) {
142142
const NO_FRAME = -1;
143143

144144
function Client() {
145-
net.Stream.call(this);
145+
net.Socket.call(this);
146146
var protocol = this.protocol = new Protocol(this);
147147
this._reqCallbacks = [];
148148
var socket = this;
@@ -161,7 +161,7 @@ function Client() {
161161

162162
protocol.onResponse = this._onResponse.bind(this);
163163
}
164-
inherits(Client, net.Stream);
164+
inherits(Client, net.Socket);
165165
exports.Client = Client;
166166

167167

@@ -641,10 +641,6 @@ Client.prototype.fullTrace = function(cb) {
641641
};
642642

643643

644-
645-
646-
647-
648644
const commands = [
649645
[
650646
'run (r)',
@@ -661,6 +657,7 @@ const commands = [
661657
'unwatch',
662658
'watchers',
663659
'repl',
660+
'exec',
664661
'restart',
665662
'kill',
666663
'list',
@@ -1531,6 +1528,19 @@ Interface.prototype.pause_ = function() {
15311528
};
15321529

15331530

1531+
// execute expression
1532+
Interface.prototype.exec = function(code) {
1533+
var self = this;
1534+
this.debugEval(code, null, null, function(err, result) {
1535+
if (err) {
1536+
self.error(err);
1537+
} else {
1538+
self.print(util.inspect(result, {colors: true}));
1539+
}
1540+
});
1541+
};
1542+
1543+
15341544
// Kill child process
15351545
Interface.prototype.kill = function() {
15361546
if (!this.child) return;
@@ -1717,11 +1727,12 @@ Interface.prototype.trySpawn = function(cb) {
17171727
client.connect(port, host);
17181728
}
17191729

1720-
self.print('connecting to ' + host + ':' + port + ' ..', true);
17211730
if (isRemote) {
1731+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17221732
attemptConnect();
17231733
} else {
17241734
this.child.stderr.once('data', function() {
1735+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17251736
setImmediate(attemptConnect);
17261737
});
17271738
}

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)