diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-12-22 11:48:22 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-12-30 12:35:11 +0300 |
commit | 8e96b8ab9bd559914c18b0bdf3b291862c961f94 (patch) | |
tree | 9d20fb569938275f284370b52f39942b17c60079 /lib | |
parent | 797aa97e19bbb7b9536e2a7da03012e2db018d23 (diff) |
keep track of current frame. eval works for global scope
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_debugger.js | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/lib/_debugger.js b/lib/_debugger.js index 5c0dd555010..0232f312baa 100644 --- a/lib/_debugger.js +++ b/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(); }); |