2020-08-11 08:45:40 +00:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start(
|
|
|
|
'Tests that stepOver and stepInto correctly handle skipLists.');
|
|
|
|
|
|
|
|
function test(input) {
|
|
|
|
debugger;
|
|
|
|
var a = 4;
|
|
|
|
var sum = 0;
|
|
|
|
if (input > 0) {
|
|
|
|
sum = a + input;
|
|
|
|
}
|
|
|
|
var b = 5;
|
|
|
|
sum = add(sum, b);
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
function add(a, b) {
|
2020-08-12 11:22:36 +00:00
|
|
|
var res = a + b;
|
|
|
|
return res;
|
2020-08-11 08:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contextGroup.addScript(`${test} //# sourceURL=test.js`);
|
|
|
|
contextGroup.addScript(`${add}`);
|
|
|
|
|
|
|
|
const first_non_debug_line_offset = 2;
|
|
|
|
const last_line_line_offset = 9;
|
|
|
|
const function_call_line_offset = 8;
|
|
|
|
const function_call_column_offset = 2;
|
|
|
|
const if_case_line_offset = 4;
|
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
const add_first_line_line_offset = 1;
|
|
|
|
const add_last_line_line_offset = 2;
|
|
|
|
const add_last_line_column_offset = 13;
|
|
|
|
|
2020-08-11 08:45:40 +00:00
|
|
|
Protocol.Debugger.enable();
|
|
|
|
runTest()
|
|
|
|
.catch(reason => InspectorTest.log(`Failed: ${reason}`))
|
|
|
|
.then(InspectorTest.completeTest);
|
|
|
|
|
|
|
|
async function runTest() {
|
2020-08-12 11:22:36 +00:00
|
|
|
const response = await Protocol.Debugger.onceScriptParsed(2);
|
|
|
|
const scriptIds = response.map(msg => msg.params.scriptId);
|
2020-08-11 08:45:40 +00:00
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
await checkValidSkipLists(scriptIds[0], scriptIds[1]);
|
|
|
|
await checkInvalidSkipLists(scriptIds[0]);
|
2020-08-11 08:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function checkInvalidSkipLists(scriptId) {
|
2020-08-12 11:22:36 +00:00
|
|
|
const actions = ['stepOver', 'stepInto'];
|
|
|
|
for (let action of actions) {
|
|
|
|
InspectorTest.log('Test: start position has invalid column number');
|
|
|
|
let skipList = [createLocationRange(
|
|
|
|
scriptId, first_non_debug_line_offset, -1, last_line_line_offset, 0)];
|
|
|
|
await testStep(skipList, action);
|
|
|
|
|
|
|
|
InspectorTest.log('Test: start position has invalid line number');
|
|
|
|
skipList =
|
|
|
|
[createLocationRange(scriptId, -1, 0, first_non_debug_line_offset, 0)];
|
|
|
|
await testStep(skipList, action);
|
|
|
|
|
|
|
|
InspectorTest.log('Test: end position smaller than start position');
|
|
|
|
skipList = [createLocationRange(
|
|
|
|
scriptId, if_case_line_offset, 0, first_non_debug_line_offset, 0)];
|
|
|
|
await testStep(skipList, action);
|
|
|
|
|
|
|
|
InspectorTest.log('Test: skip list is not maximally merged');
|
|
|
|
skipList = [
|
|
|
|
createLocationRange(
|
|
|
|
scriptId, first_non_debug_line_offset, 0, if_case_line_offset, 0),
|
|
|
|
createLocationRange(
|
|
|
|
scriptId, if_case_line_offset, 0, last_line_line_offset, 0)
|
|
|
|
];
|
|
|
|
await testStep(skipList, action);
|
|
|
|
|
|
|
|
InspectorTest.log('Test: skip list is not sorted');
|
|
|
|
skipList = [
|
|
|
|
createLocationRange(
|
|
|
|
scriptId, function_call_line_offset, 0, last_line_line_offset, 0),
|
|
|
|
createLocationRange(
|
|
|
|
scriptId, first_non_debug_line_offset, 0, if_case_line_offset, 0)
|
|
|
|
];
|
|
|
|
await testStep(skipList, action);
|
|
|
|
}
|
|
|
|
}
|
2020-08-11 08:45:40 +00:00
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
async function checkValidSkipLists(testScriptId, addScriptId) {
|
|
|
|
InspectorTest.log('Test: Stepping over without skip list');
|
|
|
|
await testStep([], 'stepOver');
|
2020-08-11 08:45:40 +00:00
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
InspectorTest.log('Test: Stepping over with skip list');
|
|
|
|
let skipList = [
|
|
|
|
createLocationRange(
|
|
|
|
testScriptId, first_non_debug_line_offset, 0, if_case_line_offset, 0),
|
|
|
|
createLocationRange(
|
|
|
|
testScriptId, function_call_line_offset, 0, last_line_line_offset, 0)
|
|
|
|
];
|
|
|
|
await testStep(skipList, 'stepOver');
|
|
|
|
|
|
|
|
InspectorTest.log('Test: Stepping over start location is inclusive');
|
|
|
|
skipList = [createLocationRange(
|
|
|
|
testScriptId, function_call_line_offset, function_call_column_offset,
|
|
|
|
last_line_line_offset, 0)];
|
|
|
|
await testStep(skipList, 'stepOver');
|
|
|
|
|
|
|
|
InspectorTest.log('Test: Stepping over end location is exclusive');
|
2020-08-11 08:45:40 +00:00
|
|
|
skipList = [createLocationRange(
|
2020-08-12 11:22:36 +00:00
|
|
|
testScriptId, first_non_debug_line_offset, 0, function_call_line_offset,
|
|
|
|
function_call_column_offset)];
|
|
|
|
await testStep(skipList, 'stepOver');
|
|
|
|
|
|
|
|
InspectorTest.log('Test: Stepping into without skip list');
|
|
|
|
skipList = [];
|
|
|
|
await testStep(skipList, 'stepInto');
|
2020-08-11 08:45:40 +00:00
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
InspectorTest.log(
|
|
|
|
'Test: Stepping into with skip list, while call itself is skipped');
|
2020-08-11 08:45:40 +00:00
|
|
|
skipList = [
|
|
|
|
createLocationRange(
|
2020-08-12 11:22:36 +00:00
|
|
|
addScriptId, add_first_line_line_offset, 0, add_last_line_line_offset,
|
|
|
|
0),
|
2020-08-11 08:45:40 +00:00
|
|
|
createLocationRange(
|
2020-08-12 11:22:36 +00:00
|
|
|
testScriptId, first_non_debug_line_offset, 0,
|
|
|
|
function_call_line_offset + 1, 0),
|
2020-08-11 08:45:40 +00:00
|
|
|
];
|
2020-08-12 11:22:36 +00:00
|
|
|
await testStep(skipList, 'stepInto');
|
2020-08-11 08:45:40 +00:00
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
InspectorTest.log('Test: Stepping into start location is inclusive');
|
2020-08-11 08:45:40 +00:00
|
|
|
skipList = [
|
|
|
|
createLocationRange(
|
2020-08-12 11:22:36 +00:00
|
|
|
addScriptId, add_last_line_line_offset, add_last_line_column_offset,
|
|
|
|
add_last_line_line_offset + 1, 0),
|
2020-08-11 08:45:40 +00:00
|
|
|
];
|
2020-08-12 11:22:36 +00:00
|
|
|
await testStep(skipList, 'stepInto');
|
2020-08-11 08:45:40 +00:00
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
InspectorTest.log('Test: Stepping into end location is exclusive');
|
|
|
|
skipList = [
|
2020-08-11 08:45:40 +00:00
|
|
|
createLocationRange(
|
2020-08-12 11:22:36 +00:00
|
|
|
addScriptId, add_last_line_line_offset - 1, 0,
|
|
|
|
add_last_line_line_offset, add_last_line_column_offset),
|
2020-08-11 08:45:40 +00:00
|
|
|
];
|
2020-08-12 11:22:36 +00:00
|
|
|
await testStep(skipList, 'stepInto');
|
2020-08-11 08:45:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
async function testStep(skipList, stepAction) {
|
2020-08-11 08:45:40 +00:00
|
|
|
InspectorTest.log(
|
2020-08-12 11:22:36 +00:00
|
|
|
`Testing ${stepAction} with skipList: ${JSON.stringify(skipList)}`);
|
2020-08-11 08:45:40 +00:00
|
|
|
Protocol.Runtime.evaluate({expression: 'test(5);'});
|
|
|
|
while (true) {
|
|
|
|
const pausedMsg = await Protocol.Debugger.oncePaused();
|
|
|
|
const topCallFrame = pausedMsg.params.callFrames[0];
|
|
|
|
printCallFrame(topCallFrame);
|
|
|
|
if (topCallFrame.location.lineNumber == last_line_line_offset) break;
|
|
|
|
|
2020-08-12 11:22:36 +00:00
|
|
|
const stepOverMsg = await Protocol.Debugger[stepAction]({skipList});
|
2020-08-11 08:45:40 +00:00
|
|
|
if (stepOverMsg.error) {
|
|
|
|
InspectorTest.log(stepOverMsg.error.message);
|
|
|
|
Protocol.Debugger.resume();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await Protocol.Debugger.resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
function createLocationRange(
|
|
|
|
scriptId, startLine, startColumn, endLine, endColumn) {
|
|
|
|
return {
|
|
|
|
scriptId: scriptId,
|
|
|
|
start: {lineNumber: startLine, columnNumber: startColumn},
|
|
|
|
end: {lineNumber: endLine, columnNumber: endColumn}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printCallFrame(frame) {
|
|
|
|
InspectorTest.log(
|
|
|
|
frame.functionName + ': ' + frame.location.lineNumber + ':' +
|
|
|
|
frame.location.columnNumber);
|
|
|
|
}
|