Commit d689da91 authored by peter.rybin@gmail.com's avatar peter.rybin@gmail.com

Issue 1418: Debug: extends setBreakpoint API to accept partial script name as a parameter

Review URL: http://codereview.chromium.org/7200024

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8355 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 097060c6
......@@ -977,9 +977,14 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) {
// 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);
if (target[0] == '/' && target[target.length - 1] == '/') {
type = 'scriptRegExp';
target = target.substring(1, target.length - 1);
} else {
type = 'script';
}
// Check for both line and column.
pos = tmp.indexOf(':');
......@@ -1984,6 +1989,9 @@ function DebugResponseDetails(response) {
if (breakpoint.script_name) {
result += ' script_name=' + breakpoint.script_name;
}
if (breakpoint.script_regexp) {
result += ' script_regexp=' + breakpoint.script_regexp;
}
result += ' line=' + (breakpoint.line + 1);
if (breakpoint.column != null) {
result += ' column=' + (breakpoint.column + 1);
......
......@@ -68,7 +68,8 @@ Debug.ScriptCompilationType = { Host: 0,
// The different script break point types.
Debug.ScriptBreakPointType = { ScriptId: 0,
ScriptName: 1 };
ScriptName: 1,
ScriptRegExp: 2 };
function ScriptTypeFlag(type) {
return (1 << type);
......@@ -255,8 +256,12 @@ function ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column,
this.type_ = type;
if (type == Debug.ScriptBreakPointType.ScriptId) {
this.script_id_ = script_id_or_name;
} else { // type == Debug.ScriptBreakPointType.ScriptName
} else if (type == Debug.ScriptBreakPointType.ScriptName) {
this.script_name_ = script_id_or_name;
} else if (type == Debug.ScriptBreakPointType.ScriptRegExp) {
this.script_regexp_object_ = new RegExp(script_id_or_name);
} else {
throw new Error("Unexpected breakpoint type " + type);
}
this.line_ = opt_line || 0;
this.column_ = opt_column;
......@@ -309,6 +314,11 @@ ScriptBreakPoint.prototype.script_name = function() {
};
ScriptBreakPoint.prototype.script_regexp_object = function() {
return this.script_regexp_object_;
};
ScriptBreakPoint.prototype.line = function() {
return this.line_;
};
......@@ -384,10 +394,19 @@ ScriptBreakPoint.prototype.setIgnoreCount = function(ignoreCount) {
ScriptBreakPoint.prototype.matchesScript = function(script) {
if (this.type_ == Debug.ScriptBreakPointType.ScriptId) {
return this.script_id_ == script.id;
} else { // this.type_ == Debug.ScriptBreakPointType.ScriptName
return this.script_name_ == script.nameOrSourceURL() &&
script.line_offset <= this.line_ &&
this.line_ < script.line_offset + script.lineCount();
} else {
// We might want to account columns here as well.
if (!(script.line_offset <= this.line_ &&
this.line_ < script.line_offset + script.lineCount())) {
return false;
}
if (this.type_ == Debug.ScriptBreakPointType.ScriptName) {
return this.script_name_ == script.nameOrSourceURL();
} else if (this.type_ == Debug.ScriptBreakPointType.ScriptRegExp) {
return this.script_regexp_object_.test(script.nameOrSourceURL());
} else {
throw new Error("Unexpected breakpoint type " + this.type_);
}
}
};
......@@ -431,7 +450,8 @@ ScriptBreakPoint.prototype.set = function (script) {
}
var actual_location = script.locationFromPosition(actual_position, true);
break_point.actual_location = { line: actual_location.line,
column: actual_location.column };
column: actual_location.column,
script_id: script.id };
this.break_points_.push(break_point);
return break_point;
};
......@@ -644,7 +664,8 @@ Debug.setBreakPoint = function(func, opt_line, opt_column, opt_condition) {
actual_position += this.sourcePosition(func);
var actual_location = script.locationFromPosition(actual_position, true);
break_point.actual_location = { line: actual_location.line,
column: actual_location.column };
column: actual_location.column,
script_id: script.id };
break_point.setCondition(opt_condition);
return break_point.number();
}
......@@ -799,6 +820,15 @@ Debug.setScriptBreakPointByName = function(script_name,
}
Debug.setScriptBreakPointByRegExp = function(script_regexp,
opt_line, opt_column,
opt_condition, opt_groupId) {
return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptRegExp,
script_regexp, opt_line, opt_column,
opt_condition, opt_groupId);
}
Debug.enableScriptBreakPoint = function(break_point_number) {
var script_break_point = this.findScriptBreakPoint(break_point_number, false);
script_break_point.enable();
......@@ -1549,12 +1579,7 @@ DebugCommandProcessor.prototype.setBreakPointRequest_ =
response.failed('Missing argument "type" or "target"');
return;
}
if (type != 'function' && type != 'handle' &&
type != 'script' && type != 'scriptId') {
response.failed('Illegal type "' + type + '"');
return;
}
// Either function or script break point.
var break_point_number;
if (type == 'function') {
......@@ -1598,9 +1623,16 @@ DebugCommandProcessor.prototype.setBreakPointRequest_ =
break_point_number =
Debug.setScriptBreakPointByName(target, line, column, condition,
groupId);
} else { // type == 'scriptId.
} else if (type == 'scriptId') {
break_point_number =
Debug.setScriptBreakPointById(target, line, column, condition, groupId);
} else if (type == 'scriptRegExp') {
break_point_number =
Debug.setScriptBreakPointByRegExp(target, line, column, condition,
groupId);
} else {
response.failed('Illegal type "' + type + '"');
return;
}
// Set additional break point properties.
......@@ -1621,9 +1653,14 @@ DebugCommandProcessor.prototype.setBreakPointRequest_ =
if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) {
response.body.type = 'scriptId';
response.body.script_id = break_point.script_id();
} else {
} else if (break_point.type() == Debug.ScriptBreakPointType.ScriptName) {
response.body.type = 'scriptName';
response.body.script_name = break_point.script_name();
} else if (break_point.type() == Debug.ScriptBreakPointType.ScriptRegExp) {
response.body.type = 'scriptRegExp';
response.body.script_regexp = break_point.script_regexp_object().source;
} else {
throw new Error("Internal error: Unexpected breakpoint type: " + break_point.type());
}
response.body.line = break_point.line();
response.body.column = break_point.column();
......@@ -1753,9 +1790,14 @@ DebugCommandProcessor.prototype.listBreakpointsRequest_ = function(request, resp
if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) {
description.type = 'scriptId';
description.script_id = break_point.script_id();
} else {
} else if (break_point.type() == Debug.ScriptBreakPointType.ScriptName) {
description.type = 'scriptName';
description.script_name = break_point.script_name();
} else if (break_point.type() == Debug.ScriptBreakPointType.ScriptRegExp) {
description.type = 'scriptRegExp';
description.script_regexp = break_point.script_regexp_object().source;
} else {
throw new Error("Internal error: Unexpected breakpoint type: " + break_point.type());
}
array.push(description);
}
......
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