2021-01-05 06:07:29 +00:00
|
|
|
// Copyright 2019 the V8 project authors. All rights reserved.
|
2017-07-02 19:18:57 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-09-22 19:33:11 +00:00
|
|
|
// Flags: --experimental-wasm-type-reflection --experimental-wasm-simd
|
|
|
|
// SIMD in Liftoff only works with these cpu features, force them on.
|
|
|
|
// Flags: --enable-sse3 --enable-ssse3 --enable-sse4-1
|
2020-06-03 11:55:31 +00:00
|
|
|
|
2020-06-10 03:54:24 +00:00
|
|
|
utils.load('test/inspector/wasm-inspector-test.js');
|
|
|
|
|
2017-07-02 19:18:57 +00:00
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start(
|
2021-01-05 06:07:29 +00:00
|
|
|
'Test retrieving scope information from compiled Liftoff frames');
|
2017-07-02 19:18:57 +00:00
|
|
|
session.setupScriptMap();
|
|
|
|
Protocol.Debugger.enable();
|
2020-01-13 08:39:01 +00:00
|
|
|
Protocol.Debugger.onPaused(printPauseLocationsAndContinue);
|
2017-07-02 19:18:57 +00:00
|
|
|
|
2021-01-05 06:07:29 +00:00
|
|
|
let breakpointLocation = -1;
|
2020-01-09 12:11:55 +00:00
|
|
|
|
2021-01-05 05:51:52 +00:00
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
|
|
async function test() {
|
|
|
|
// Instantiate wasm and wait for three wasm scripts for the three functions.
|
|
|
|
instantiateWasm();
|
|
|
|
let scriptIds = await waitForWasmScripts();
|
|
|
|
|
|
|
|
// Set a breakpoint.
|
|
|
|
InspectorTest.log(
|
2021-01-05 06:07:29 +00:00
|
|
|
'Setting breakpoint on line 2 (first instruction) of third function');
|
|
|
|
let breakpoint = await Protocol.Debugger.setBreakpoint(
|
|
|
|
{'location': {'scriptId': scriptIds[0], 'lineNumber': 0, 'columnNumber': breakpointLocation}});
|
2021-01-05 05:51:52 +00:00
|
|
|
printIfFailure(breakpoint);
|
|
|
|
InspectorTest.logMessage(breakpoint.result.actualLocation);
|
|
|
|
|
|
|
|
// Now run the wasm code.
|
2021-01-05 06:07:29 +00:00
|
|
|
await WasmInspectorTest.evalWithUrl('instance.exports.main(42)', 'runWasm');
|
2021-01-05 05:51:52 +00:00
|
|
|
InspectorTest.log('exports.main returned. Test finished.');
|
|
|
|
}
|
|
|
|
]);
|
2017-07-02 19:18:57 +00:00
|
|
|
|
2020-01-13 08:39:01 +00:00
|
|
|
async function printPauseLocationsAndContinue(msg) {
|
|
|
|
let loc = msg.params.callFrames[0].location;
|
|
|
|
InspectorTest.log('Paused:');
|
|
|
|
await session.logSourceLocation(loc);
|
|
|
|
InspectorTest.log('Scope:');
|
|
|
|
for (var frame of msg.params.callFrames) {
|
|
|
|
var isWasmFrame = /^wasm/.test(frame.url);
|
|
|
|
var functionName = frame.functionName || '(anonymous)';
|
|
|
|
var lineNumber = frame.location.lineNumber;
|
|
|
|
var columnNumber = frame.location.columnNumber;
|
|
|
|
InspectorTest.log(`at ${functionName} (${lineNumber}:${columnNumber}):`);
|
|
|
|
for (var scope of frame.scopeChain) {
|
|
|
|
InspectorTest.logObject(' - scope (' + scope.type + '):');
|
|
|
|
if (!isWasmFrame && scope.type == 'global') {
|
|
|
|
// Skip global scope for non wasm-functions.
|
|
|
|
InspectorTest.logObject(' -- skipped globals');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var properties = await Protocol.Runtime.getProperties(
|
|
|
|
{'objectId': scope.object.objectId});
|
2020-06-10 03:54:24 +00:00
|
|
|
await WasmInspectorTest.dumpScopeProperties(properties);
|
2020-01-13 08:39:01 +00:00
|
|
|
}
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
2020-01-13 08:39:01 +00:00
|
|
|
InspectorTest.log();
|
|
|
|
Protocol.Debugger.stepOver();
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function instantiateWasm() {
|
|
|
|
var builder = new WasmModuleBuilder();
|
2020-05-26 03:14:02 +00:00
|
|
|
// Add a global, memory and exports to populate the module scope.
|
|
|
|
builder.addGlobal(kWasmI32, true).exportAs('exported_global');
|
|
|
|
builder.addMemory(1,1).exportMemoryAs('exported_memory');
|
2020-06-03 11:55:31 +00:00
|
|
|
builder.addTable(kWasmAnyFunc, 3).exportAs('exported_table');
|
2017-07-02 19:18:57 +00:00
|
|
|
|
2021-01-05 06:07:29 +00:00
|
|
|
// Add two functions without breakpoint, to check that locals and operand
|
|
|
|
// stack values are shown correctly in Liftoff code.
|
|
|
|
// Function A will have its parameter spilled to the stack, because it calls
|
|
|
|
// function B.
|
|
|
|
// Function B has a local with a constant value (not using a register), the
|
|
|
|
// parameter will be held in a register.
|
|
|
|
const main = builder.addFunction('A (liftoff)', kSig_v_i)
|
|
|
|
.addBody([
|
|
|
|
// Call function 'B', forwarding param 0.
|
|
|
|
kExprLocalGet, 0, kExprCallFunction, 1
|
|
|
|
])
|
|
|
|
.exportAs('main');
|
|
|
|
|
|
|
|
builder.addFunction('B (liftoff)', kSig_v_i, ['i32_arg'])
|
|
|
|
.addLocals(kWasmI32, 1, ['i32_local'])
|
|
|
|
.addLocals(kWasmF32, 4, ['f32_local', '0', '0'])
|
|
|
|
.addLocals(kWasmS128, 1, ['v128_local'])
|
|
|
|
.addBody([
|
|
|
|
// Load a parameter and a constant onto the operand stack.
|
|
|
|
kExprLocalGet, 0, kExprI32Const, 3,
|
|
|
|
// Set local 6 to v128 i32.x4 23, 23, 23, 23.
|
|
|
|
kExprI32Const, 23,
|
|
|
|
kSimdPrefix, kExprI32x4Splat,
|
|
|
|
kExprLocalSet, 6,
|
|
|
|
// Set local 2 to 7.2.
|
|
|
|
...wasmF32Const(7.2), kExprLocalSet, 2,
|
|
|
|
// Call function 'C', forwarding param 0.
|
|
|
|
kExprLocalGet, 0, kExprCallFunction, 2,
|
|
|
|
// Drop the two operand stack values.
|
|
|
|
kExprDrop, kExprDrop
|
|
|
|
]);
|
|
|
|
|
|
|
|
// A third function which will be stepped through.
|
|
|
|
let func = builder.addFunction('C (interpreted)', kSig_v_i, ['i32_arg'])
|
|
|
|
.addLocals(kWasmI32, 1, ['i32_local'])
|
|
|
|
.addLocals(kWasmF32, 1, [''])
|
|
|
|
.addBody([
|
|
|
|
// Set global 0 to param 0.
|
|
|
|
kExprLocalGet, 0, kExprGlobalSet, 0,
|
|
|
|
// Set local 1 to 47.
|
|
|
|
kExprI32Const, 47, kExprLocalSet, 1,
|
|
|
|
]);
|
2017-07-02 19:18:57 +00:00
|
|
|
|
2020-06-03 11:55:31 +00:00
|
|
|
// Append function to table to test function table output.
|
|
|
|
builder.appendToTable([main.index]);
|
|
|
|
|
2021-01-05 06:07:29 +00:00
|
|
|
var module_bytes = builder.toArray();
|
2020-01-09 12:11:55 +00:00
|
|
|
breakpointLocation = func.body_offset;
|
2017-07-02 19:18:57 +00:00
|
|
|
|
2021-01-05 06:07:29 +00:00
|
|
|
|
2020-06-16 05:11:11 +00:00
|
|
|
function addWasmJSToTable() {
|
2020-06-03 11:55:31 +00:00
|
|
|
// Create WasmJS functions to test the function tables output.
|
|
|
|
const js_func = function js_func() { return 7; };
|
2021-01-05 06:07:29 +00:00
|
|
|
const wasmjs_func = new WebAssembly.Function({parameters:[], results:['i32']}, js_func);
|
|
|
|
const wasmjs_anonymous_func = new WebAssembly.Function({parameters:[], results:['i32']}, _ => 7);
|
2020-06-03 11:55:31 +00:00
|
|
|
|
|
|
|
instance.exports.exported_table.set(0, wasmjs_func);
|
|
|
|
instance.exports.exported_table.set(1, wasmjs_anonymous_func);
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InspectorTest.log('Calling instantiate function.');
|
2021-01-05 06:07:29 +00:00
|
|
|
await WasmInspectorTest.instantiate(module_bytes);
|
|
|
|
await WasmInspectorTest.evalWithUrl(`(${addWasmJSToTable})()`, 'populateTable');
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 08:39:01 +00:00
|
|
|
function printIfFailure(message) {
|
2017-07-02 19:18:57 +00:00
|
|
|
if (!message.result) {
|
|
|
|
InspectorTest.logMessage(message);
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2019-10-24 09:35:06 +00:00
|
|
|
async function waitForWasmScripts() {
|
2020-01-09 12:11:55 +00:00
|
|
|
InspectorTest.log('Waiting for wasm script to be parsed.');
|
2019-10-24 09:35:06 +00:00
|
|
|
let wasm_script_ids = [];
|
2020-01-09 12:11:55 +00:00
|
|
|
while (wasm_script_ids.length < 1) {
|
2017-07-02 19:18:57 +00:00
|
|
|
let script_msg = await Protocol.Debugger.onceScriptParsed();
|
|
|
|
let url = script_msg.params.url;
|
2020-01-09 12:11:55 +00:00
|
|
|
if (url.startsWith('wasm://')) {
|
2019-10-24 09:35:06 +00:00
|
|
|
InspectorTest.log('Got wasm script!');
|
|
|
|
wasm_script_ids.push(script_msg.params.scriptId);
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-24 09:35:06 +00:00
|
|
|
return wasm_script_ids;
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|