Permalink
Browse files

debugger: Better backtraces

  • Loading branch information...
1 parent 7df8a05 commit d87ab5450bc09a91a741452946b68ca1df4a4add @ry ry committed Jan 13, 2011
Showing with 76 additions and 10 deletions.
  1. +76 −10 lib/_debugger.js
View
@@ -211,6 +211,8 @@ Client.prototype.reqVersion = function(cb) {
Client.prototype.reqLookup = function(refs, cb) {
+ var self = this;
+
// TODO: We have a cache of handle's we've already seen in this.handles
// This can be used if we're careful.
var req = {
@@ -221,6 +223,14 @@ Client.prototype.reqLookup = function(refs, cb) {
};
this.req(req, function(res) {
+ if (res.success) {
+ for (var ref in res.body) {
+ if (typeof res.body[ref] == 'object') {
+ self._addHandle(res.body[ref]);
+ }
+ }
+ }
+
if (cb) cb(res);
});
};
@@ -240,6 +250,8 @@ Client.prototype.reqEval = function(expression, cb) {
req.arguments.frame = this.currentFrame;
}
+ console.error("currentFrame: %d", this.currentFrame);
+
this.req(req, function(res) {
if (res.success) {
self._addHandle(res.body);
@@ -356,7 +368,6 @@ Client.prototype.mirrorObject = function(handle, cb) {
var mirror = {};
for (var i = 0; i < handle.properties.length; i++) {
var value = res.body[handle.properties[i].ref];
- self._addHandle(value);
mirror[handle.properties[i].name] = value.text;
}
@@ -376,6 +387,52 @@ Client.prototype.mirrorObject = function(handle, cb) {
};
+Client.prototype.fullTrace = function(cb) {
+ var self = this;
+
+ this.reqBacktrace(function(trace) {
+ var refs = [];
+
+ for (var i = 0; i < trace.frames.length; i++) {
+ var frame = trace.frames[i];
+ // looks like this:
+ // { type: 'frame',
+ // index: 0,
+ // receiver: { ref: 1 },
+ // func: { ref: 0 },
+ // script: { ref: 7 },
+ // constructCall: false,
+ // atReturn: false,
+ // debuggerFrame: false,
+ // arguments: [],
+ // locals: [],
+ // position: 160,
+ // line: 7,
+ // column: 2,
+ // sourceLineText: ' debugger;',
+ // scopes: [ { type: 1, index: 0 }, { type: 0, index: 1 } ],
+ // text: '#00 blah() /home/ryan/projects/node/test-debug.js line 8 column 3 (position 161)' }
+ refs.push(frame.script.ref);
+ refs.push(frame.func.ref);
+ refs.push(frame.receiver.ref);
+ }
+
+ self.reqLookup(refs, function(res) {
+ for (var i = 0; i < trace.frames.length; i++) {
+ var frame = trace.frames[i];
+ frame.script = res.body[frame.script.ref];
+ frame.func = res.body[frame.func.ref];
+ frame.receiver = res.body[frame.receiver.ref];
+ }
+
+ if (cb) cb(trace);
+ });
+ });
+}
+
+
+
+
var commands = [
@@ -712,18 +769,27 @@ Interface.prototype.handleCommand = function(cmd) {
self.printNotConnected();
return;
}
- client.reqBacktrace(function(bt) {
- if (/full/.test(cmd)) {
- console.log(bt);
- } else if (bt.totalFrames == 0) {
+
+ client.fullTrace(function(bt) {
+ if (bt.totalFrames == 0) {
console.log('(empty stack)');
} else {
- var result = '';
- for (j = 0; j < bt.frames.length; j++) {
- if (j != 0) result += '\n';
- result += bt.frames[j].text;
+ var text = '';
+ var firstFrameNative = bt.frames[0].script.isNative;
+ for (var i = 0; i < bt.frames.length; i++) {
+ var frame = bt.frames[i];
+ if (!firstFrameNative && frame.script.isNative) break;
+
+ text += '#' + i + ' ';
+ if (frame.func.inferredName && frame.func.inferredName.length > 0) {
+ text += frame.func.inferredName + ' ';
+ }
+ text += require('path').basename(frame.script.name) + ':';
+ text += (frame.line + 1) + ':' + (frame.column + 1);
+ text += '\n';
}
- console.log(result);
+
+ console.log(text);
}
term.prompt();
});

0 comments on commit d87ab54

Please sign in to comment.