Commit 6d08c94c authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm][debug] Provide WebAssembly Table entries to DevTools

With this CL, V8 adds an internal field to the WebAssembly Table object
that is sent to DevTools to also show table entries. As WebAssembly
Tables get initialized lazily, V8 only shows the name of the function
instead of the function object itself.

Screenshot before change: https://imgur.com/a/XFvy3lA
Screenshot after change: https://imgur.com/kT84kst
R=kimanh@chromium.org

Change-Id: I56a0b07785ff3484f1447419fe39ae5ec3f93247
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2897097Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarKim-Anh Tran <kimanh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74690}
parent e90c366b
......@@ -1113,5 +1113,24 @@ Handle<ArrayList> AddWasmModuleObjectInternalProperties(
return result;
}
Handle<ArrayList> AddWasmTableObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result, Handle<WasmTableObject> table) {
int length = table->current_length();
Handle<FixedArray> entries = isolate->factory()->NewFixedArray(length);
for (int i = 0; i < length; ++i) {
entries->set(i, *WasmTableObject::Get(isolate, table, i));
}
Handle<JSArray> final_entries = isolate->factory()->NewJSArrayWithElements(
entries, i::PACKED_ELEMENTS, length);
JSObject::SetPrototype(final_entries, isolate->factory()->null_value(), false,
kDontThrow)
.Check();
result = ArrayList::Add(
isolate, result,
isolate->factory()->NewStringFromStaticChars("[[Entries]]"),
final_entries);
return result;
}
} // namespace internal
} // namespace v8
......@@ -32,6 +32,7 @@ class ArrayList;
class WasmFrame;
class WasmInstanceObject;
class WasmModuleObject;
class WasmTableObject;
class WasmValueObject : public JSObject {
public:
......@@ -76,10 +77,14 @@ Handle<String> GetWasmFunctionDebugName(Isolate* isolate,
Handle<ArrayList> AddWasmInstanceObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result,
Handle<WasmInstanceObject> instance);
Handle<ArrayList> AddWasmModuleObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result,
Handle<WasmModuleObject> module_object);
Handle<ArrayList> AddWasmTableObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result, Handle<WasmTableObject> table);
} // namespace internal
} // namespace v8
......
......@@ -359,6 +359,9 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
} else if (object->IsWasmModuleObject()) {
result = AddWasmModuleObjectInternalProperties(
isolate, result, Handle<WasmModuleObject>::cast(object));
} else if (object->IsWasmTableObject()) {
result = AddWasmTableObjectInternalProperties(
isolate, result, Handle<WasmTableObject>::cast(object));
#endif // V8_ENABLE_WEBASSEMBLY
}
return isolate->factory()->NewJSArrayWithElements(
......
......@@ -26,7 +26,8 @@ at $C (interpreted) (0:169):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 0 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $B (liftoff) (0:158):
- scope (wasm-expression-stack):
stack: "0": 42 (i32), "1": 3 (i32)
......@@ -43,7 +44,8 @@ at $B (liftoff) (0:158):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 0 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -55,7 +57,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 0 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -76,7 +79,8 @@ at $C (interpreted) (0:171):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 0 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $B (liftoff) (0:158):
- scope (wasm-expression-stack):
stack: "0": 42 (i32), "1": 3 (i32)
......@@ -93,7 +97,8 @@ at $B (liftoff) (0:158):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 0 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -105,7 +110,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 0 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -126,7 +132,8 @@ at $C (interpreted) (0:173):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $B (liftoff) (0:158):
- scope (wasm-expression-stack):
stack: "0": 42 (i32), "1": 3 (i32)
......@@ -143,7 +150,8 @@ at $B (liftoff) (0:158):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -155,7 +163,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -176,7 +185,8 @@ at $C (interpreted) (0:175):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $B (liftoff) (0:158):
- scope (wasm-expression-stack):
stack: "0": 42 (i32), "1": 3 (i32)
......@@ -193,7 +203,8 @@ at $B (liftoff) (0:158):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -205,7 +216,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -226,7 +238,8 @@ at $C (interpreted) (0:177):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $B (liftoff) (0:158):
- scope (wasm-expression-stack):
stack: "0": 42 (i32), "1": 3 (i32)
......@@ -243,7 +256,8 @@ at $B (liftoff) (0:158):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -255,7 +269,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -279,7 +294,8 @@ at $B (liftoff) (0:160):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -291,7 +307,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -315,7 +332,8 @@ at $B (liftoff) (0:161):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -327,7 +345,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -351,7 +370,8 @@ at $B (liftoff) (0:162):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at $A (liftoff) (0:128):
- scope (wasm-expression-stack):
stack:
......@@ -363,7 +383,8 @@ at $A (liftoff) (0:128):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......@@ -382,7 +403,8 @@ at $A (liftoff) (0:130):
functions: "$A (liftoff)": (Function), "$B (liftoff)": (Function), "$C (interpreted)": (Function)
globals: "$exported_global": 42 (i32)
memories: "$exported_memory": (Memory)
tables: "$exported_table": (Table)
tables:
$exported_table: 0: function js_func() { [native code] }, 1: function () { [native code] }, 2: undefined, 3: function $A (liftoff)() { [native code] }
at (anonymous) (0:17):
- scope (global):
-- skipped globals
......
......@@ -87,6 +87,7 @@ async function getScopeValues(name, value) {
return value.description;
if (name === 'instance') return dumpInstanceProperties(value);
if (name === 'module') return value.description;
if (name === 'tables') return dumpTables(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printIfFailure(msg);
......@@ -137,3 +138,26 @@ async function dumpInstanceProperties(instanceObj) {
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
async function dumpTables(tablesObj) {
let msg =
await Protocol.Runtime.getProperties({objectId: tablesObj.objectId});
let tables_str = [];
for (let table of msg.result.result) {
let table_content =
await Protocol.Runtime.getProperties({objectId: table.value.objectId});
let entries_object = table_content.result.internalProperties.filter(
p => p.name === '[[Entries]]')[0];
entries = await Protocol.Runtime.getProperties(
{objectId: entries_object.value.objectId});
let functions = [];
for (let entry of entries.result.result) {
if (entry.name === 'length') continue;
functions.push(`${entry.name}: ${entry.value.description}`);
}
const functions_str = functions.join(', ');
tables_str.push(` ${table.name}: ${functions_str}`);
}
return '\n' + tables_str.join('\n');
}
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