Commit 7fd0da52 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Add setting break points by using handles.

Extend the D8 break command to handle script names with :line[:column] position specification and handles using #<id>#.
Review URL: http://codereview.chromium.org/92011

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1770 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent befbeba8
......@@ -653,17 +653,47 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) {
// Process arguments if any.
if (args && args.length > 0) {
var target = args;
var type = 'function';
var line;
var column;
var condition;
var pos;
var pos = args.indexOf(' ');
// Check for breakpoint condition.
pos = args.indexOf(' ');
if (pos > 0) {
target = args.substring(0, pos);
condition = args.substring(pos + 1, args.length);
}
// Check for script breakpoint (name:line[:column]). If no ':' in break
// specification it is considered a function break point.
pos = target.indexOf(':');
if (pos > 0) {
type = 'script';
var tmp = target.substring(pos + 1, target.length);
target = target.substring(0, pos);
// Check for both line and column.
pos = tmp.indexOf(':');
if (pos > 0) {
column = parseInt(tmp.substring(pos + 1, tmp.length)) - 1;
line = parseInt(tmp.substring(0, pos)) - 1;
} else {
line = parseInt(tmp) - 1;
}
} else if (target[0] == '#' && target[target.length - 1] == '#') {
type = 'handle';
target = target.substring(1, target.length - 1);
} else {
type = 'function';
}
request.arguments = {};
request.arguments.type = 'function';
request.arguments.type = type;
request.arguments.target = target;
request.arguments.line = line;
request.arguments.column = column;
request.arguments.condition = condition;
} else {
throw new Error('Invalid break arguments.');
......@@ -721,6 +751,9 @@ DebugRequest.prototype.helpCommand_ = function(args) {
}
print('break location [condition]');
print(' break on named function: location is a function name');
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('frame <frame #>');
......
......@@ -1273,11 +1273,12 @@ DebugCommandProcessor.prototype.setBreakPointRequest_ =
var ignoreCount = request.arguments.ignoreCount;
// Check for legal arguments.
if (!type || !target) {
if (!type || IS_UNDEFINED(target)) {
response.failed('Missing argument "type" or "target"');
return;
}
if (type != 'function' && type != 'script' && type != 'scriptId') {
if (type != 'function' && type != 'handle' &&
type != 'script' && type != 'scriptId') {
response.failed('Illegal type "' + type + '"');
return;
}
......@@ -1306,6 +1307,20 @@ DebugCommandProcessor.prototype.setBreakPointRequest_ =
// Set function break point.
break_point_number = Debug.setBreakPoint(f, line, column, condition);
} else if (type == 'handle') {
// Find the object pointed by the specified handle.
var handle = parseInt(target, 10);
var mirror = LookupMirror(handle);
if (!mirror) {
return response.failed('Object #' + handle + '# not found');
}
if (!mirror.isFunction()) {
return response.failed('Object #' + handle + '# is not a function');
}
// Set function break point.
break_point_number = Debug.setBreakPoint(mirror.value(),
line, column, condition);
} else if (type == 'script') {
// set script break point.
break_point_number =
......
......@@ -54,14 +54,14 @@ function testArguments(dcp, arguments, success, is_script) {
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
if (success) {
assertTrue(response.success, json_response);
assertTrue(response.success, request + ' -> ' + json_response);
if (is_script) {
assertEquals('scriptName', response.body.type, json_response);
assertEquals('scriptName', response.body.type, request + ' -> ' + json_response);
} else {
assertEquals('scriptId', response.body.type, json_response);
assertEquals('scriptId', response.body.type, request + ' -> ' + json_response);
}
} else {
assertFalse(response.success, json_response);
assertFalse(response.success, request + ' -> ' + json_response);
}
}
......@@ -75,6 +75,8 @@ function listener(event, exec_state, event_data, data) {
var request = '{' + base_request + '}'
var response = safeEval(dcp.processDebugJSONRequest(request));
assertFalse(response.success);
var mirror;
testArguments(dcp, '{}', false);
testArguments(dcp, '{"type":"xx"}', false);
......@@ -86,6 +88,9 @@ function listener(event, exec_state, event_data, data) {
testArguments(dcp, '{"type":"function","target":"f","line":-1}', false);
testArguments(dcp, '{"type":"function","target":"f","column":-1}', false);
testArguments(dcp, '{"type":"function","target":"f","ignoreCount":-1}', false);
testArguments(dcp, '{"type":"handle","target":"-1"}', false);
mirror = debug.MakeMirror(o);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', false);
// Test some legal setbreakpoint requests.
testArguments(dcp, '{"type":"function","target":"f"}', true, false);
......@@ -106,6 +111,11 @@ function listener(event, exec_state, event_data, data) {
testArguments(dcp, '{"type":"scriptId","target":' + g_script_id + ',"line":' + g_line + '}', true, false);
testArguments(dcp, '{"type":"scriptId","target":' + h_script_id + ',"line":' + h_line + '}', true, false);
mirror = debug.MakeMirror(f);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', true, false);
mirror = debug.MakeMirror(o.a);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', true, false);
// Indicate that all was processed.
listenerComplete = true;
}
......@@ -127,6 +137,8 @@ function g() {
eval('function h(){}');
o = {a:function(){},b:function(){}}
// Check the script ids for the test functions.
f_script_id = Debug.findScript(f).id;
g_script_id = Debug.findScript(g).id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment