2018-04-19 12:18:48 +00:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const {session, contextGroup, Protocol} =
|
|
|
|
InspectorTest.start('Tests stepping through wasm scripts.');
|
2018-04-19 12:18:48 +00:00
|
|
|
|
|
|
|
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const builder = new WasmModuleBuilder();
|
2018-04-19 12:18:48 +00:00
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const func_a_idx =
|
2018-04-19 12:18:48 +00:00
|
|
|
builder.addFunction('wasm_A', kSig_v_v).addBody([kExprNop, kExprNop]).index;
|
|
|
|
|
|
|
|
// wasm_B calls wasm_A <param0> times.
|
|
|
|
builder.addFunction('wasm_B', kSig_v_i)
|
|
|
|
.addBody([
|
|
|
|
// clang-format off
|
|
|
|
kExprLoop, kWasmStmt, // while
|
|
|
|
kExprGetLocal, 0, // -
|
|
|
|
kExprIf, kWasmStmt, // if <param0> != 0
|
|
|
|
kExprGetLocal, 0, // -
|
|
|
|
kExprI32Const, 1, // -
|
|
|
|
kExprI32Sub, // -
|
|
|
|
kExprSetLocal, 0, // decrease <param0>
|
|
|
|
kExprCallFunction, func_a_idx, // -
|
|
|
|
kExprBr, 1, // continue
|
|
|
|
kExprEnd, // -
|
|
|
|
kExprEnd, // break
|
|
|
|
// 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
|
|
|
|
|
|
|
function instantiate(bytes) {
|
2018-10-08 11:33:09 +00:00
|
|
|
let buffer = new ArrayBuffer(bytes.length);
|
|
|
|
let view = new Uint8Array(buffer);
|
|
|
|
for (let i = 0; i < bytes.length; ++i) {
|
2018-04-19 12:18:48 +00:00
|
|
|
view[i] = bytes[i] | 0;
|
|
|
|
}
|
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
let module = new WebAssembly.Module(buffer);
|
|
|
|
return new WebAssembly.Instance(module);
|
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
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const evalWithUrl = (code, url) =>
|
|
|
|
Protocol.Runtime
|
|
|
|
.evaluate({'expression': code + '\n//# sourceURL=v8://test/' + url})
|
|
|
|
.then(getResult);
|
2018-04-19 12:18:48 +00:00
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
function setBreakpoint(line, script) {
|
|
|
|
InspectorTest.log(
|
|
|
|
'Setting breakpoint on line ' + line + ' on script ' + script.url);
|
|
|
|
return Protocol.Debugger
|
|
|
|
.setBreakpoint(
|
|
|
|
{'location': {'scriptId': script.scriptId, 'lineNumber': line}})
|
|
|
|
.then(getResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
Protocol.Debugger.onPaused(pause_msg => {
|
|
|
|
let loc = pause_msg.params.callFrames[0].location;
|
|
|
|
InspectorTest.log('Breaking on line ' + loc.lineNumber);
|
2018-04-19 12:18:48 +00:00
|
|
|
Protocol.Debugger.resume();
|
|
|
|
});
|
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
(async function test() {
|
|
|
|
await Protocol.Debugger.enable();
|
|
|
|
InspectorTest.log('Instantiating.');
|
|
|
|
// Spawn asynchronously:
|
|
|
|
let instantiate_code = 'const instance = (' + instantiate + ')(' +
|
|
|
|
JSON.stringify(module_bytes) + ');';
|
|
|
|
evalWithUrl(instantiate_code, 'instantiate');
|
|
|
|
InspectorTest.log(
|
|
|
|
'Waiting for two wasm scripts (ignoring first non-wasm script).');
|
|
|
|
const [, {params: wasm_script_a}, {params: wasm_script_b}] =
|
|
|
|
await Protocol.Debugger.onceScriptParsed(3);
|
|
|
|
for (script of [wasm_script_a, wasm_script_b]) {
|
|
|
|
InspectorTest.log('Source of script ' + script.url + ':');
|
|
|
|
let src_msg =
|
|
|
|
await Protocol.Debugger.getScriptSource({scriptId: script.scriptId});
|
|
|
|
let lines = getResult(src_msg).scriptSource.replace(/\s+$/, '').split('\n');
|
|
|
|
InspectorTest.log(
|
|
|
|
lines.map((line, nr) => (nr + 1) + ': ' + line).join('\n') + '\n');
|
2018-04-19 12:18:48 +00:00
|
|
|
}
|
2018-10-08 11:33:09 +00:00
|
|
|
for (line of [8, 7, 6, 5, 3, 4]) {
|
|
|
|
await setBreakpoint(line, wasm_script_b);
|
2018-04-19 12:18:48 +00:00
|
|
|
}
|
2018-10-08 11:33:09 +00:00
|
|
|
InspectorTest.log('Calling main(4)');
|
|
|
|
await evalWithUrl('instance.exports.main(4)', 'runWasm');
|
|
|
|
InspectorTest.log('exports.main returned!');
|
|
|
|
InspectorTest.log('Finished!');
|
|
|
|
InspectorTest.completeTest();
|
|
|
|
})();
|