Browse Source

keep track of current frame. eval works for global scope

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
8e96b8ab9b
  1. 51
      lib/_debugger.js

51
lib/_debugger.js

@ -110,7 +110,7 @@ Protocol.prototype.serialize = function(req) {
}; };
var NO_FRAME = -1;
function Client() { function Client() {
net.Stream.call(this); net.Stream.call(this);
@ -118,6 +118,9 @@ function Client() {
this._reqCallbacks = []; this._reqCallbacks = [];
var socket = this; var socket = this;
this.currentFrame = NO_FRAME;
this.currentSourceLine = -1;
// Note that 'Protocol' requires strings instead of Buffers. // Note that 'Protocol' requires strings instead of Buffers.
socket.setEncoding('utf8'); socket.setEncoding('utf8');
socket.on('data', function(d) { socket.on('data', function(d) {
@ -142,7 +145,7 @@ Client.prototype._onResponse = function(res) {
this._reqCallbacks.splice(i, 1); this._reqCallbacks.splice(i, 1);
cb(res.body); cb(res.body);
} else { } else {
console.error("unhandled res: %j", res.body); this.emit('unhandledResponse', res.body);
} }
}; };
@ -161,7 +164,30 @@ Client.prototype.reqVersion = function(cb) {
}; };
var helpMessage = "Commands: version, eval, help, quit"; Client.prototype.reqEval = function(expression, cb) {
var req = {
command: 'evaluate',
arguments: { expression: expression }
};
if (this.currentFrame == NO_FRAME) req.arguments.global = true;
this.req(req, function (res) {
if (cb) cb(res.body);
});
};
// reqBacktrace(cb)
// TODO: from, to, bottom
Client.prototype.reqBacktrace = function(cb) {
this.req({ command: 'backtrace' } , function (res) {
if (cb) cb(res.body);
});
};
var helpMessage = "Commands: backtrace, version, eval, help, quit";
function startInterface() { function startInterface() {
@ -194,13 +220,14 @@ function startInterface() {
i.prompt(); i.prompt();
}); });
} else if (/^eval/.test(cmd)) { } else if ('backtrace' == cmd || 'bt' == cmd) {
var req = { c.reqBacktrace(function (bt) {
command: 'evaluate', console.log(bt);
arguments: { 'expression': cmd.slice(5) } i.prompt();
}; });
c.req(req, function (res) { } else if (/^eval/.test(cmd)) {
c.reqEval(cmd.slice(5), function (res) {
console.log(res); console.log(res);
i.prompt(); i.prompt();
}); });
@ -214,6 +241,12 @@ function startInterface() {
} }
}); });
c.on('unhandledResponse', function (res) {
console.log("\r\nunhandled res:");
console.log(res.body);
i.prompt();
});
i.on('close', function() { i.on('close', function() {
stdin.destroy(); stdin.destroy();
}); });

Loading…
Cancel
Save