2017-07-02 19:18:57 +00:00
|
|
|
// Copyright 2017 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-01-10 11:22:33 +00:00
|
|
|
// Disable Liftoff to get deterministic (non-existing) scope information for
|
|
|
|
// compiled frames.
|
|
|
|
// Flags: --no-liftoff
|
|
|
|
|
2017-07-02 19:18:57 +00:00
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start(
|
|
|
|
'Test retrieving scope information when pausing in wasm functions');
|
|
|
|
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
|
|
|
|
|
|
|
let evaluate = code => Protocol.Runtime.evaluate({expression: code});
|
|
|
|
|
2020-01-13 08:39:01 +00:00
|
|
|
let breakpointLocation = undefined; // Will be set by {instantiateWasm}.
|
2020-01-09 12:11:55 +00:00
|
|
|
|
2017-07-02 19:18:57 +00:00
|
|
|
(async function test() {
|
2020-01-13 08:39:01 +00:00
|
|
|
// Instantiate wasm and wait for three wasm scripts for the three functions.
|
|
|
|
instantiateWasm();
|
|
|
|
let scriptIds = await waitForWasmScripts();
|
|
|
|
|
|
|
|
// Set a breakpoint.
|
|
|
|
InspectorTest.log(
|
|
|
|
'Setting breakpoint on first instruction of second function');
|
|
|
|
let breakpoint = await Protocol.Debugger.setBreakpoint({
|
|
|
|
'location' : {
|
|
|
|
'scriptId' : scriptIds[0],
|
|
|
|
'lineNumber' : 0,
|
|
|
|
'columnNumber' : breakpointLocation
|
|
|
|
}
|
|
|
|
});
|
|
|
|
printIfFailure(breakpoint);
|
|
|
|
InspectorTest.logMessage(breakpoint.result.actualLocation);
|
|
|
|
|
|
|
|
// Now run the wasm code.
|
2017-07-02 19:18:57 +00:00
|
|
|
await evaluate('instance.exports.main(4)');
|
|
|
|
InspectorTest.log('exports.main returned. Test finished.');
|
|
|
|
InspectorTest.completeTest();
|
|
|
|
})();
|
|
|
|
|
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});
|
|
|
|
await dumpScopeProperties(properties);
|
|
|
|
}
|
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() {
|
|
|
|
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
|
|
|
|
var builder = new WasmModuleBuilder();
|
2020-01-13 08:39:01 +00:00
|
|
|
// Also add a global, so we have some global scope.
|
2019-05-10 00:52:56 +00:00
|
|
|
builder.addGlobal(kWasmI32, true);
|
2017-07-02 19:18:57 +00:00
|
|
|
|
2019-10-24 09:35:06 +00:00
|
|
|
// Add a function without breakpoint, to check that locals are shown
|
|
|
|
// correctly in compiled code.
|
|
|
|
builder.addFunction('call_func', kSig_v_i).addLocals({f32_count: 1}).addBody([
|
|
|
|
// Set local 1 to 7.2.
|
|
|
|
...wasmF32Const(7.2), kExprLocalSet, 1,
|
|
|
|
// Call function 'func', forwarding param 0.
|
|
|
|
kExprLocalGet, 0, kExprCallFunction, 1
|
|
|
|
]).exportAs('main');
|
|
|
|
|
|
|
|
// A second function which will be stepped through.
|
2020-01-09 12:11:55 +00:00
|
|
|
let func = builder.addFunction('func', kSig_v_i)
|
2017-07-02 19:18:57 +00:00
|
|
|
.addLocals(
|
2020-01-14 11:44:18 +00:00
|
|
|
{i32_count: 1, i64_count: 1, f64_count: 3},
|
|
|
|
['i32Arg', undefined, 'i64_local', 'unicode☼f64', '0', '0'])
|
2017-07-02 19:18:57 +00:00
|
|
|
.addBody([
|
|
|
|
// Set param 0 to 11.
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprI32Const, 11, kExprLocalSet, 0,
|
2017-07-02 19:18:57 +00:00
|
|
|
// Set local 1 to 47.
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprI32Const, 47, kExprLocalSet, 1,
|
2019-01-10 13:35:42 +00:00
|
|
|
// Set local 2 to 0x7FFFFFFFFFFFFFFF (max i64).
|
|
|
|
kExprI64Const, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalSet, 2,
|
2019-01-10 13:35:42 +00:00
|
|
|
// Set local 2 to 0x8000000000000000 (min i64).
|
|
|
|
kExprI64Const, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f,
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalSet, 2,
|
2019-01-10 13:35:42 +00:00
|
|
|
// Set local 3 to 1/7.
|
2017-07-02 19:18:57 +00:00
|
|
|
kExprI32Const, 1, kExprF64UConvertI32, kExprI32Const, 7,
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprF64UConvertI32, kExprF64Div, kExprLocalSet, 3,
|
2019-05-10 00:52:56 +00:00
|
|
|
|
|
|
|
// Set global 0 to 15
|
2019-10-08 13:16:30 +00:00
|
|
|
kExprI32Const, 15, kExprGlobalSet, 0,
|
2019-10-24 09:35:06 +00:00
|
|
|
]);
|
2017-07-02 19:18:57 +00:00
|
|
|
|
2020-01-13 08:39:01 +00:00
|
|
|
let moduleBytes = builder.toArray();
|
2020-01-09 12:11:55 +00:00
|
|
|
breakpointLocation = func.body_offset;
|
2017-07-02 19:18:57 +00:00
|
|
|
|
|
|
|
function instantiate(bytes) {
|
|
|
|
var buffer = new ArrayBuffer(bytes.length);
|
|
|
|
var view = new Uint8Array(buffer);
|
|
|
|
for (var i = 0; i < bytes.length; ++i) {
|
|
|
|
view[i] = bytes[i] | 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var module = new WebAssembly.Module(buffer);
|
2020-01-13 08:39:01 +00:00
|
|
|
return new WebAssembly.Instance(module);
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InspectorTest.log('Calling instantiate function.');
|
2020-01-13 08:39:01 +00:00
|
|
|
evaluate(`var instance = (${instantiate})(${JSON.stringify(moduleBytes)})`);
|
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
|
|
|
}
|
|
|
|
|
2019-01-10 13:35:42 +00:00
|
|
|
async function getScopeValues(value) {
|
|
|
|
if (value.type != 'object') {
|
|
|
|
InspectorTest.log('Expected object. Found:');
|
|
|
|
InspectorTest.logObject(value);
|
|
|
|
return;
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
2019-01-10 13:35:42 +00:00
|
|
|
|
|
|
|
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
|
2020-01-13 08:39:01 +00:00
|
|
|
printIfFailure(msg);
|
2019-01-10 13:35:42 +00:00
|
|
|
let printProperty = elem => '"' + elem.name + '"' +
|
|
|
|
': ' + elem.value.value + ' (' + elem.value.type + ')';
|
|
|
|
return msg.result.result.map(printProperty).join(', ');
|
2017-07-02 19:18:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 13:35:42 +00:00
|
|
|
async function dumpScopeProperties(message) {
|
2020-01-13 08:39:01 +00:00
|
|
|
printIfFailure(message);
|
2017-07-02 19:18:57 +00:00
|
|
|
for (var value of message.result.result) {
|
2019-01-10 13:35:42 +00:00
|
|
|
var value_str = await getScopeValues(value.value);
|
2017-07-02 19:18:57 +00:00
|
|
|
InspectorTest.log(' ' + value.name + ': ' + value_str);
|
|
|
|
}
|
|
|
|
}
|