2021-01-05 06:07:29 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
2018-04-19 12:18:48 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-06-16 05:11:11 +00:00
|
|
|
utils.load('test/inspector/wasm-inspector-test.js');
|
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const {session, contextGroup, Protocol} =
|
|
|
|
InspectorTest.start('Tests stepping through wasm scripts.');
|
2021-01-05 06:07:29 +00:00
|
|
|
session.setupScriptMap();
|
2018-04-19 12:18:48 +00:00
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const builder = new WasmModuleBuilder();
|
2018-04-19 12:18:48 +00:00
|
|
|
|
2021-01-05 06:07:29 +00:00
|
|
|
const func_a =
|
|
|
|
builder.addFunction('wasm_A', kSig_v_v).addBody([kExprNop, kExprNop]);
|
2018-04-19 12:18:48 +00:00
|
|
|
|
|
|
|
// wasm_B calls wasm_A <param0> times.
|
2020-01-09 12:11:55 +00:00
|
|
|
const func_b = builder.addFunction('wasm_B', kSig_v_i)
|
2018-04-19 12:18:48 +00:00
|
|
|
.addBody([
|
|
|
|
// clang-format off
|
2021-03-22 06:56:01 +00:00
|
|
|
kExprLoop, kWasmVoid, // while
|
2021-01-05 06:07:29 +00:00
|
|
|
kExprLocalGet, 0, // -
|
2021-03-22 06:56:01 +00:00
|
|
|
kExprIf, kWasmVoid, // if <param0> != 0
|
2021-01-05 06:07:29 +00:00
|
|
|
kExprLocalGet, 0, // -
|
|
|
|
kExprI32Const, 1, // -
|
|
|
|
kExprI32Sub, // -
|
|
|
|
kExprLocalSet, 0, // decrease <param0>
|
|
|
|
kExprCallFunction, func_a.index, // -
|
|
|
|
kExprBr, 1, // continue
|
|
|
|
kExprEnd, // -
|
|
|
|
kExprEnd, // break
|
2018-04-19 12:18:48 +00:00
|
|
|
// clang-format on
|
|
|
|
])
|
|
|
|
.exportAs('main');
|
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const module_bytes = builder.toArray();
|
2018-04-19 12:18:48 +00:00
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const getResult = msg => msg.result || InspectorTest.logMessage(msg);
|
2018-04-19 12:18:48 +00:00
|
|
|
|
2021-01-05 06:07:29 +00:00
|
|
|
function setBreakpoint(offset, scriptId, scriptUrl) {
|
2018-10-08 11:33:09 +00:00
|
|
|
InspectorTest.log(
|
2021-01-05 06:07:29 +00:00
|
|
|
'Setting breakpoint at offset ' + offset + ' on script ' + scriptUrl);
|
2018-10-08 11:33:09 +00:00
|
|
|
return Protocol.Debugger
|
|
|
|
.setBreakpoint(
|
2021-01-05 06:07:29 +00:00
|
|
|
{'location': {'scriptId': scriptId, 'lineNumber': 0, 'columnNumber': offset}})
|
2018-10-08 11:33:09 +00:00
|
|
|
.then(getResult);
|
|
|
|
}
|
|
|
|
|
2021-01-05 06:07:29 +00:00
|
|
|
// Only set breakpoints during the first loop iteration.
|
|
|
|
var first_iteration = true;
|
|
|
|
|
|
|
|
Protocol.Debugger.onPaused(async 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 functionName = frame.functionName || '(anonymous)';
|
|
|
|
var lineNumber = frame.location.lineNumber;
|
|
|
|
var columnNumber = frame.location.columnNumber;
|
|
|
|
InspectorTest.log(`at ${functionName} (${lineNumber}:${columnNumber}):`);
|
|
|
|
if (!/^wasm/.test(frame.url)) {
|
|
|
|
InspectorTest.log(' -- skipped');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (var scope of frame.scopeChain) {
|
|
|
|
InspectorTest.logObject(' - scope (' + scope.type + '):');
|
|
|
|
var properties = await Protocol.Runtime.getProperties(
|
|
|
|
{'objectId': scope.object.objectId});
|
|
|
|
await WasmInspectorTest.dumpScopeProperties(properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first_iteration && loc.columnNumber == func_a.body_offset) {
|
|
|
|
// Check that setting breakpoints on active instances of A and B takes
|
|
|
|
// effect immediately.
|
|
|
|
setBreakpoint(func_a.body_offset + 1, loc.scriptId, frame.url);
|
|
|
|
// All of the following breakpoints are in reachable code, except offset 17.
|
|
|
|
for (offset of [18, 17, 11, 10, 8, 6, 2, 4]) {
|
|
|
|
setBreakpoint(func_b.body_offset + offset, loc.scriptId, frame.url);
|
|
|
|
}
|
|
|
|
first_iteration = false;
|
2020-01-09 12:11:55 +00:00
|
|
|
}
|
2021-01-05 06:07:29 +00:00
|
|
|
|
2018-04-19 12:18:48 +00:00
|
|
|
Protocol.Debugger.resume();
|
|
|
|
});
|
|
|
|
|
2021-01-05 05:51:52 +00:00
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
|
|
async function test() {
|
2021-04-09 08:58:46 +00:00
|
|
|
await Protocol.Runtime.enable();
|
2021-01-05 05:51:52 +00:00
|
|
|
await Protocol.Debugger.enable();
|
|
|
|
InspectorTest.log('Instantiating.');
|
|
|
|
// Spawn asynchronously:
|
|
|
|
WasmInspectorTest.instantiate(module_bytes);
|
|
|
|
InspectorTest.log(
|
|
|
|
'Waiting for wasm script (ignoring first non-wasm script).');
|
|
|
|
// Ignore javascript and full module wasm script, get scripts for functions.
|
|
|
|
const [, {params: wasm_script}] = await Protocol.Debugger.onceScriptParsed(2);
|
2021-01-05 06:07:29 +00:00
|
|
|
// Set a breakpoint in function A at offset 0. When the debugger hits this
|
|
|
|
// breakpoint, new ones will be added.
|
|
|
|
await setBreakpoint(func_a.body_offset, wasm_script.scriptId, wasm_script.url);
|
2021-01-05 05:51:52 +00:00
|
|
|
InspectorTest.log('Calling main(4)');
|
|
|
|
await WasmInspectorTest.evalWithUrl('instance.exports.main(4)', 'runWasm');
|
|
|
|
InspectorTest.log('exports.main returned!');
|
2018-04-19 12:18:48 +00:00
|
|
|
}
|
2021-01-05 05:51:52 +00:00
|
|
|
]);
|