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() {
net.Stream.call(this);
@ -118,6 +118,9 @@ function Client() {
this._reqCallbacks = [];
var socket = this;
this.currentFrame = NO_FRAME;
this.currentSourceLine = -1;
// Note that 'Protocol' requires strings instead of Buffers.
socket.setEncoding('utf8');
socket.on('data', function(d) {
@ -142,7 +145,7 @@ Client.prototype._onResponse = function(res) {
this._reqCallbacks.splice(i, 1);
cb(res.body);
} 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() {
@ -194,13 +220,14 @@ function startInterface() {
i.prompt();
});
} else if (/^eval/.test(cmd)) {
var req = {
command: 'evaluate',
arguments: { 'expression': cmd.slice(5) }
};
} else if ('backtrace' == cmd || 'bt' == cmd) {
c.reqBacktrace(function (bt) {
console.log(bt);
i.prompt();
});
c.req(req, function (res) {
} else if (/^eval/.test(cmd)) {
c.reqEval(cmd.slice(5), function (res) {
console.log(res);
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() {
stdin.destroy();
});

Loading…
Cancel
Save