Browse Source

debugger: Clean up a few commands

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
0c928b124c
  1. 61
      lib/_debugger.js

61
lib/_debugger.js

@ -174,7 +174,11 @@ Client.prototype.reqEval = function(expression, cb) {
arguments: { expression: expression } arguments: { expression: expression }
}; };
if (this.currentFrame == NO_FRAME) req.arguments.global = true; if (this.currentFrame == NO_FRAME) {
req.arguments.global = true;
} else {
req.arguments.frame = this.currentFrame;
}
this.req(req, function (res) { this.req(req, function (res) {
if (cb) cb(res.body); if (cb) cb(res.body);
@ -215,13 +219,27 @@ Client.prototype.reqScripts = function(cb) {
Client.prototype.reqContinue = function(cb) { Client.prototype.reqContinue = function(cb) {
this.req({ command: 'continue' } , function (res) { this.req({ command: 'continue' }, function (res) {
if (cb) cb(res);
});
};
// c.next(1, cb);
Client.prototype.step = function(action, count, cb) {
var req = {
command: 'continue',
arguments: { stepaction: action, stepcount: count }
};
this.req(req, function (res) {
if (cb) cb(res); if (cb) cb(res);
}); });
}; };
var helpMessage = "Commands: scripts, backtrace, version, eval, help, quit";
var helpMessage = "Commands: print, step, next, continue, scripts, backtrace, version, quit";
function SourceUnderline(source_text, position) { function SourceUnderline(source_text, position) {
if (!source_text) { if (!source_text) {
@ -303,7 +321,7 @@ function startInterface() {
}); });
term.on('line', function(cmd) { term.on('line', function(cmd) {
if (cmd == 'quit') { if (cmd == 'quit' || cmd == 'q' || cmd == 'exit') {
tryQuit(); tryQuit();
} else if (/^help/.test(cmd)) { } else if (/^help/.test(cmd)) {
console.log(helpMessage); console.log(helpMessage);
@ -322,9 +340,7 @@ function startInterface() {
} else if (bt.totalFrames == 0) { } else if (bt.totalFrames == 0) {
console.log('(empty stack)'); console.log('(empty stack)');
} else { } else {
var result = 'Frames #' + bt.fromFrame + var result = '';
' to #' + (bt.toFrame - 1) +
' of ' + bt.totalFrames + '\n';
for (j = 0; j < bt.frames.length; j++) { for (j = 0; j < bt.frames.length; j++) {
if (j != 0) result += '\n'; if (j != 0) result += '\n';
result += bt.frames[j].text; result += bt.frames[j].text;
@ -336,7 +352,17 @@ function startInterface() {
} else if (/^continue/.test(cmd) || /^c/.test(cmd)) { } else if (/^continue/.test(cmd) || /^c/.test(cmd)) {
c.reqContinue(function (res) { c.reqContinue(function (res) {
// Wait for break point. (disable raw mode?) // Wait for break point. (disable raw mode?)
});
} else if (/^next/.test(cmd) || /^n/.test(cmd)) {
c.step('next', 1, function (res) {
// Wait for break point. (disable raw mode?)
});
} else if (/^step/.test(cmd) || /^s/.test(cmd)) {
c.step('in', 1, function (res) {
// Wait for break point. (disable raw mode?)
}); });
} else if (/^scripts/.test(cmd)) { } else if (/^scripts/.test(cmd)) {
@ -350,11 +376,22 @@ function startInterface() {
term.prompt(); term.prompt();
}); });
} else if (/^eval/.test(cmd)) { } else if (/^print/.test(cmd) || /^p/.test(cmd)) {
c.reqEval(cmd.slice(5), function (res) { var i = cmd.indexOf(' ');
console.log(res); if (i < 0) {
console.log("print [expression]");
term.prompt(); term.prompt();
}); } else {
cmd = cmd.slice(i);
c.reqEval(cmd, function (res) {
if (res) {
console.log(res.text);
} else {
console.log(res);
}
term.prompt();
});
}
} else { } else {
if (!/^\s*$/.test(cmd)) { if (!/^\s*$/.test(cmd)) {

Loading…
Cancel
Save