2020-08-06 14:51:42 +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.
|
|
|
|
//
|
|
|
|
// Flags: --allow-natives-syntax
|
|
|
|
|
|
|
|
utils.load('test/inspector/wasm-inspector-test.js');
|
|
|
|
|
|
|
|
let {session, contextGroup, Protocol} =
|
|
|
|
InspectorTest.start('Tests pausing a running script and stepping');
|
|
|
|
|
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
|
|
|
|
let pause = builder.addImport('imports', 'pause', kSig_v_v);
|
|
|
|
let f = builder.addFunction('f', kSig_i_i)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0,
|
|
|
|
kExprI32Const, 1,
|
|
|
|
kExprI32Add]);
|
|
|
|
let main = builder.addFunction('main', kSig_i_v)
|
|
|
|
.addBody([
|
|
|
|
kExprCallFunction, pause,
|
|
|
|
kExprI32Const, 12, kExprCallFunction, f.index])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
var module_bytes = builder.toArray();
|
|
|
|
|
|
|
|
function instantiate(bytes, imports) {
|
|
|
|
var buffer = new ArrayBuffer(bytes.length);
|
|
|
|
var view = new Uint8Array(buffer);
|
|
|
|
for (var i = 0; i < bytes.length; ++i) {
|
|
|
|
view[i] = bytes[i] | 0;
|
|
|
|
}
|
|
|
|
const module = new WebAssembly.Module(buffer);
|
|
|
|
return new WebAssembly.Instance(module, imports);
|
|
|
|
}
|
|
|
|
|
2021-01-05 05:51:52 +00:00
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
|
|
async function testPauseAndStep() {
|
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('Instantiate');
|
|
|
|
const instantiate_code = `var instance = (${instantiate})(${JSON.stringify(module_bytes)}, {'imports': {'pause': () => { %ScheduleBreak() } }});`;
|
|
|
|
WasmInspectorTest.evalWithUrl(instantiate_code, 'instantiate');
|
|
|
|
InspectorTest.log('Wait for script');
|
|
|
|
const [, {params: wasmScript}] = await Protocol.Debugger.onceScriptParsed(2);
|
|
|
|
InspectorTest.log('Got wasm script: ' + wasmScript.url);
|
2020-08-06 14:51:42 +00:00
|
|
|
|
2021-01-05 05:51:52 +00:00
|
|
|
InspectorTest.log('Run');
|
|
|
|
Protocol.Runtime.evaluate({expression: 'instance.exports.main()'});
|
|
|
|
InspectorTest.log('Expecting to pause at ' + (f.body_offset - 1));
|
|
|
|
await waitForPauseAndStep('stepInto');
|
|
|
|
await waitForPauseAndStep('stepInto');
|
|
|
|
await waitForPauseAndStep('stepInto');
|
|
|
|
await waitForPauseAndStep('stepInto');
|
|
|
|
await waitForPauseAndStep('resume');
|
|
|
|
}
|
|
|
|
]);
|
2020-08-06 14:51:42 +00:00
|
|
|
|
|
|
|
async function waitForPauseAndStep(stepAction) {
|
|
|
|
const msg = await Protocol.Debugger.oncePaused();
|
|
|
|
await inspect(msg.params.callFrames[0]);
|
|
|
|
Protocol.Debugger[stepAction]();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function inspect(frame) {
|
|
|
|
let loc = frame.location;
|
|
|
|
let line = [`Paused at offset ${loc.columnNumber}`];
|
|
|
|
// Inspect only the top wasm frame.
|
|
|
|
for (var scope of frame.scopeChain) {
|
|
|
|
if (scope.type == 'module') continue;
|
2021-03-10 15:29:01 +00:00
|
|
|
var { objectId } = scope.object;
|
|
|
|
if (scope.type == 'wasm-expression-stack') {
|
|
|
|
objectId = (await Protocol.Runtime.callFunctionOn({
|
|
|
|
functionDeclaration: 'function() { return this.stack }',
|
|
|
|
objectId
|
|
|
|
})).result.result.objectId;
|
|
|
|
}
|
|
|
|
var properties =
|
|
|
|
await Protocol.Runtime.getProperties({objectId});
|
|
|
|
let str = (await Promise.all(properties.result.result.map(
|
2021-02-08 15:39:00 +00:00
|
|
|
elem => WasmInspectorTest.getWasmValue(elem.value))))
|
|
|
|
.join(', ');
|
2020-08-06 14:51:42 +00:00
|
|
|
line.push(`${scope.type}: [${str}]`);
|
|
|
|
}
|
|
|
|
InspectorTest.log(line.join('; '));
|
|
|
|
}
|