[inspector] added restrictToFunction flag for getPossibleBreakpoints

BUG=chromium:695236
R=dgozman@chromium.org,yangguo@chromium.org

Review-Url: https://codereview.chromium.org/2710953004
Cr-Commit-Position: refs/heads/master@{#43457}
This commit is contained in:
kozyatinskiy 2017-02-27 08:53:03 -08:00 committed by Commit bot
parent 7d1d83e525
commit 4d7fa10c2b
11 changed files with 654 additions and 12 deletions

View File

@ -9241,7 +9241,7 @@ int GetSmiValue(i::Handle<i::FixedArray> array, int index) {
bool debug::Script::GetPossibleBreakpoints(
const debug::Location& start, const debug::Location& end,
std::vector<debug::Location>* locations) const {
bool restrict_to_function, std::vector<debug::Location>* locations) const {
CHECK(!start.IsEmpty());
i::Handle<i::Script> script = Utils::OpenHandle(this);
if (script->type() == i::Script::TYPE_WASM) {
@ -9267,8 +9267,8 @@ bool debug::Script::GetPossibleBreakpoints(
if (start_offset >= end_offset) return true;
std::set<int> offsets;
if (!isolate->debug()->GetPossibleBreakpoints(script, start_offset,
end_offset, &offsets)) {
if (!isolate->debug()->GetPossibleBreakpoints(
script, start_offset, end_offset, restrict_to_function, &offsets)) {
return false;
}

View File

@ -137,6 +137,7 @@ class V8_EXPORT_PRIVATE Script {
bool IsModule() const;
bool GetPossibleBreakpoints(const debug::Location& start,
const debug::Location& end,
bool restrict_to_function,
std::vector<debug::Location>* locations) const;
private:

View File

@ -1343,7 +1343,24 @@ void FindBreakablePositions(Handle<DebugInfo> debug_info, int start_position,
} // namespace
bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position,
int end_position, std::set<int>* positions) {
int end_position, bool restrict_to_function,
std::set<int>* positions) {
if (restrict_to_function) {
Handle<Object> result =
FindSharedFunctionInfoInScript(script, start_position);
if (result->IsUndefined(isolate_)) return false;
// Make sure the function has set up the debug info.
Handle<SharedFunctionInfo> shared =
Handle<SharedFunctionInfo>::cast(result);
if (!EnsureDebugInfo(shared)) return false;
Handle<DebugInfo> debug_info(shared->GetDebugInfo());
FindBreakablePositions(debug_info, start_position, end_position,
BREAK_POSITION_ALIGNED, positions);
return true;
}
while (true) {
HandleScope scope(isolate_);
List<Handle<SharedFunctionInfo>> candidates;

View File

@ -312,7 +312,8 @@ class Debug {
bool PrepareFunctionForBreakPoints(Handle<SharedFunctionInfo> shared);
bool GetPossibleBreakpoints(Handle<Script> script, int start_position,
int end_position, std::set<int>* positions);
int end_position, bool restrict_to_function,
std::set<int>* positions);
void RecordGenerator(Handle<JSGeneratorObject> generator_object);

View File

@ -534,7 +534,8 @@
"name": "getPossibleBreakpoints",
"parameters": [
{ "name": "start", "$ref": "Location", "description": "Start of range to search possible breakpoint locations in." },
{ "name": "end", "$ref": "Location", "optional": true, "description": "End of range to search possible breakpoint locations in (excluding). When not specifed, end of scripts is used as end of range." }
{ "name": "end", "$ref": "Location", "optional": true, "description": "End of range to search possible breakpoint locations in (excluding). When not specifed, end of scripts is used as end of range." },
{ "name": "restrictToFunction", "type": "boolean", "optional": true, "description": "Only consider locations which are in the same (non-nested) function as start." }
],
"returns": [
{ "name": "locations", "type": "array", "items": { "$ref": "Location" }, "description": "List of the possible breakpoint locations." }

View File

@ -361,7 +361,7 @@ void V8DebuggerAgentImpl::removeBreakpointImpl(const String16& breakpointId) {
Response V8DebuggerAgentImpl::getPossibleBreakpoints(
std::unique_ptr<protocol::Debugger::Location> start,
Maybe<protocol::Debugger::Location> end,
Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction,
std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations) {
String16 scriptId = start->getScriptId();
@ -386,7 +386,8 @@ Response V8DebuggerAgentImpl::getPossibleBreakpoints(
if (it == m_scripts.end()) return Response::Error("Script not found");
std::vector<v8::debug::Location> v8Locations;
if (!it->second->getPossibleBreakpoints(v8Start, v8End, &v8Locations))
if (!it->second->getPossibleBreakpoints(
v8Start, v8End, restrictToFunction.fromMaybe(false), &v8Locations))
return Response::InternalError();
*locations = protocol::Array<protocol::Debugger::Location>::create();

View File

@ -66,7 +66,7 @@ class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
override;
Response getPossibleBreakpoints(
std::unique_ptr<protocol::Debugger::Location> start,
Maybe<protocol::Debugger::Location> end,
Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction,
std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations)
override;
Response setScriptSource(

View File

@ -172,10 +172,12 @@ class ActualScript : public V8DebuggerScript {
bool getPossibleBreakpoints(
const v8::debug::Location& start, const v8::debug::Location& end,
bool restrictToFunction,
std::vector<v8::debug::Location>* locations) override {
v8::HandleScope scope(m_isolate);
v8::Local<v8::debug::Script> script = m_script.Get(m_isolate);
return script->GetPossibleBreakpoints(start, end, locations);
return script->GetPossibleBreakpoints(start, end, restrictToFunction,
locations);
}
void resetBlackboxedStateCache() override {
@ -228,6 +230,7 @@ class WasmVirtualScript : public V8DebuggerScript {
bool getPossibleBreakpoints(
const v8::debug::Location& start, const v8::debug::Location& end,
bool restrictToFunction,
std::vector<v8::debug::Location>* locations) override {
v8::HandleScope scope(m_isolate);
v8::Local<v8::debug::Script> script = m_script.Get(m_isolate);
@ -247,8 +250,8 @@ class WasmVirtualScript : public V8DebuggerScript {
scriptId(), v8ScriptId);
}
bool success = script->GetPossibleBreakpoints(translatedStart,
translatedEnd, locations);
bool success = script->GetPossibleBreakpoints(
translatedStart, translatedEnd, restrictToFunction, locations);
for (v8::debug::Location& loc : *locations) {
TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId,
scriptId());

View File

@ -77,6 +77,7 @@ class V8DebuggerScript {
virtual bool getPossibleBreakpoints(
const v8::debug::Location& start, const v8::debug::Location& end,
bool ignoreNestedFunctions,
std::vector<v8::debug::Location>* locations) = 0;
virtual void resetBlackboxedStateCache() = 0;

View File

@ -0,0 +1,497 @@
Checks Debugger.getPossibleBreakpoints with ignoreNestedFunctions
Running test: testWholeFunction
function test() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
function nested1() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
#}
function nested2() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
#}
#nested1();
#nested2();
#}
//# sourceURL=test.js
Running test: testWholeFunctionWithoutNested
function test() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
function nested1() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
#}
function nested2() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
#}
#nested1();
#nested2();
#}
//# sourceURL=test.js
Running test: testPartOfFunctionWithoutNested
function test() {
#Array.#from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Running test: testNestedFunction
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
#}
function nested2() {
#Array.#from([1,2]).#map(() => #1#).#filter(() => #true#);
#}
#nested1();
#nested2();
#}
//# sourceURL=test.js
Run test() to check breakpoints..
test (test.js:9:2)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
^nested1();
nested2();
}
//# sourceURL=test.js
nested1 (test.js:4:4)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
^Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested1 (test.js:4:10)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.^from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested1 (test.js:4:22)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).^map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:4:32)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => ^1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:4:33)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1^).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:4:32)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => ^1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:4:33)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1^).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested1 (test.js:4:35)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).^filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:4:48)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => ^true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:4:52)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true^);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:4:48)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => ^true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:4:52)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true^);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested1 (test.js:5:2)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
^}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
test (test.js:10:2)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
^nested2();
}
//# sourceURL=test.js
nested2 (test.js:7:4)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
^Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested2 (test.js:7:10)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.^from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested2 (test.js:7:22)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).^map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:7:32)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => ^1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:7:33)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1^).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:7:32)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => ^1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map (test.js:7:33)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1^).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested2 (test.js:7:35)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).^filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:7:48)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => ^true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:7:52)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true^);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:7:48)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => ^true);
}
nested1();
nested2();
}
//# sourceURL=test.js
Array.from.map.filter (test.js:7:52)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true^);
}
nested1();
nested2();
}
//# sourceURL=test.js
nested2 (test.js:8:2)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
^}
nested1();
nested2();
}
//# sourceURL=test.js
test (test.js:11:0)
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
^}
//# sourceURL=test.js

View File

@ -0,0 +1,120 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
print('Checks Debugger.getPossibleBreakpoints with ignoreNestedFunctions');
var source = `
function test() {
Array.from([1,2]).map(() => 1).filter(() => true);
function nested1() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
function nested2() {
Array.from([1,2]).map(() => 1).filter(() => true);
}
nested1();
nested2();
}
//# sourceURL=test.js`;
InspectorTest.addScript(source);
var scriptId;
Protocol.Debugger.onceScriptParsed().then(message => {
if (message.params.url === 'test.js')
scriptId = message.params.scriptId;
}).then(() => InspectorTest.runTestSuite(tests));
InspectorTest.setupScriptMap();
Protocol.Debugger.onPaused(dumpBreakLocationInSourceAndResume);
Protocol.Debugger.enable();
var tests = [
function testWholeFunction(next) {
Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), ignoreNestedFunctions: false })
.then(dumpAllLocations)
.then(next);
},
function testWholeFunctionWithoutNested(next) {
Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), ignoreNestedFunctions: true })
.then(dumpAllLocations)
.then(next);
},
function testPartOfFunctionWithoutNested(next) {
Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), end: location(2, 18), ignoreNestedFunctions: true })
.then(dumpAllLocations)
.then(next);
},
function testNestedFunction(next) {
Protocol.Debugger.getPossibleBreakpoints({ start: location(4, 0), ignoreNestedFunctions: true })
.then(dumpAllLocations)
.then(setAllBreakpoints)
.then(() => InspectorTest.log('Run test() to check breakpoints..'))
.then(() => Protocol.Runtime.evaluate({ expression: 'test()' }))
.then(next);
}
];
function location(lineNumber, columnNumber) {
return { lineNumber: lineNumber, columnNumber: columnNumber, scriptId: scriptId };
}
function setAllBreakpoints(message) {
var promises = [];
for (var location of message.result.locations)
promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(checkBreakpoint));
return Promise.all(promises);
}
function checkBreakpoint(message) {
if (message.error) {
InspectorTest.log('FAIL: error in setBreakpoint');
InspectorTest.logMessage(message);
return;
}
var id_data = message.result.breakpointId.split(':');
if (parseInt(id_data[1]) !== message.result.actualLocation.lineNumber || parseInt(id_data[2]) !== message.result.actualLocation.columnNumber) {
InspectorTest.log('FAIL: possible breakpoint was resolved in another location');
}
}
function dumpAllLocations(message) {
if (message.error) {
InspectorTest.logMessage(message);
return;
}
var sourceLines = source.split('\n')
var lineOffsets = Array(sourceLines.length).fill(0);
for (var location of message.result.locations) {
var lineNumber = location.lineNumber;
var columnNumber = location.columnNumber;
var line = sourceLines[lineNumber] || '';
var offset = lineOffsets[lineNumber];
line = line.slice(0, columnNumber + offset) + '#' + line.slice(columnNumber + offset);
++lineOffsets[lineNumber];
sourceLines[lineNumber] = line;
}
InspectorTest.log(sourceLines.join('\n'));
return message;
}
function dumpBreakLocationInSourceAndResume(message) {
InspectorTest.logCallFrames([ message.params.callFrames[0] ]);
var location = message.params.callFrames[0].location;
var sourceLines = source.split('\n')
var lineNumber = location.lineNumber
var columnNumber = location.columnNumber;
var line = sourceLines[lineNumber];
line = line.slice(0, columnNumber) + '^' + line.slice(columnNumber);
sourceLines[lineNumber] = line;
InspectorTest.log(sourceLines.join('\n'));
InspectorTest.log('');
Protocol.Debugger.resume();
}