Commit e9380ae2 authored by Arnaud Robin's avatar Arnaud Robin Committed by Commit Bot

[wasm] Add indentation and function names when tracing function calls

Added display of identation, function index, function names and compiler
used when tracing function calls in wasm.

R=clemensb@chromium.org

Bug: v8:10559
Change-Id: I58b4e7b077365bdee7bae9b5ad8a50178c322147
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2230532
Commit-Queue: Arnaud Robin <arobin@google.com>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68198}
parent 93e992bb
...@@ -915,13 +915,12 @@ int StackSize(Isolate* isolate) { ...@@ -915,13 +915,12 @@ int StackSize(Isolate* isolate) {
return n; return n;
} }
void PrintIndentation(Isolate* isolate) { void PrintIndentation(int stack_size) {
const int nmax = 80; const int max_display = 80;
int n = StackSize(isolate); if (stack_size <= max_display) {
if (n <= nmax) { PrintF("%4d:%*s", stack_size, stack_size, "");
PrintF("%4d:%*s", n, n, "");
} else { } else {
PrintF("%4d:%*s", n, nmax, "..."); PrintF("%4d:%*s", stack_size, max_display, "...");
} }
} }
...@@ -930,7 +929,7 @@ void PrintIndentation(Isolate* isolate) { ...@@ -930,7 +929,7 @@ void PrintIndentation(Isolate* isolate) {
RUNTIME_FUNCTION(Runtime_TraceEnter) { RUNTIME_FUNCTION(Runtime_TraceEnter) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK_EQ(0, args.length()); DCHECK_EQ(0, args.length());
PrintIndentation(isolate); PrintIndentation(StackSize(isolate));
JavaScriptFrame::PrintTop(isolate, stdout, true, false); JavaScriptFrame::PrintTop(isolate, stdout, true, false);
PrintF(" {\n"); PrintF(" {\n");
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
...@@ -940,18 +939,59 @@ RUNTIME_FUNCTION(Runtime_TraceExit) { ...@@ -940,18 +939,59 @@ RUNTIME_FUNCTION(Runtime_TraceExit) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_CHECKED(Object, obj, 0); CONVERT_ARG_CHECKED(Object, obj, 0);
PrintIndentation(isolate); PrintIndentation(StackSize(isolate));
PrintF("} -> "); PrintF("} -> ");
obj.ShortPrint(); obj.ShortPrint();
PrintF("\n"); PrintF("\n");
return obj; // return TOS return obj; // return TOS
} }
namespace {
int WasmStackSize(Isolate* isolate) {
// TODO(wasm): Fix this for mixed JS/Wasm stacks with both --trace and
// --trace-wasm.
int n = 0;
for (StackTraceFrameIterator it(isolate); !it.done(); it.Advance()) {
if (it.is_wasm()) n++;
}
return n;
}
} // namespace
RUNTIME_FUNCTION(Runtime_WasmTraceEnter) { RUNTIME_FUNCTION(Runtime_WasmTraceEnter) {
SealHandleScope shs(isolate); HandleScope shs(isolate);
DCHECK_EQ(0, args.length()); DCHECK_EQ(0, args.length());
// TODO(10559): Print function name and indentation. PrintIndentation(WasmStackSize(isolate));
PrintF("Enter function\n");
// Find the caller wasm frame.
wasm::WasmCodeRefScope wasm_code_ref_scope;
StackTraceFrameIterator it(isolate);
DCHECK(!it.done());
DCHECK(it.is_wasm());
WasmFrame* frame = WasmFrame::cast(it.frame());
// Find the function name.
int func_index = frame->function_index();
const wasm::WasmModule* module = frame->wasm_instance().module();
wasm::ModuleWireBytes wire_bytes =
wasm::ModuleWireBytes(frame->native_module()->wire_bytes());
wasm::WireBytesRef name_ref =
module->lazily_generated_names.LookupFunctionName(
wire_bytes, func_index, VectorOf(module->export_table));
wasm::WasmName name = wire_bytes.GetNameOrNull(name_ref);
wasm::WasmCode* code = frame->wasm_code();
PrintF(code->is_liftoff() ? "~" : "*");
if (name.empty()) {
PrintF("wasm-function[%d] {\n", func_index);
} else {
PrintF("wasm-function[%d] \"%.*s\" {\n", func_index, name.length(),
name.begin());
}
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
...@@ -960,8 +1000,8 @@ RUNTIME_FUNCTION(Runtime_WasmTraceExit) { ...@@ -960,8 +1000,8 @@ RUNTIME_FUNCTION(Runtime_WasmTraceExit) {
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_CHECKED(Smi, value_addr_smi, 0); CONVERT_ARG_CHECKED(Smi, value_addr_smi, 0);
// TODO(10559): Print function name and indentation. PrintIndentation(WasmStackSize(isolate));
PrintF("Exit function"); PrintF("}");
// Find the caller wasm frame. // Find the caller wasm frame.
wasm::WasmCodeRefScope wasm_code_ref_scope; wasm::WasmCodeRefScope wasm_code_ref_scope;
......
...@@ -11,10 +11,17 @@ let kRet23Function = builder.addFunction('ret_23', kSig_i_v) ...@@ -11,10 +11,17 @@ let kRet23Function = builder.addFunction('ret_23', kSig_i_v)
.addBody([kExprI32Const, 23]) .addBody([kExprI32Const, 23])
.exportFunc() .exportFunc()
.index; .index;
let kCall23Function = builder.addFunction('call_23', kSig_i_v)
.addBody([kExprCallFunction, kRet23Function])
.exportFunc()
.index;
let kRet57Function = builder.addFunction('ret_57', kSig_l_v) let kRet57Function = builder.addFunction('ret_57', kSig_l_v)
.addBody([kExprI64Const, 57]) .addBody([kExprI64Const, 57])
.exportFunc() .exportFunc()
.index; .index;
let kUnnamedFunction = builder.addFunction(undefined, kSig_l_v)
.addBody([kExprCallFunction, kRet57Function])
.index;
let kRet0Function = builder.addFunction('ret_0', kSig_f_v) let kRet0Function = builder.addFunction('ret_0', kSig_f_v)
.addBody(wasmF32Const(0)) .addBody(wasmF32Const(0))
.exportFunc() .exportFunc()
...@@ -25,10 +32,10 @@ let kRet1Function = builder.addFunction('ret_1', kSig_d_v) ...@@ -25,10 +32,10 @@ let kRet1Function = builder.addFunction('ret_1', kSig_d_v)
.index; .index;
builder.addFunction('main', kSig_v_v) builder.addFunction('main', kSig_v_v)
.addBody([ .addBody([
kExprCallFunction, kRet23Function, kExprDrop, // - kExprCallFunction, kCall23Function, kExprDrop, // -
kExprCallFunction, kRet57Function, kExprDrop, // - kExprCallFunction, kUnnamedFunction, kExprDrop, // -
kExprCallFunction, kRet0Function, kExprDrop, // - kExprCallFunction, kRet0Function, kExprDrop, // -
kExprCallFunction, kRet1Function, kExprDrop // - kExprCallFunction, kRet1Function, kExprDrop // -
]) ])
.exportAs('main'); .exportAs('main');
......
Enter function 1: ~wasm-function[6] "main" {
Enter function 2: ~wasm-function[1] "call_23" {
Exit function -> 23 3: ~wasm-function[0] "ret_23" {
Enter function 3: } -> 23
Exit function -> 57 2: } -> 23
Enter function 2: ~wasm-function[3] {
Exit function -> 0.000000 3: ~wasm-function[2] "ret_57" {
Enter function 3: } -> 57
Exit function -> 1.000000 2: } -> 57
Exit function 2: ~wasm-function[4] "ret_0" {
2: } -> 0.000000
2: ~wasm-function[5] "ret_1" {
2: } -> 1.000000
1: }
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