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.
|
|
|
|
|
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.');
|
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
|
|
|
|
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.
|
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
|
|
|
|
kExprLoop, kWasmStmt, // while
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalGet, 0, // -
|
2018-04-19 12:18:48 +00:00
|
|
|
kExprIf, kWasmStmt, // if <param0> != 0
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalGet, 0, // -
|
2018-04-19 12:18:48 +00:00
|
|
|
kExprI32Const, 1, // -
|
|
|
|
kExprI32Sub, // -
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalSet, 0, // decrease <param0>
|
2018-04-19 12:18:48 +00:00
|
|
|
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
|
|
|
|
2018-10-08 11:33:09 +00:00
|
|
|
const getResult = msg => msg.result || InspectorTest.logMessage(msg);
|
2018-04-19 12:18:48 +00:00
|
|
|
|
2020-01-09 12:11:55 +00:00
|
|
|
function setBreakpoint(offset, script) {
|
2018-10-08 11:33:09 +00:00
|
|
|
InspectorTest.log(
|
2020-01-09 12:11:55 +00:00
|
|
|
'Setting breakpoint at offset ' + offset + ' on script ' + script.url);
|
2018-10-08 11:33:09 +00:00
|
|
|
return Protocol.Debugger
|
|
|
|
.setBreakpoint(
|
2020-01-09 12:11:55 +00:00
|
|
|
{'location': {'scriptId': script.scriptId, 'lineNumber': 0, 'columnNumber': offset}})
|
2018-10-08 11:33:09 +00:00
|
|
|
.then(getResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
Protocol.Debugger.onPaused(pause_msg => {
|
|
|
|
let loc = pause_msg.params.callFrames[0].location;
|
2020-01-09 12:11:55 +00:00
|
|
|
if (loc.lineNumber != 0) {
|
|
|
|
InspectorTest.log('Unexpected line number: ' + loc.lineNumber);
|
|
|
|
}
|
|
|
|
InspectorTest.log('Breaking on byte offset ' + loc.columnNumber);
|
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:
|
2020-06-16 05:11:11 +00:00
|
|
|
WasmInspectorTest.instantiate(module_bytes);
|
2018-10-08 11:33:09 +00:00
|
|
|
InspectorTest.log(
|
2020-01-09 12:11:55 +00:00
|
|
|
'Waiting for wasm script (ignoring first non-wasm script).');
|
2019-11-06 15:51:44 +00:00
|
|
|
// Ignore javascript and full module wasm script, get scripts for functions.
|
2020-01-09 12:11:55 +00:00
|
|
|
const [, {params: wasm_script}] = await Protocol.Debugger.onceScriptParsed(2);
|
|
|
|
for (offset of [11, 10, 8, 6, 2, 4]) {
|
|
|
|
await setBreakpoint(func_b.body_offset + offset, wasm_script);
|
2018-04-19 12:18:48 +00:00
|
|
|
}
|
2018-10-08 11:33:09 +00:00
|
|
|
InspectorTest.log('Calling main(4)');
|
2020-06-16 05:11:11 +00:00
|
|
|
await WasmInspectorTest.evalWithUrl('instance.exports.main(4)', 'runWasm');
|
2018-10-08 11:33:09 +00:00
|
|
|
InspectorTest.log('exports.main returned!');
|
|
|
|
InspectorTest.log('Finished!');
|
|
|
|
InspectorTest.completeTest();
|
|
|
|
})();
|