Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c6809c

Browse filesBrowse files
JacksonTianMyles Borins
authored andcommitted
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 <info@bnoordhuis.nl> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent cc3645c commit 1c6809c
Copy full SHA for 1c6809c

File tree

Expand file treeCollapse file tree

3 files changed

+35
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+35
-4
lines changed
Open diff view settings
Collapse file

‎doc/api/debugger.markdown‎

Copy file name to clipboardExpand all lines: doc/api/debugger.markdown
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ after)
152152
* `watchers` - List all watchers and their values (automatically listed on each
153153
breakpoint)
154154
* `repl` - Open debugger's repl for evaluation in debugging script's context
155+
* `exec expr` - Execute an expression in debugging script's context
155156

156157
### Execution control
157158

Collapse file

‎lib/_debugger.js‎

Copy file name to clipboardExpand all lines: lib/_debugger.js
+23-3Lines changed: 23 additions & 3 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 = (res) => this._onResponse(res);
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
@@ -1521,6 +1528,18 @@ Interface.prototype.pause_ = function() {
15211528
};
15221529

15231530

1531+
// execute expression
1532+
Interface.prototype.exec = function(code) {
1533+
this.debugEval(code, null, null, (err, result) => {
1534+
if (err) {
1535+
this.error(err);
1536+
} else {
1537+
this.print(util.inspect(result, {colors: true}));
1538+
}
1539+
});
1540+
};
1541+
1542+
15241543
// Kill child process
15251544
Interface.prototype.kill = function() {
15261545
if (!this.child) return;
@@ -1726,11 +1745,12 @@ Interface.prototype.trySpawn = function(cb) {
17261745
client.connect(port, host);
17271746
}
17281747

1729-
self.print('connecting to ' + host + ':' + port + ' ..', true);
17301748
if (isRemote) {
1749+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17311750
attemptConnect();
17321751
} else {
17331752
this.child.stderr.once('data', function() {
1753+
self.print('connecting to ' + host + ':' + port + ' ..', true);
17341754
setImmediate(attemptConnect);
17351755
});
17361756
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/debugger/test-debugger-repl.js
+11-1Lines changed: 11 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.