debugger: fix backtrace with no frames
authorFedor Indutny <fedor.indutny@gmail.com>
Sun, 25 Sep 2011 19:20:47 +0000 (02:20 +0700)
committerRyan Dahl <ry@tinyclouds.org>
Mon, 26 Sep 2011 17:57:19 +0000 (10:57 -0700)
Fixes #1768

lib/_debugger.js
test/fixtures/breakpoints.js
test/simple/test-debugger-repl.js

index a0e2cf8..8d16a89 100644 (file)
@@ -587,6 +587,7 @@ Client.prototype.fullTrace = function(cb) {
 
   this.reqBacktrace(function(err, trace) {
     if (err) return cb(err);
+    if (trace.totalFrames <= 0) return cb(Error('No frames'));
 
     var refs = [];
 
@@ -615,6 +616,8 @@ Client.prototype.fullTrace = function(cb) {
     }
 
     self.reqLookup(refs, function(res) {
+      if (!res.success) return cb(res.message || true);
+
       for (var i = 0; i < trace.frames.length; i++) {
         var frame = trace.frames[i];
         frame.script = res.body[frame.script.ref];
@@ -1104,7 +1107,7 @@ Interface.prototype.backtrace = function() {
 
   self.pause();
   client.fullTrace(function(err, bt) {
-    if (err) return self.error(err);
+    if (err) return self.error('Can\'t request backtrace now');
     if (bt.totalFrames == 0) {
       self.print('(empty stack)');
     } else {
index ec6c526..4ea4c12 100644 (file)
@@ -14,3 +14,8 @@ a();
 a(1);
 b();
 b();
+
+
+
+setInterval(function() {
+}, 5000);
index ea2aed9..58e2405 100644 (file)
@@ -43,6 +43,7 @@ child.stderr.pipe(process.stdout);
 var expected = [];
 
 child.on('line', function(line) {
+  console.log(JSON.stringify(line));
   assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
 
   var expectedLine = expected[0].lines.shift();
@@ -110,6 +111,21 @@ addTest('o', [
   "\b 16 b();"
 ]);
 
+// Continue
+addTest('c', [
+ "debug> debug> debug> \bbreak in [unnamed]:7",
+  "\b  5   var i = 10;",
+  "\b  6   while (--i != 0);",
+  "\b  7   debugger;",
+  "\b  8   return i;",
+  "\b  9 };"
+]);
+
+// Continue
+addTest('c, bt', [
+  "debug> \bCan't request backtrace now"
+]);
+
 
 function finish() {
   process.exit(0);