v8/test/inspector/debugger/wasm-memory-names.js
Benedikt Meurer a23adbbc5a [inspector][wasm] Improve Scope view and instance preview.
This adds the following internal properties to `WasmInstanceObject`
values in DevTools:

 - `[[Module]]` pointing to the `WasmModuleObject`, allowing the
   developer to find the module to an instance no matter where in
   DevTools front-end the instance is inspected.
 - `[[Functions]]`, `[[Globals]]`, `[[Memories]]`, and `[[Tables]]`
   are shown (when they aren't empty), allowing developers to inspect
   the entities within an instance no matter where in DevTools front-end
   it's inspected.

This also updates the _Module_ scope for Wasm frames to show the entity
containers (`functions`, `globals`, `memories` and `tables`) in addition
to the `instance` and `module` to make it easier accessible (fewer
clicks to get there), but also to align it better with the _Add property
path to Watch_ and _Copy property path_ features (since exactly the same
names are exposed via Debug Evaluate on Wasm frames).

```
> Stack
> Locals
v Module
  > module
  > instance
  > functions
  > globals
  > memories
  > tables
```

Drive-by-fix: Move GetWasmModuleObjectInternalProperties() logic into
debug-wasm-support.cc

Screenshot: https://imgur.com/ksEHG2I.png
Doc: http://bit.ly/devtools-wasm-entities
Fixed: chromium:1165294
Bug: chromium:1071432, chromium:1164241, chromium:1165304
Change-Id: Ia88fb2705287c79988ff2b432e4a33ac34e098f5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2622912
Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72042}
2021-01-12 15:13:49 +00:00

104 lines
3.1 KiB
JavaScript

// 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.
utils.load('test/inspector/wasm-inspector-test.js');
let {session, contextGroup, Protocol} =
InspectorTest.start('Test wasm memory names');
let func;
// No name memory.
function createModuleBytesUnnamedMemory() {
let builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
func = builder.addFunction('main', kSig_i_i)
.addBody([kExprI32Const, 0, kExprI32LoadMem, 0, 0])
.exportAs('main');
return JSON.stringify(builder.toArray());
}
// Exported memory.
function createModuleBytesExportedMemory() {
let builder = new WasmModuleBuilder();
var memory = builder.addMemory(1, 1);
builder.addExportOfKind('exported_memory', kExternalMemory);
func = builder.addFunction('main', kSig_i_i)
.addBody([kExprI32Const, 0, kExprI32LoadMem, 0, 0])
.exportAs('main');
return JSON.stringify(builder.toArray());
}
// Imported memory.
function createModuleBytesImportedMemory() {
let builder = new WasmModuleBuilder();
builder.addImportedMemory('module_name', 'imported_mem', 0, 1);
func = builder.addFunction('main', kSig_i_i)
.addBody([kExprI32Const, 0, kExprI32LoadMem, 0, 0])
.exportAs('main');
return JSON.stringify(builder.toArray());
}
function createInstance(moduleBytes) {
let module = new WebAssembly.Module((new Uint8Array(moduleBytes)).buffer);
let memory = new WebAssembly.Memory({initial: 1, maximum: 1});
instance =
new WebAssembly.Instance(module, {module_name: {imported_mem: memory}});
}
async function check(moduleBytes) {
Protocol.Runtime.evaluate({
expression: `
createInstance(${moduleBytes});`
});
InspectorTest.log('Waiting for wasm script to be parsed.');
let scriptId;
while (true) {
let msg = await Protocol.Debugger.onceScriptParsed();
if (msg.params.url.startsWith('wasm://')) {
scriptId = msg.params.scriptId;
break;
}
}
InspectorTest.log('Setting breakpoint in wasm.');
await Protocol.Debugger.setBreakpoint(
{location: {scriptId, lineNumber: 0, columnNumber: func.body_offset}});
InspectorTest.log('Running main.');
Protocol.Runtime.evaluate({expression: 'instance.exports.main()'});
const {params: {callFrames: [{callFrameId}]}} =
await Protocol.Debugger.oncePaused();
InspectorTest.log('Paused in debugger.');
const {result: {result: {objectId}}} =
await Protocol.Debugger.evaluateOnCallFrame(
{callFrameId, expression: `memories`});
const {result: {result: properties}} =
await Protocol.Runtime.getProperties({objectId});
for (const {name} of properties) {
InspectorTest.log(`name: ${name}`);
}
await Protocol.Debugger.resume();
InspectorTest.log('Finished.');
}
contextGroup.addScript(`
let instance;
${createInstance.toString()}`);
InspectorTest.runAsyncTestSuite([
async function test() {
Protocol.Debugger.enable();
await check(createModuleBytesUnnamedMemory());
await check(createModuleBytesExportedMemory());
await check(createModuleBytesImportedMemory());
}
]);