Browse Source

restore breakpoints after restart, fix message handling

Fedor Indutny 14 years ago
committed by Ryan Dahl
parent
commit
4a537c1b88
  1. 65
      lib/_debugger.js

65
lib/_debugger.js

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

Loading…
Cancel
Save