Skip to content

Commit ce423f3

Browse files
JacksonTianrvagg
authored andcommittedDec 5, 2015
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: #1491 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 6c16c40 commit ce423f3

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed
 

‎doc/api/debugger.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ after)
143143
* `watchers` - List all watchers and their values (automatically listed on each
144144
breakpoint)
145145
* `repl` - Open debugger's repl for evaluation in debugging script's context
146+
* `exec expr` - Execute an expression in debugging script's context
146147

147148
### Execution control
148149

‎lib/_debugger.js

+23-3
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

@@ -657,6 +657,7 @@ const commands = [
657657
'unwatch',
658658
'watchers',
659659
'repl',
660+
'exec',
660661
'restart',
661662
'kill',
662663
'list',
@@ -949,6 +950,12 @@ Interface.prototype.controlEval = function(code, context, filename, callback) {
949950
}
950951
}
951952

953+
// exec process.title => exec("process.title");
954+
var match = code.match(/^\s*exec\s+([^\n]*)/);
955+
if (match) {
956+
code = 'exec(' + JSON.stringify(match[1]) + ')';
957+
}
958+
952959
var result = vm.runInContext(code, context, filename);
953960

954961
// Repl should not ask for next command
@@ -1527,6 +1534,18 @@ Interface.prototype.pause_ = function() {
15271534
};
15281535

15291536

1537+
// execute expression
1538+
Interface.prototype.exec = function(code) {
1539+
this.debugEval(code, null, null, (err, result) => {
1540+
if (err) {
1541+
this.error(err);
1542+
} else {
1543+
this.print(util.inspect(result, {colors: true}));
1544+
}
1545+
});
1546+
};
1547+
1548+
15301549
// Kill child process
15311550
Interface.prototype.kill = function() {
15321551
if (!this.child) return;
@@ -1730,11 +1749,12 @@ Interface.prototype.trySpawn = function(cb) {
17301749
client.connect(port, host);
17311750
}
17321751

1733-
self.print('connecting to ' + host + ':' + port + ' ..', true);
17341752
if (isRemote) {
1753+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17351754
attemptConnect();
17361755
} else {
17371756
this.child.stderr.once('data', function() {
1757+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17381758
setImmediate(attemptConnect);
17391759
});
17401760
}

‎test/debugger/test-debugger-repl.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,20 @@ addTest('sb("setInterval()", "!(setInterval.flag++)")', [
5151

5252
// Continue
5353
addTest('c', [
54-
/break in node.js:\d+/,
54+
/break in timers.js:\d+/,
5555
/\d/, /\d/, /\d/, /\d/, /\d/
5656
]);
5757

58+
// Execute
59+
addTest('exec process.title', [
60+
/node/
61+
]);
62+
63+
// Execute
64+
addTest('exec exec process.title', [
65+
/SyntaxError: Unexpected identifier/
66+
]);
67+
5868
// REPL and process.env regression
5969
addTest('repl', [
6070
/Ctrl/

0 commit comments

Comments
 (0)
Please sign in to comment.