[inspector] Improve RemoteObject description for Wasm functions.

The WebAssembly specification requires the "name" property of (exported)
function wrappers to hold the index of the function within the module,
and the default ToString algorithm for Function instances thus generates
something along the lines of `function 42() { [native code] }`, which is
technically correct, but not very useful to developers to diagnose
(humans don't think of functions in a module in terms of their indices).
With this CL, we change the description returned for Wasm (exported)
functions to use the debug name of the Wasm function instead.

Screenshot: https://imgur.com/a/FVPeXDU.png
Doc: http://bit.ly/devtools-wasm-entities
Fixed: chromium:1206620
Bug: chromium:1164241
Change-Id: I096abc287ea077556c13c71f8d71f64452ab4831
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2891570
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74517}
This commit is contained in:
Benedikt Meurer 2021-05-12 09:42:16 +02:00 committed by V8 LUCI CQ
parent 203f527619
commit 32f80efe7e
3 changed files with 36 additions and 15 deletions

View File

@ -14,6 +14,7 @@
#include "src/objects/js-generator-inl.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/regexp/regexp-stack.h"
#include "src/strings/string-builder-inl.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/debug/debug-wasm-objects-inl.h"
@ -65,8 +66,28 @@ Local<String> GetFunctionDescription(Local<Function> function) {
i::Handle<i::JSBoundFunction>::cast(receiver)));
}
if (receiver->IsJSFunction()) {
return Utils::ToLocal(
i::JSFunction::ToString(i::Handle<i::JSFunction>::cast(receiver)));
auto function = i::Handle<i::JSFunction>::cast(receiver);
#if V8_ENABLE_WEBASSEMBLY
if (function->shared().HasWasmExportedFunctionData()) {
auto isolate = function->GetIsolate();
auto func_index =
function->shared().wasm_exported_function_data().function_index();
auto instance = i::handle(
function->shared().wasm_exported_function_data().instance(), isolate);
if (instance->module()->origin == i::wasm::kWasmOrigin) {
// For asm.js functions, we can still print the source
// code (hopefully), so don't bother with them here.
auto debug_name =
i::GetWasmFunctionDebugName(isolate, instance, func_index);
i::IncrementalStringBuilder builder(isolate);
builder.AppendCString("function ");
builder.AppendString(debug_name);
builder.AppendCString("() { [native code] }");
return Utils::ToLocal(builder.Finish().ToHandleChecked());
}
}
#endif // V8_ENABLE_WEBASSEMBLY
return Utils::ToLocal(i::JSFunction::ToString(function));
}
return Utils::ToLocal(
receiver->GetIsolate()->factory()->function_native_code_string());

View File

@ -55,18 +55,18 @@ Debugger paused in $main.
> functions = Functions
> typeof functions = "object"
> Object.keys(functions) = Array(4)
> functions[0] = function 0() { [native code] }
> functions[1] = function 1() { [native code] }
> functions[2] = function 2() { [native code] }
> functions[3] = function 3() { [native code] }
> functions[4] = function 4() { [native code] }
> functions["$foo.bar"] = function 0() { [native code] }
> functions["$main"] = function 1() { [native code] }
> $main = function 1() { [native code] }
> functions["$func2"] = function 2() { [native code] }
> $func2 = function 2() { [native code] }
> functions["$func4"] = function 4() { [native code] }
> $func4 = function 4() { [native code] }
> functions[0] = function $foo.bar() { [native code] }
> functions[1] = function $main() { [native code] }
> functions[2] = function $func2() { [native code] }
> functions[3] = function $func2() { [native code] }
> functions[4] = function $func4() { [native code] }
> functions["$foo.bar"] = function $foo.bar() { [native code] }
> functions["$main"] = function $main() { [native code] }
> $main = function $main() { [native code] }
> functions["$func2"] = function $func2() { [native code] }
> $func2 = function $func2() { [native code] }
> functions["$func4"] = function $func4() { [native code] }
> $func4 = function $func4() { [native code] }
Running test: testLocals
Compile module.

View File

@ -25,7 +25,7 @@ at $main (0:107):
instance: exports: "main" (Function)
module: Module
functions: "$main": (Function)
globals: "$global0": function 0() { [native code] } ((ref null $type3))
globals: "$global0": function $main() { [native code] } ((ref null $type3))
at (anonymous) (0:17):
-- skipped
exports.main returned!