Added support to backtrace from botton of stack to debugger protocol.

Fixed backtrace in D8 debugger and added gdb like syntax 'bt n' and 'bt -n' in addition to the already existing 'bt from to'.
Review URL: http://codereview.chromium.org/99342

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1929 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
sgjesse@chromium.org 2009-05-13 08:54:50 +00:00
parent 83f2c1968f
commit ada3d37219
3 changed files with 56 additions and 11 deletions

View File

@ -498,9 +498,26 @@ DebugRequest.prototype.stepCommandToJSONRequest_ = function(args) {
DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) {
// Build a backtrace request from the text command.
var request = this.createRequest('backtrace');
// Default is to show top 10 frames.
request.arguments = {};
request.arguments.fromFrame = 0;
request.arguments.toFrame = 10;
args = args.split(/\s*[ ]+\s*/g);
if (args.length == 2) {
request.arguments = {};
if (args.length == 1 && args[0].length > 0) {
var frameCount = parseInt(args[0]);
if (frameCount > 0) {
// Show top frames.
request.arguments.fromFrame = 0;
request.arguments.toFrame = frameCount;
} else {
// Show bottom frames.
request.arguments.fromFrame = 0;
request.arguments.toFrame = -frameCount;
request.arguments.bottom = true;
}
} else if (args.length == 2) {
var fromFrame = parseInt(args[0]);
var toFrame = parseInt(args[1]);
if (isNaN(fromFrame) || fromFrame < 0) {
@ -513,9 +530,13 @@ DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) {
throw new Error('Invalid arguments start frame cannot be larger ' +
'than end frame.');
}
// Show frame range.
request.arguments.fromFrame = fromFrame;
request.arguments.toFrame = toFrame + 1;
} else if (args.length > 2) {
throw new Error('Invalid backtrace arguments.');
}
return request.toJSONProtocol();
};
@ -755,7 +776,7 @@ DebugRequest.prototype.helpCommand_ = function(args) {
print(' break on function: location is #<id>#');
print(' break on script position: location is name:line[:column]');
print('clear <breakpoint #>');
print('backtrace [from frame #] [to frame #]]');
print('backtrace [n] | [-n] | [from to]');
print('frame <frame #>');
print('step [in | next | out| min [step count]]');
print('print <expression>');

View File

@ -1452,12 +1452,18 @@ DebugCommandProcessor.prototype.backtraceRequest_ = function(request, response)
// Get the range from the arguments.
if (request.arguments) {
from_index = request.arguments.fromFrame;
if (from_index < 0) {
return response.failed('Invalid frame number');
if (request.arguments.fromFrame) {
from_index = request.arguments.fromFrame;
}
to_index = request.arguments.toFrame;
if (to_index < 0) {
if (request.arguments.toFrame) {
to_index = request.arguments.toFrame;
}
if (request.arguments.bottom) {
var tmp_index = total_frames - from_index;
from_index = total_frames - to_index
to_index = tmp_index;
}
if (from_index < 0 || to_index < 0) {
return response.failed('Invalid frame number');
}
}

View File

@ -37,7 +37,7 @@ var m = function() {
};
function g() {
m();
m();
};
@ -80,8 +80,9 @@ function listener(event, exec_state, event_data, data) {
{
// The expected backtrace is
// 0: f
// 1: g
// 2: [anonymous]
// 1: m
// 2: g
// 3: [anonymous]
var response;
var backtrace;
@ -133,6 +134,23 @@ function listener(event, exec_state, event_data, data) {
assertEquals(2, frames[1].index);
assertEquals("g", response.lookup(frames[1].func.ref).name);
// Get backtrace with bottom two frames.
json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFrame":0,"toFrame":2, "bottom":true}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
backtrace = response.body();
assertEquals(2, backtrace.fromFrame);
assertEquals(4, backtrace.toFrame);
assertEquals(4, backtrace.totalFrames);
var frames = backtrace.frames;
assertEquals(2, frames.length);
for (var i = 0; i < frames.length; i++) {
assertEquals('frame', frames[i].type);
}
assertEquals(2, frames[0].index);
assertEquals("g", response.lookup(frames[0].func.ref).name);
assertEquals(3, frames[1].index);
assertEquals("", response.lookup(frames[1].func.ref).name);
// Get the individual frames.
json = '{"seq":0,"type":"request","command":"frame"}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));