Commit 96062c04 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Use spec'ed location format

This CL changes the printed wasm locations to use the spec'ed format
(see https://github.com/WebAssembly/design/blob/master/Web.md#developer-facing-display-conventions).

Before: <WASM[<id>]+<offset>
After:  wasm-function[<id>]:<offset>

R=ahaas@chromium.org

Change-Id: If8018012b518143d6353f5a1f5319764ee46f148
Reviewed-on: https://chromium-review.googlesource.com/529104Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45820}
parent 2b9e36e9
...@@ -1422,10 +1422,11 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { ...@@ -1422,10 +1422,11 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
// print the exception. // print the exception.
printf("%s\n", exception_string); printf("%s\n", exception_string);
} else if (message->GetScriptOrigin().Options().IsWasm()) { } else if (message->GetScriptOrigin().Options().IsWasm()) {
// Print <WASM>[(function index)]((function name))+(offset): (message). // Print wasm-function[(function index)]:(offset): (message).
int function_index = message->GetLineNumber(context).FromJust() - 1; int function_index = message->GetLineNumber(context).FromJust() - 1;
int offset = message->GetStartColumn(context).FromJust(); int offset = message->GetStartColumn(context).FromJust();
printf("<WASM>[%d]+%d: %s\n", function_index, offset, exception_string); printf("wasm-function[%d]:%d: %s\n", function_index, offset,
exception_string);
} else { } else {
// Print (filename):(line number): (message). // Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName()); v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
......
...@@ -675,24 +675,21 @@ MaybeHandle<String> WasmStackFrame::ToString() { ...@@ -675,24 +675,21 @@ MaybeHandle<String> WasmStackFrame::ToString() {
IncrementalStringBuilder builder(isolate_); IncrementalStringBuilder builder(isolate_);
Handle<Object> name = GetFunctionName(); Handle<Object> name = GetFunctionName();
if (name->IsNull(isolate_)) { if (!name->IsNull(isolate_)) {
builder.AppendCString("<WASM UNNAMED>");
} else {
DCHECK(name->IsString());
builder.AppendString(Handle<String>::cast(name)); builder.AppendString(Handle<String>::cast(name));
builder.AppendCString(" (");
} }
builder.AppendCString(" (<WASM>["); builder.AppendCString("wasm-function[");
char buffer[16]; char buffer[16];
SNPrintF(ArrayVector(buffer), "%u", wasm_func_index_); SNPrintF(ArrayVector(buffer), "%u]", wasm_func_index_);
builder.AppendCString(buffer); builder.AppendCString(buffer);
builder.AppendCString("]+"); SNPrintF(ArrayVector(buffer), ":%d", GetPosition());
SNPrintF(ArrayVector(buffer), "%d", GetPosition());
builder.AppendCString(buffer); builder.AppendCString(buffer);
builder.AppendCString(")");
if (!name->IsNull(isolate_)) builder.AppendCString(")");
return builder.Finish(); return builder.Finish();
} }
......
...@@ -18,8 +18,8 @@ end ...@@ -18,8 +18,8 @@ end
Getting current stack trace via "new Error().stack". Getting current stack trace via "new Error().stack".
Error Error
at v8://test/getStack:1:1 at v8://test/getStack:1:1
at func (<WASM>[0]+1) at func (wasm-function[0]:1)
at main (<WASM>[1]+1) at main (wasm-function[1]:1)
at v8://test/runWasm:1:22 at v8://test/runWasm:1:22
exports.main returned. exports.main returned.
Finished. Finished.
...@@ -12,8 +12,8 @@ Result of evaluate (string): ...@@ -12,8 +12,8 @@ Result of evaluate (string):
Error: this is your stack trace: Error: this is your stack trace:
-- skipped -- -- skipped --
at call_debugger (<anonymous>:3:5) at call_debugger (<anonymous>:3:5)
at call_func (<WASM>[1]+1) at call_func (wasm-function[1]:1)
at main (<WASM>[2]+3) at main (wasm-function[2]:3)
at testFunction (<anonymous>:15:20) at testFunction (<anonymous>:15:20)
at <anonymous>:1:1 at <anonymous>:1:1
Finished! Finished!
<WASM>[0]+5: RuntimeError: divide by zero wasm-function[0]:5: RuntimeError: divide by zero
RuntimeError: divide by zero RuntimeError: divide by zero
at main (<WASM>[0]+5) at main (wasm-function[0]:5)
at *%(basename)s:15:16 at *%(basename)s:15:16
...@@ -39,7 +39,7 @@ function checkStack(stack, expected_lines) { ...@@ -39,7 +39,7 @@ function checkStack(stack, expected_lines) {
checkStack(stripPath(stack), [ checkStack(stripPath(stack), [
'Error: test imported stack', // - 'Error: test imported stack', // -
/^ at func \(interpreter.js:\d+:28\)$/, // - /^ at func \(interpreter.js:\d+:28\)$/, // -
' at main (<WASM>[1]+1)', // - ' at main (wasm-function[1]:1)', // -
/^ at testCallImported \(interpreter.js:\d+:22\)$/, // - /^ at testCallImported \(interpreter.js:\d+:22\)$/, // -
/^ at interpreter.js:\d+:3$/ /^ at interpreter.js:\d+:3$/
]); ]);
...@@ -101,8 +101,8 @@ function checkStack(stack, expected_lines) { ...@@ -101,8 +101,8 @@ function checkStack(stack, expected_lines) {
assertEquals(interpreted_before + 2, %WasmNumInterpretedCalls(instance)); assertEquals(interpreted_before + 2, %WasmNumInterpretedCalls(instance));
checkStack(stripPath(stack), [ checkStack(stripPath(stack), [
'RuntimeError: unreachable', // - 'RuntimeError: unreachable', // -
' at foo (<WASM>[0]+3)', // - ' at foo (wasm-function[0]:3)', // -
' at main (<WASM>[1]+2)', // - ' at main (wasm-function[1]:2)', // -
/^ at testTrap \(interpreter.js:\d+:24\)$/, // - /^ at testTrap \(interpreter.js:\d+:24\)$/, // -
/^ at interpreter.js:\d+:3$/ /^ at interpreter.js:\d+:3$/
]); ]);
...@@ -133,7 +133,7 @@ function checkStack(stack, expected_lines) { ...@@ -133,7 +133,7 @@ function checkStack(stack, expected_lines) {
checkStack(stripPath(stack), [ checkStack(stripPath(stack), [
'Error: thrown from imported function', // - 'Error: thrown from imported function', // -
/^ at func \(interpreter.js:\d+:11\)$/, // - /^ at func \(interpreter.js:\d+:11\)$/, // -
' at main (<WASM>[1]+1)', // - ' at main (wasm-function[1]:1)', // -
/^ at testThrowFromImport \(interpreter.js:\d+:24\)$/, // - /^ at testThrowFromImport \(interpreter.js:\d+:24\)$/, // -
/^ at interpreter.js:\d+:3$/ /^ at interpreter.js:\d+:3$/
]); ]);
...@@ -213,10 +213,10 @@ function checkStack(stack, expected_lines) { ...@@ -213,10 +213,10 @@ function checkStack(stack, expected_lines) {
for (var e = 0; e < stacks.length; ++e) { for (var e = 0; e < stacks.length; ++e) {
expected = ['Error: reentrant interpreter test #' + e]; expected = ['Error: reentrant interpreter test #' + e];
expected.push(/^ at func \(interpreter.js:\d+:17\)$/); expected.push(/^ at func \(interpreter.js:\d+:17\)$/);
expected.push(' at main (<WASM>[1]+3)'); expected.push(' at main (wasm-function[1]:3)');
for (var k = e; k > 0; --k) { for (var k = e; k > 0; --k) {
expected.push(/^ at func \(interpreter.js:\d+:33\)$/); expected.push(/^ at func \(interpreter.js:\d+:33\)$/);
expected.push(' at main (<WASM>[1]+3)'); expected.push(' at main (wasm-function[1]:3)');
} }
expected.push( expected.push(
/^ at testReentrantInterpreter \(interpreter.js:\d+:22\)$/); /^ at testReentrantInterpreter \(interpreter.js:\d+:22\)$/);
...@@ -289,8 +289,8 @@ function checkStack(stack, expected_lines) { ...@@ -289,8 +289,8 @@ function checkStack(stack, expected_lines) {
if (!(e instanceof TypeError)) throw e; if (!(e instanceof TypeError)) throw e;
checkStack(stripPath(e.stack), [ checkStack(stripPath(e.stack), [
'TypeError: invalid type', // - 'TypeError: invalid type', // -
' at direct (<WASM>[1]+1)', // - ' at direct (wasm-function[1]:1)', // -
' at main (<WASM>[3]+3)', // - ' at main (wasm-function[3]:3)', // -
/^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // - /^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // -
/^ at interpreter.js:\d+:3$/ /^ at interpreter.js:\d+:3$/
]); ]);
...@@ -302,8 +302,8 @@ function checkStack(stack, expected_lines) { ...@@ -302,8 +302,8 @@ function checkStack(stack, expected_lines) {
if (!(e instanceof TypeError)) throw e; if (!(e instanceof TypeError)) throw e;
checkStack(stripPath(e.stack), [ checkStack(stripPath(e.stack), [
'TypeError: invalid type', // - 'TypeError: invalid type', // -
' at indirect (<WASM>[2]+1)', // - ' at indirect (wasm-function[2]:1)', // -
' at main (<WASM>[3]+3)', // - ' at main (wasm-function[3]:3)', // -
/^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // - /^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // -
/^ at interpreter.js:\d+:3$/ /^ at interpreter.js:\d+:3$/
]); ]);
...@@ -325,8 +325,8 @@ function checkStack(stack, expected_lines) { ...@@ -325,8 +325,8 @@ function checkStack(stack, expected_lines) {
if (!(e instanceof RangeError)) throw e; if (!(e instanceof RangeError)) throw e;
checkStack(stripPath(e.stack), [ checkStack(stripPath(e.stack), [
'RangeError: Maximum call stack size exceeded', 'RangeError: Maximum call stack size exceeded',
' at main (<WASM>[0]+0)' ' at main (wasm-function[0]:0)'
].concat(Array(9).fill(' at main (<WASM>[0]+2)'))); ].concat(Array(9).fill(' at main (wasm-function[0]:2)')));
} }
})(); })();
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// clang-format off
// Flags: --expose-wasm // Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js"); load("test/mjsunit/wasm/wasm-constants.js");
...@@ -25,8 +24,8 @@ function verifyStack(frames, expected) { ...@@ -25,8 +24,8 @@ function verifyStack(frames, expected) {
assertContains(exp[4], frames[i].getFileName(), "["+i+"].getFileName()"); assertContains(exp[4], frames[i].getFileName(), "["+i+"].getFileName()");
var toString; var toString;
if (exp[0]) { if (exp[0]) {
var fun_str = exp[1] !== null ? exp[1] : "<WASM UNNAMED>"; toString = "wasm-function[" + exp[2] + "]:" + exp[3];
toString = fun_str + " (<WASM>[" + exp[2] + "]+" + exp[3] + ")"; if (exp[1] !== null) toString = exp[1] + " (" + toString + ")";
} else { } else {
toString = exp[4] + ":" + exp[2] + ":"; toString = exp[4] + ":" + exp[2] + ":";
} }
...@@ -69,12 +68,12 @@ builder.addFunction("call_mem_out_of_bounds", kSig_i_v) ...@@ -69,12 +68,12 @@ builder.addFunction("call_mem_out_of_bounds", kSig_i_v)
var module = builder.instantiate({mod: {func: STACK}}); var module = builder.instantiate({mod: {func: STACK}});
(function testSimpleStack() { (function testSimpleStack() {
var expected_string = "Error\n" + var expected_string = 'Error\n' +
// The line numbers below will change as this test gains / loses lines.. // The line numbers below will change as this test gains / loses lines..
" at STACK (stack.js:40:11)\n" + // -- ' at STACK (stack.js:39:11)\n' + // --
" at main (<WASM>[1]+1)\n" + // -- ' at main (wasm-function[1]:1)\n' + // --
" at testSimpleStack (stack.js:79:18)\n" + // -- ' at testSimpleStack (stack.js:78:18)\n' + // --
" at stack.js:81:3"; // -- ' at stack.js:80:3'; // --
module.exports.main(); module.exports.main();
assertEquals(expected_string, stripPath(stack)); assertEquals(expected_string, stripPath(stack));
...@@ -91,10 +90,10 @@ Error.prepareStackTrace = function(error, frames) { ...@@ -91,10 +90,10 @@ Error.prepareStackTrace = function(error, frames) {
verifyStack(stack, [ verifyStack(stack, [
// isWasm function line pos file // isWasm function line pos file
[ false, "STACK", 40, 0, "stack.js"], [ false, "STACK", 39, 0, "stack.js"],
[ true, "main", 1, 1, null], [ true, "main", 1, 1, null],
[ false, "testStackFrames", 90, 0, "stack.js"], [ false, "testStackFrames", 89, 0, "stack.js"],
[ false, null, 99, 0, "stack.js"] [ false, null, 98, 0, "stack.js"]
]); ]);
})(); })();
...@@ -107,8 +106,8 @@ Error.prepareStackTrace = function(error, frames) { ...@@ -107,8 +106,8 @@ Error.prepareStackTrace = function(error, frames) {
verifyStack(e.stack, [ verifyStack(e.stack, [
// isWasm function line pos file // isWasm function line pos file
[ true, "exec_unreachable", 2, 1, null], [ true, "exec_unreachable", 2, 1, null],
[ false, "testWasmUnreachable", 103, 0, "stack.js"], [ false, "testWasmUnreachable", 102, 0, "stack.js"],
[ false, null, 114, 0, "stack.js"] [ false, null, 113, 0, "stack.js"]
]); ]);
} }
})(); })();
...@@ -123,8 +122,8 @@ Error.prepareStackTrace = function(error, frames) { ...@@ -123,8 +122,8 @@ Error.prepareStackTrace = function(error, frames) {
// isWasm function line pos file // isWasm function line pos file
[ true, null, 3, 3, null], [ true, null, 3, 3, null],
[ true, "call_mem_out_of_bounds", 4, 1, null], [ true, "call_mem_out_of_bounds", 4, 1, null],
[ false, "testWasmMemOutOfBounds", 118, 0, "stack.js"], [ false, "testWasmMemOutOfBounds", 117, 0, "stack.js"],
[ false, null, 130, 0, "stack.js"] [ false, null, 129, 0, "stack.js"]
]); ]);
} }
})(); })();
......
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