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 Test retrieving scope information when pausing in wasm functions
Installing code and global variable.
Calling instantiate function. Calling instantiate function.
Waiting for wasm script to be parsed. Waiting for wasm script to be parsed.
Got wasm script! Got wasm script!
...@@ -17,7 +16,7 @@ at func (0:69): ...@@ -17,7 +16,7 @@ at func (0:69):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "i32Arg": 4 (number), "local#1": 0 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number) locals: "i32Arg": 4 (number), "local#1": 0 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number)
stack: stack:
at call_func (0:58): at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
...@@ -51,7 +50,7 @@ at func (0:73): ...@@ -51,7 +50,7 @@ at func (0:73):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "i32Arg": 11 (number), "local#1": 0 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number) locals: "i32Arg": 11 (number), "local#1": 0 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number)
stack: stack:
at call_func (0:58): at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
...@@ -85,7 +84,7 @@ at func (0:77): ...@@ -85,7 +84,7 @@ at func (0:77):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number) locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": 0 (number), "unicode☼f64": 0 (number)
stack: stack:
at call_func (0:58): at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
...@@ -119,7 +118,7 @@ at func (0:90): ...@@ -119,7 +118,7 @@ at func (0:90):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": 9223372036854775807 (string), "unicode☼f64": 0 (number) locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": 9223372036854775807 (string), "unicode☼f64": 0 (number)
stack: stack:
at call_func (0:58): at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
...@@ -153,7 +152,7 @@ at func (0:103): ...@@ -153,7 +152,7 @@ at func (0:103):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0 (number) locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0 (number)
stack: stack:
at call_func (0:58): at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
...@@ -255,7 +254,7 @@ at func (0:112): ...@@ -255,7 +254,7 @@ at func (0:112):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0.14285714285714285 (number) locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0.14285714285714285 (number)
stack: stack:
at call_func (0:58): at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
...@@ -289,7 +288,7 @@ at func (0:116): ...@@ -289,7 +288,7 @@ at func (0:116):
globals: "global#0": 15 (number) globals: "global#0": 15 (number)
- scope (local): - scope (local):
locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0.14285714285714285 (number) locals: "i32Arg": 11 (number), "local#1": 47 (number), "i64_local": -9223372036854775808 (string), "unicode☼f64": 0.14285714285714285 (number)
stack: stack:
at call_func (0:58): at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 15 (number) globals: "global#0": 15 (number)
......
...@@ -10,35 +10,68 @@ let {session, contextGroup, Protocol} = InspectorTest.start( ...@@ -10,35 +10,68 @@ let {session, contextGroup, Protocol} = InspectorTest.start(
'Test retrieving scope information when pausing in wasm functions'); 'Test retrieving scope information when pausing in wasm functions');
session.setupScriptMap(); session.setupScriptMap();
Protocol.Debugger.enable(); Protocol.Debugger.enable();
Protocol.Debugger.onPaused(printPauseLocationsAndContinue);
let evaluate = code => Protocol.Runtime.evaluate({expression: code}); let evaluate = code => Protocol.Runtime.evaluate({expression: code});
let breakpointLocation = -1; let breakpointLocation = undefined; // Will be set by {instantiateWasm}.
(async function test() { (async function test() {
let scriptIds = await instantiateWasm(); // Instantiate wasm and wait for three wasm scripts for the three functions.
await setBreakpoint(scriptIds); instantiateWasm();
printPauseLocationsAndContinue(); 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)'); await evaluate('instance.exports.main(4)');
InspectorTest.log('exports.main returned. Test finished.'); InspectorTest.log('exports.main returned. Test finished.');
InspectorTest.completeTest(); InspectorTest.completeTest();
})(); })();
async function printPauseLocationsAndContinue() { async function printPauseLocationsAndContinue(msg) {
while (true) { let loc = msg.params.callFrames[0].location;
let msg = await Protocol.Debugger.oncePaused(); InspectorTest.log('Paused:');
let loc = msg.params.callFrames[0].location; await session.logSourceLocation(loc);
InspectorTest.log('Paused:'); InspectorTest.log('Scope:');
await session.logSourceLocation(loc); for (var frame of msg.params.callFrames) {
await dumpScopeChainsOnPause(msg); var isWasmFrame = /^wasm/.test(frame.url);
Protocol.Debugger.stepOver(); 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() { async function instantiateWasm() {
utils.load('test/mjsunit/wasm/wasm-module-builder.js'); utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
// Also add a global, so we have some global scope.
builder.addGlobal(kWasmI32, true); builder.addGlobal(kWasmI32, true);
// Add a function without breakpoint, to check that locals are shown // Add a function without breakpoint, to check that locals are shown
...@@ -74,7 +107,7 @@ async function instantiateWasm() { ...@@ -74,7 +107,7 @@ async function instantiateWasm() {
kExprI32Const, 15, kExprGlobalSet, 0, kExprI32Const, 15, kExprGlobalSet, 0,
]); ]);
var module_bytes = builder.toArray(); let moduleBytes = builder.toArray();
breakpointLocation = func.body_offset; breakpointLocation = func.body_offset;
function instantiate(bytes) { function instantiate(bytes) {
...@@ -85,27 +118,14 @@ async function instantiateWasm() { ...@@ -85,27 +118,14 @@ async function instantiateWasm() {
} }
var module = new WebAssembly.Module(buffer); var module = new WebAssembly.Module(buffer);
// Set global variable. return new WebAssembly.Instance(module);
instance = new WebAssembly.Instance(module);
} }
InspectorTest.log('Installing code and global variable.');
await evaluate('var instance;\n' + instantiate.toString());
InspectorTest.log('Calling instantiate function.'); InspectorTest.log('Calling instantiate function.');
evaluate('instantiate(' + JSON.stringify(module_bytes) + ')'); evaluate(`var instance = (${instantiate})(${JSON.stringify(moduleBytes)})`);
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);
} }
function printFailure(message) { function printIfFailure(message) {
if (!message.result) { if (!message.result) {
InspectorTest.logMessage(message); InspectorTest.logMessage(message);
} }
...@@ -134,39 +154,16 @@ async function getScopeValues(value) { ...@@ -134,39 +154,16 @@ async function getScopeValues(value) {
} }
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId}); let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printFailure(msg); printIfFailure(msg);
let printProperty = elem => '"' + elem.name + '"' + let printProperty = elem => '"' + elem.name + '"' +
': ' + elem.value.value + ' (' + elem.value.type + ')'; ': ' + elem.value.value + ' (' + elem.value.type + ')';
return msg.result.result.map(printProperty).join(', '); return msg.result.result.map(printProperty).join(', ');
} }
async function dumpScopeProperties(message) { async function dumpScopeProperties(message) {
printFailure(message); printIfFailure(message);
for (var value of message.result.result) { for (var value of message.result.result) {
var value_str = await getScopeValues(value.value); var value_str = await getScopeValues(value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str); 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