Commit c8e3cbbe authored by Kim-Anh Tran's avatar Kim-Anh Tran Committed by Commit Bot

[wasm][debugging] Add wasm instance to module scope

This adds the wasm instance to the module scope. The instance
contains the exported entities that can now be inspected.

Bug: chromium:1043034
Change-Id: I9236ac9c126f3bc4b1e056990fe34956bbe8ed6b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2213433
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67961}
parent 4c256166
......@@ -349,6 +349,12 @@ Handle<JSObject> GetModuleScopeObject(Handle<WasmInstanceObject> instance) {
Handle<JSObject> module_scope_object =
isolate->factory()->NewJSObjectWithNullProto();
Handle<String> instance_name =
isolate->factory()->InternalizeString(StaticCharVector("instance"));
JSObject::AddProperty(isolate, module_scope_object, instance_name, instance,
NONE);
if (instance->has_memory_object()) {
Handle<String> name;
// TODO(duongn): extend the logic when multiple memories are supported.
......
......@@ -62,6 +62,7 @@ async function logMemoryName(msg, Protocol) {
})).result.result;
for (let prop of moduleObjectProps) {
if (prop.name == 'instance') continue;
InspectorTest.log(`name: ${prop.name}`);
}
}
......
......@@ -62,8 +62,10 @@ 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 global, memory and exports to populate the module scope.
builder.addGlobal(kWasmI32, true).exportAs('exported_global');
builder.addMemory(1,1).exportMemoryAs('exported_memory');
builder.addTable(kWasmAnyFunc, 0).exportAs('exported_table');
// Add two functions without breakpoint, to check that locals and operand
// stack values are shown correctly in Liftoff code.
......@@ -144,8 +146,11 @@ async function waitForWasmScripts() {
return wasm_script_ids;
}
async function getScopeValues(value) {
async function getScopeValues(name, value) {
if (value.type == 'object') {
if (value.subtype == 'typedarray') return value.description;
if (name == 'instance') return dumpInstanceProperties(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printIfFailure(msg);
const printProperty = function(elem) {
......@@ -159,11 +164,34 @@ async function getScopeValues(value) {
async function dumpScopeProperties(message) {
printIfFailure(message);
for (var value of message.result.result) {
var value_str = await getScopeValues(value.value);
var value_str = await getScopeValues(value.name, value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
async function dumpInstanceProperties(instanceObj) {
function invokeGetter(property) {
return this[JSON.parse(property)];
}
const exportsName = 'exports';
let exportsObj = await Protocol.Runtime.callFunctionOn(
{objectId: instanceObj.objectId,
functionDeclaration: invokeGetter.toString(),
arguments: [{value: JSON.stringify(exportsName)}]
});
printIfFailure(exportsObj);
let exports = await Protocol.Runtime.getProperties(
{objectId: exportsObj.result.result.objectId});
printIfFailure(exports);
const printExports = function(value) {
return `"${value.name}" (${value.value.className})`;
}
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
function getWasmValue(wasmValue) {
return typeof (wasmValue.value) === 'undefined' ?
wasmValue.unserializableValue :
......
......@@ -67,8 +67,10 @@ 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 global, memory and exports to populate the module scope.
builder.addGlobal(kWasmI32, true).exportAs('exported_global');
builder.addMemory(1,1).exportMemoryAs('exported_memory');
builder.addTable(kWasmAnyFunc, 0).exportAs('exported_table');
// Add a function without breakpoint, to check that locals are shown
// correctly in compiled code.
......@@ -142,8 +144,11 @@ async function waitForWasmScripts() {
return wasm_script_ids;
}
async function getScopeValues(value) {
async function getScopeValues(name, value) {
if (value.type == 'object') {
if (value.subtype == 'typedarray') return value.description;
if (name == 'instance') return dumpInstanceProperties(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printIfFailure(msg);
const printProperty = function(elem) {
......@@ -157,11 +162,34 @@ async function getScopeValues(value) {
async function dumpScopeProperties(message) {
printIfFailure(message);
for (var value of message.result.result) {
var value_str = await getScopeValues(value.value);
var value_str = await getScopeValues(value.name, value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
async function dumpInstanceProperties(instanceObj) {
function invokeGetter(property) {
return this[JSON.parse(property)];
}
const exportsName = 'exports';
let exportsObj = await Protocol.Runtime.callFunctionOn(
{objectId: instanceObj.objectId,
functionDeclaration: invokeGetter.toString(),
arguments: [{value: JSON.stringify(exportsName)}]
});
printIfFailure(exportsObj);
let exports = await Protocol.Runtime.getProperties(
{objectId: exportsObj.result.result.objectId});
printIfFailure(exports);
const printExports = function(value) {
return `"${value.name}" (${value.value.className})`;
}
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
function getWasmValue(wasmValue) {
return typeof (wasmValue.value) === 'undefined' ?
wasmValue.unserializableValue :
......
......@@ -8,10 +8,12 @@ Script wasm://wasm/0c10a5fe byte offset 38: Wasm opcode 0x01
Scope:
at wasm_A (0:38):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -31,10 +33,12 @@ Script wasm://wasm/0c10a5fe byte offset 39: Wasm opcode 0x01
Scope:
at wasm_A (0:39):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -45,6 +49,7 @@ Script wasm://wasm/0c10a5fe byte offset 45: Wasm opcode 0x20
Scope:
at wasm_B (0:45):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -55,6 +60,7 @@ Script wasm://wasm/0c10a5fe byte offset 47: Wasm opcode 0x04
Scope:
at wasm_B (0:47):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -66,6 +72,7 @@ Script wasm://wasm/0c10a5fe byte offset 49: Wasm opcode 0x20
Scope:
at wasm_B (0:49):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -76,6 +83,7 @@ Script wasm://wasm/0c10a5fe byte offset 51: Wasm opcode 0x41
Scope:
at wasm_B (0:51):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -87,6 +95,7 @@ Script wasm://wasm/0c10a5fe byte offset 53: Wasm opcode 0x6b
Scope:
at wasm_B (0:53):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -99,6 +108,7 @@ Script wasm://wasm/0c10a5fe byte offset 54: Wasm opcode 0x21
Scope:
at wasm_B (0:54):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 3 (i32)
- scope (wasm-expression-stack):
......@@ -110,10 +120,12 @@ Script wasm://wasm/0c10a5fe byte offset 38: Wasm opcode 0x01
Scope:
at wasm_A (0:38):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -124,10 +136,12 @@ Script wasm://wasm/0c10a5fe byte offset 39: Wasm opcode 0x01
Scope:
at wasm_A (0:39):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -138,6 +152,7 @@ Script wasm://wasm/0c10a5fe byte offset 45: Wasm opcode 0x20
Scope:
at wasm_B (0:45):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -148,6 +163,7 @@ Script wasm://wasm/0c10a5fe byte offset 47: Wasm opcode 0x04
Scope:
at wasm_B (0:47):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -159,6 +175,7 @@ Script wasm://wasm/0c10a5fe byte offset 49: Wasm opcode 0x20
Scope:
at wasm_B (0:49):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -169,6 +186,7 @@ Script wasm://wasm/0c10a5fe byte offset 51: Wasm opcode 0x41
Scope:
at wasm_B (0:51):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -180,6 +198,7 @@ Script wasm://wasm/0c10a5fe byte offset 53: Wasm opcode 0x6b
Scope:
at wasm_B (0:53):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -192,6 +211,7 @@ Script wasm://wasm/0c10a5fe byte offset 54: Wasm opcode 0x21
Scope:
at wasm_B (0:54):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 2 (i32)
- scope (wasm-expression-stack):
......@@ -203,10 +223,12 @@ Script wasm://wasm/0c10a5fe byte offset 38: Wasm opcode 0x01
Scope:
at wasm_A (0:38):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -217,10 +239,12 @@ Script wasm://wasm/0c10a5fe byte offset 39: Wasm opcode 0x01
Scope:
at wasm_A (0:39):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -231,6 +255,7 @@ Script wasm://wasm/0c10a5fe byte offset 45: Wasm opcode 0x20
Scope:
at wasm_B (0:45):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -241,6 +266,7 @@ Script wasm://wasm/0c10a5fe byte offset 47: Wasm opcode 0x04
Scope:
at wasm_B (0:47):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -252,6 +278,7 @@ Script wasm://wasm/0c10a5fe byte offset 49: Wasm opcode 0x20
Scope:
at wasm_B (0:49):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -262,6 +289,7 @@ Script wasm://wasm/0c10a5fe byte offset 51: Wasm opcode 0x41
Scope:
at wasm_B (0:51):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -273,6 +301,7 @@ Script wasm://wasm/0c10a5fe byte offset 53: Wasm opcode 0x6b
Scope:
at wasm_B (0:53):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -285,6 +314,7 @@ Script wasm://wasm/0c10a5fe byte offset 54: Wasm opcode 0x21
Scope:
at wasm_B (0:54):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 1 (i32)
- scope (wasm-expression-stack):
......@@ -296,10 +326,12 @@ Script wasm://wasm/0c10a5fe byte offset 38: Wasm opcode 0x01
Scope:
at wasm_A (0:38):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 0 (i32)
- scope (wasm-expression-stack):
......@@ -310,10 +342,12 @@ Script wasm://wasm/0c10a5fe byte offset 39: Wasm opcode 0x01
Scope:
at wasm_A (0:39):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
- scope (wasm-expression-stack):
at wasm_B (0:56):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 0 (i32)
- scope (wasm-expression-stack):
......@@ -324,6 +358,7 @@ Script wasm://wasm/0c10a5fe byte offset 45: Wasm opcode 0x20
Scope:
at wasm_B (0:45):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 0 (i32)
- scope (wasm-expression-stack):
......@@ -334,6 +369,7 @@ Script wasm://wasm/0c10a5fe byte offset 47: Wasm opcode 0x04
Scope:
at wasm_B (0:47):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 0 (i32)
- scope (wasm-expression-stack):
......@@ -345,6 +381,7 @@ Script wasm://wasm/0c10a5fe byte offset 61: Wasm opcode 0x0b
Scope:
at wasm_B (0:61):
- scope (module):
instance: exports: "main" (Function)
- scope (local):
locals: "var0": 0 (i32)
- scope (wasm-expression-stack):
......
......@@ -83,7 +83,7 @@ Protocol.Debugger.onPaused(async msg => {
var properties = await Protocol.Runtime.getProperties(
{'objectId': scope.object.objectId});
for (var value of properties.result.result) {
var value_str = await getScopeValues(value.value);
var value_str = await getScopeValues(value.name, value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
......@@ -108,8 +108,10 @@ function getWasmValue(value) {
value.value;
}
async function getScopeValues(value) {
async function getScopeValues(name, value) {
if (value.type == 'object') {
if (name == 'instance') return dumpInstanceProperties(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
const printProperty = function(elem) {
return `"${elem.name}": ${getWasmValue(elem.value)} (${elem.value.subtype})`;
......@@ -119,6 +121,27 @@ async function getScopeValues(value) {
return getWasmValue(value) + ' (' + value.subtype + ')';
}
async function dumpInstanceProperties(instanceObj) {
function invokeGetter(property) {
return this[JSON.parse(property)];
}
const exportsName = 'exports';
let exportsObj = await Protocol.Runtime.callFunctionOn(
{objectId: instanceObj.objectId,
functionDeclaration: invokeGetter.toString(),
arguments: [{value: JSON.stringify(exportsName)}]
});
let exports = await Protocol.Runtime.getProperties(
{objectId: exportsObj.result.result.objectId});
const printExports = function(value) {
return `"${value.name}" (${value.value.className})`;
}
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
(async function test() {
await Protocol.Debugger.enable();
InspectorTest.log('Instantiating.');
......
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