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) {
return n;
}
void PrintIndentation(Isolate* isolate) {
const int nmax = 80;
int n = StackSize(isolate);
if (n <= nmax) {
PrintF("%4d:%*s", n, n, "");
void PrintIndentation(int stack_size) {
const int max_display = 80;
if (stack_size <= max_display) {
PrintF("%4d:%*s", stack_size, stack_size, "");
} else {
PrintF("%4d:%*s", n, nmax, "...");
PrintF("%4d:%*s", stack_size, max_display, "...");
}
}
......@@ -930,7 +929,7 @@ void PrintIndentation(Isolate* isolate) {
RUNTIME_FUNCTION(Runtime_TraceEnter) {
SealHandleScope shs(isolate);
DCHECK_EQ(0, args.length());
PrintIndentation(isolate);
PrintIndentation(StackSize(isolate));
JavaScriptFrame::PrintTop(isolate, stdout, true, false);
PrintF(" {\n");
return ReadOnlyRoots(isolate).undefined_value();
......@@ -940,18 +939,59 @@ RUNTIME_FUNCTION(Runtime_TraceExit) {
SealHandleScope shs(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_CHECKED(Object, obj, 0);
PrintIndentation(isolate);
PrintIndentation(StackSize(isolate));
PrintF("} -> ");
obj.ShortPrint();
PrintF("\n");
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) {
SealHandleScope shs(isolate);
HandleScope shs(isolate);
DCHECK_EQ(0, args.length());
// TODO(10559): Print function name and indentation.
PrintF("Enter function\n");
PrintIndentation(WasmStackSize(isolate));
// 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();
}
......@@ -960,8 +1000,8 @@ RUNTIME_FUNCTION(Runtime_WasmTraceExit) {
DCHECK_EQ(1, args.length());
CONVERT_ARG_CHECKED(Smi, value_addr_smi, 0);
// TODO(10559): Print function name and indentation.
PrintF("Exit function");
PrintIndentation(WasmStackSize(isolate));
PrintF("}");
// Find the caller wasm frame.
wasm::WasmCodeRefScope wasm_code_ref_scope;
......
......@@ -11,10 +11,17 @@ let kRet23Function = builder.addFunction('ret_23', kSig_i_v)
.addBody([kExprI32Const, 23])
.exportFunc()
.index;
let kCall23Function = builder.addFunction('call_23', kSig_i_v)
.addBody([kExprCallFunction, kRet23Function])
.exportFunc()
.index;
let kRet57Function = builder.addFunction('ret_57', kSig_l_v)
.addBody([kExprI64Const, 57])
.exportFunc()
.index;
let kUnnamedFunction = builder.addFunction(undefined, kSig_l_v)
.addBody([kExprCallFunction, kRet57Function])
.index;
let kRet0Function = builder.addFunction('ret_0', kSig_f_v)
.addBody(wasmF32Const(0))
.exportFunc()
......@@ -25,8 +32,8 @@ let kRet1Function = builder.addFunction('ret_1', kSig_d_v)
.index;
builder.addFunction('main', kSig_v_v)
.addBody([
kExprCallFunction, kRet23Function, kExprDrop, // -
kExprCallFunction, kRet57Function, kExprDrop, // -
kExprCallFunction, kCall23Function, kExprDrop, // -
kExprCallFunction, kUnnamedFunction, kExprDrop, // -
kExprCallFunction, kRet0Function, kExprDrop, // -
kExprCallFunction, kRet1Function, kExprDrop // -
])
......
Enter function
Enter function
Exit function -> 23
Enter function
Exit function -> 57
Enter function
Exit function -> 0.000000
Enter function
Exit function -> 1.000000
Exit function
1: ~wasm-function[6] "main" {
2: ~wasm-function[1] "call_23" {
3: ~wasm-function[0] "ret_23" {
3: } -> 23
2: } -> 23
2: ~wasm-function[3] {
3: ~wasm-function[2] "ret_57" {
3: } -> 57
2: } -> 57
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