Commit e83a4611 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Clean up wasm-scope-info test

This brings the test back in sync with the wasm-scope-info-liftoff test
after the comments on https://crrev.com/c/1975754.

R=jkummerow@chromium.org

Bug: v8:10021
Change-Id: I8e3751fdb11fb32a0112c0706559a6d26e2e7594
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1977860Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65723}
parent 69b195c9
Test retrieving scope information when pausing in wasm functions
Installing code and global variable.
Calling instantiate function.
Waiting for wasm script to be parsed.
Got wasm script!
......@@ -17,7 +16,7 @@ at func (0:69):
globals: "global#0": 0 (number)
- scope (local):
locals: "i32Arg": 4 (number), "local#1": 0 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number)
stack:
stack:
at call_func (0:58):
- scope (global):
globals: "global#0": 0 (number)
......@@ -51,7 +50,7 @@ at func (0:73):
globals: "global#0": 0 (number)
- scope (local):
locals: "i32Arg": 11 (number), "local#1": 0 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number)
stack:
stack:
at call_func (0:58):
- scope (global):
globals: "global#0": 0 (number)
......@@ -85,7 +84,7 @@ at func (0:77):
globals: "global#0": 0 (number)
- scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number)
stack:
stack:
at call_func (0:58):
- scope (global):
globals: "global#0": 0 (number)
......@@ -119,7 +118,7 @@ at func (0:90):
globals: "global#0": 0 (number)
- scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": 9223372036854775807 (string), "unicode☼f64": 0 (number)
stack:
stack:
at call_func (0:58):
- scope (global):
globals: "global#0": 0 (number)
......@@ -153,7 +152,7 @@ at func (0:103):
globals: "global#0": 0 (number)
- scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0 (number)
stack:
stack:
at call_func (0:58):
- scope (global):
globals: "global#0": 0 (number)
......@@ -255,7 +254,7 @@ at func (0:112):
globals: "global#0": 0 (number)
- scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0.14285714285714285 (number)
stack:
stack:
at call_func (0:58):
- scope (global):
globals: "global#0": 0 (number)
......@@ -289,7 +288,7 @@ at func (0:116):
globals: "global#0": 15 (number)
- scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0.14285714285714285 (number)
stack:
stack:
at call_func (0:58):
- scope (global):
globals: "global#0": 15 (number)
......
......@@ -10,35 +10,68 @@ let {session, contextGroup, Protocol} = InspectorTest.start(
'Test retrieving scope information when pausing in wasm functions');
session.setupScriptMap();
Protocol.Debugger.enable();
Protocol.Debugger.onPaused(printPauseLocationsAndContinue);
let evaluate = code => Protocol.Runtime.evaluate({expression: code});
let breakpointLocation = -1;
let breakpointLocation = undefined; // Will be set by {instantiateWasm}.
(async function test() {
let scriptIds = await instantiateWasm();
await setBreakpoint(scriptIds);
printPauseLocationsAndContinue();
// 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.
await evaluate('instance.exports.main(4)');
InspectorTest.log('exports.main returned. Test finished.');
InspectorTest.completeTest();
})();
async function printPauseLocationsAndContinue() {
while (true) {
let msg = await Protocol.Debugger.oncePaused();
let loc = msg.params.callFrames[0].location;
InspectorTest.log('Paused:');
await session.logSourceLocation(loc);
await dumpScopeChainsOnPause(msg);
Protocol.Debugger.stepOver();
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);
}
}
InspectorTest.log();
Protocol.Debugger.stepOver();
}
async function instantiateWasm() {
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
// Also add a global, so we have some global scope.
builder.addGlobal(kWasmI32, true);
// Add a function without breakpoint, to check that locals are shown
......@@ -74,7 +107,7 @@ async function instantiateWasm() {
kExprI32Const, 15, kExprGlobalSet, 0,
]);
var module_bytes = builder.toArray();
let moduleBytes = builder.toArray();
breakpointLocation = func.body_offset;
function instantiate(bytes) {
......@@ -85,27 +118,14 @@ async function instantiateWasm() {
}
var module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
return new WebAssembly.Instance(module);
}
InspectorTest.log('Installing code and global variable.');
await evaluate('var instance;\n' + instantiate.toString());
InspectorTest.log('Calling instantiate function.');
evaluate('instantiate(' + JSON.stringify(module_bytes) + ')');
return waitForWasmScripts();
}
async function setBreakpoint(scriptIds) {
InspectorTest.log(
'Setting breakpoint on first instruction of second function');
let breakpoint = await Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': scriptIds[0], 'lineNumber': 0, 'columnNumber': breakpointLocation}});
printFailure(breakpoint);
InspectorTest.logMessage(breakpoint.result.actualLocation);
evaluate(`var instance = (${instantiate})(${JSON.stringify(moduleBytes)})`);
}
function printFailure(message) {
function printIfFailure(message) {
if (!message.result) {
InspectorTest.logMessage(message);
}
......@@ -134,39 +154,16 @@ async function getScopeValues(value) {
}
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printFailure(msg);
printIfFailure(msg);
let printProperty = elem => '"' + elem.name + '"' +
': ' + elem.value.value + ' (' + elem.value.type + ')';
return msg.result.result.map(printProperty).join(', ');
}
async function dumpScopeProperties(message) {
printFailure(message);
printIfFailure(message);
for (var value of message.result.result) {
var value_str = await getScopeValues(value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
async function dumpScopeChainsOnPause(message) {
InspectorTest.log(`Scope:`);
for (var frame of message.params.callFrames) {
var isWasmFrame = /^wasm/.test(frame.url);
var functionName = frame.functionName || '(anonymous)';
var lineNumber = frame.location ? frame.location.lineNumber : frame.lineNumber;
var columnNumber = frame.location ? frame.location.columnNumber : frame.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);
}
}
InspectorTest.log();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment