mirror of https://github.com/nodejs/node.git
restore breakpoints after restart, fix message handling
parent
d6088b2667
commit
4a537c1b88
|
@ -194,10 +194,16 @@ Client.prototype._removeScript = function(desc) {
|
|||
|
||||
|
||||
Client.prototype._onResponse = function(res) {
|
||||
for (var i = 0; i < this._reqCallbacks.length; i++) {
|
||||
var cb = this._reqCallbacks[i];
|
||||
if (this._reqCallbacks[i].request_seq == res.body.request_seq) break;
|
||||
}
|
||||
var cb,
|
||||
index = -1;
|
||||
|
||||
this._reqCallbacks.some(function(fn, i) {
|
||||
if (fn.request_seq == res.body.request_seq) {
|
||||
cb = fn;
|
||||
index = i;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
var self = this;
|
||||
var handled = false;
|
||||
|
@ -224,7 +230,7 @@ Client.prototype._onResponse = function(res) {
|
|||
}
|
||||
|
||||
if (cb) {
|
||||
this._reqCallbacks.splice(i, 1);
|
||||
this._reqCallbacks.splice(index, 1);
|
||||
handled = true;
|
||||
cb(res.body);
|
||||
}
|
||||
|
@ -746,6 +752,7 @@ function Interface() {
|
|||
debug: [],
|
||||
control: []
|
||||
};
|
||||
this.breakpoints = [];
|
||||
};
|
||||
|
||||
|
||||
|
@ -874,13 +881,13 @@ Interface.prototype.debugEval = function(code, context, filename, callback) {
|
|||
function intChars(n) {
|
||||
// TODO dumb:
|
||||
if (n < 50) {
|
||||
return 2;
|
||||
} else if (n < 950) {
|
||||
return 3;
|
||||
} else if (n < 9950) {
|
||||
} else if (n < 950) {
|
||||
return 4;
|
||||
} else {
|
||||
} else if (n < 9950) {
|
||||
return 5;
|
||||
} else {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -914,15 +921,17 @@ Interface.prototype.run = function() {
|
|||
|
||||
// Restart script
|
||||
Interface.prototype.restart = function() {
|
||||
if (!this.child) return this.error('App isn\'t running... Try `run` instead');
|
||||
if (!this.requireConnection()) return;
|
||||
|
||||
var self = this;
|
||||
|
||||
this.killChild();
|
||||
self.pause();
|
||||
self.killChild();
|
||||
|
||||
// XXX need to wait a little bit for the restart to work?
|
||||
setTimeout(function() {
|
||||
self.trySpawn();
|
||||
self.resume();
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
|
@ -1093,14 +1102,15 @@ Interface.prototype.out = Interface.stepGenerator('out', 1);
|
|||
|
||||
|
||||
// Add breakpoint
|
||||
Interface.prototype.setBreakpoint = function(script, line, condition) {
|
||||
Interface.prototype.setBreakpoint = function(script, line,
|
||||
condition, silent) {
|
||||
if (!this.requireConnection()) return;
|
||||
|
||||
var self = this,
|
||||
scriptId,
|
||||
ambiguous;
|
||||
|
||||
if (!this.client.scripts[script]) {
|
||||
if (script != +script && !this.client.scripts[script]) {
|
||||
Object.keys(this.client.scripts).forEach(function(id) {
|
||||
if (self.client.scripts[id].name.indexOf(script) !== -1) {
|
||||
if (scriptId) {
|
||||
|
@ -1127,16 +1137,21 @@ Interface.prototype.setBreakpoint = function(script, line, condition) {
|
|||
self.pause();
|
||||
self.client.setBreakpoint(req, function(res) {
|
||||
if (res.success) {
|
||||
self.list(5);
|
||||
if (!silent) {
|
||||
self.list(5);
|
||||
}
|
||||
self.client.breakpoints.push({
|
||||
id: res.body.breakpoint,
|
||||
scriptId: scriptId,
|
||||
script: self.client.scripts[scriptId].name,
|
||||
line: line
|
||||
script: (self.client.scripts[scriptId] || {}).name,
|
||||
line: line,
|
||||
condition: condition
|
||||
});
|
||||
|
||||
} else {
|
||||
self.print(req.message || 'error!');
|
||||
if (!silent) {
|
||||
self.print(req.message || 'error!');
|
||||
}
|
||||
}
|
||||
self.resume();
|
||||
});
|
||||
|
@ -1177,7 +1192,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
|
|||
self.pause();
|
||||
self.client.clearBreakpoint(req, function(res) {
|
||||
if (res.success) {
|
||||
self.client.breakpoints = self.client.breakpoints.splice(index, -1);
|
||||
self.client.breakpoints.splice(index, 1);
|
||||
self.list(5);
|
||||
} else {
|
||||
self.print(req.message || 'error!');
|
||||
|
@ -1273,16 +1288,18 @@ Interface.prototype.killChild = function() {
|
|||
}
|
||||
|
||||
if (this.client) {
|
||||
// Save breakpoints
|
||||
this.breakpoints = this.client.breakpoints;
|
||||
|
||||
this.client.destroy();
|
||||
this.client = null;
|
||||
}
|
||||
|
||||
this.resume();
|
||||
};
|
||||
|
||||
|
||||
Interface.prototype.trySpawn = function(cb) {
|
||||
var self = this;
|
||||
var self = this,
|
||||
breakpoints = this.breakpoints || [];
|
||||
|
||||
this.killChild();
|
||||
|
||||
|
@ -1293,8 +1310,8 @@ Interface.prototype.trySpawn = function(cb) {
|
|||
|
||||
this.pause();
|
||||
|
||||
var client = self.client = new Client();
|
||||
var connectionAttempts = 0;
|
||||
var client = self.client = new Client(),
|
||||
connectionAttempts = 0;
|
||||
|
||||
client.once('ready', function() {
|
||||
process.stdout.write(' ok\n');
|
||||
|
@ -1302,8 +1319,14 @@ Interface.prototype.trySpawn = function(cb) {
|
|||
// since we did debug-brk, we're hitting a break point immediately
|
||||
// continue before anything else.
|
||||
client.reqContinue(function() {
|
||||
self.resume();
|
||||
if (cb) cb();
|
||||
|
||||
// Restore breakpoints
|
||||
breakpoints.forEach(function(bp) {
|
||||
self.setBreakpoint(bp.scriptId, bp.line, bp.condition, true);
|
||||
});
|
||||
|
||||
self.resume();
|
||||
});
|
||||
|
||||
client.on('close', function() {
|
||||
|
|
Loading…
Reference in New Issue