|
|
@ -25,7 +25,7 @@ var util = require('util'), |
|
|
|
vm = require('vm'), |
|
|
|
repl = require('repl'), |
|
|
|
inherits = util.inherits, |
|
|
|
spawn = require('child_process').spawn; |
|
|
|
fork = require('child_process').fork; |
|
|
|
|
|
|
|
exports.start = function(argv, stdin, stdout) { |
|
|
|
argv || (argv = process.argv.slice(2)); |
|
|
@ -39,7 +39,7 @@ exports.start = function(argv, stdin, stdout) { |
|
|
|
stdin = stdin || process.openStdin(); |
|
|
|
stdout = stdout || process.stdout; |
|
|
|
|
|
|
|
var args = ['--debug-brk'].concat(argv), |
|
|
|
var args = argv, |
|
|
|
interface = new Interface(stdin, stdout, args); |
|
|
|
|
|
|
|
stdin.resume(); |
|
|
@ -169,6 +169,8 @@ function Client() { |
|
|
|
this.scripts = {}; |
|
|
|
this.breakpoints = []; |
|
|
|
|
|
|
|
this.isolates = process.features.isolates; |
|
|
|
|
|
|
|
// Note that 'Protocol' requires strings instead of Buffers.
|
|
|
|
socket.setEncoding('utf8'); |
|
|
|
socket.on('data', function(d) { |
|
|
@ -1595,20 +1597,51 @@ Interface.prototype.trySpawn = function(cb) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!this.child) { |
|
|
|
this.child = spawn(process.execPath, this.args); |
|
|
|
var client = self.client = new Client(), |
|
|
|
connectionAttempts = 0; |
|
|
|
|
|
|
|
this.child.stdout.on('data', this.childPrint.bind(this)); |
|
|
|
this.child.stderr.on('data', this.childPrint.bind(this)); |
|
|
|
if (!this.child) { |
|
|
|
if (client.isolates) { |
|
|
|
this.child = fork(this.args.shift(), this.args, { |
|
|
|
thread: true, |
|
|
|
debug: function(d) { |
|
|
|
d.onmessage = function(event) { |
|
|
|
client._onResponse({ |
|
|
|
headers: {}, |
|
|
|
body: JSON.parse(event) |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// Monkey patch client to send requests directly to debugger
|
|
|
|
client.req = function(req, cb) { |
|
|
|
req.type = 'request'; |
|
|
|
cb.request_seq = req.seq = this.protocol.reqSeq++; |
|
|
|
this._reqCallbacks.push(cb); |
|
|
|
|
|
|
|
d.write(JSON.stringify(req)); |
|
|
|
}; |
|
|
|
|
|
|
|
client.emit('ready'); |
|
|
|
|
|
|
|
client._onResponse({ |
|
|
|
headers: { Type: 'connect' }, |
|
|
|
body: {} |
|
|
|
}); |
|
|
|
}, |
|
|
|
debugBrk: true |
|
|
|
}); |
|
|
|
this.child.kill = function() { |
|
|
|
self.error('isolate.kill is not implemented yet!'); |
|
|
|
}; |
|
|
|
} else { |
|
|
|
this.child = fork('--debug-brk', this.args); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.pause(); |
|
|
|
|
|
|
|
var client = self.client = new Client(), |
|
|
|
connectionAttempts = 0; |
|
|
|
|
|
|
|
client.once('ready', function() { |
|
|
|
self.stdout.write(' ok\n'); |
|
|
|
if (!client.isolates) self.stdout.write(' ok\n'); |
|
|
|
|
|
|
|
// Restore breakpoints
|
|
|
|
breakpoints.forEach(function(bp) { |
|
|
@ -1656,11 +1689,14 @@ Interface.prototype.trySpawn = function(cb) { |
|
|
|
function attemptConnect() { |
|
|
|
++connectionAttempts; |
|
|
|
self.stdout.write('.'); |
|
|
|
|
|
|
|
client.connect(port, host); |
|
|
|
} |
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
|
self.print('connecting..', true); |
|
|
|
attemptConnect(); |
|
|
|
}, 50); |
|
|
|
if (!client.isolates) { |
|
|
|
setTimeout(function() { |
|
|
|
self.print('connecting..', true); |
|
|
|
attemptConnect(); |
|
|
|
}, 50); |
|
|
|
} |
|
|
|
}; |
|
|
|