Commit a0fd7918 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Fix source positions for thrown exceptions.

This fixes the source position printed in the stack trace for exceptions
thrown from within Wasm code. Specifically this affects the stack trace
attached to the exception object, as well as the message propagated to
the console. Both are tested by the new message test.

R=clemensh@chromium.org
TEST=message/fail/wasm-exception-throw
BUG=v8:8091

Change-Id: I5b2f76191cf47457ac113dce9d9601a8a810ee19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1591603Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61239}
parent 748a1469
......@@ -2073,7 +2073,8 @@ Node* WasmGraphBuilder::MemoryGrow(Node* input) {
Node* WasmGraphBuilder::Throw(uint32_t exception_index,
const wasm::WasmException* exception,
const Vector<Node*> values) {
const Vector<Node*> values,
wasm::WasmCodePosition position) {
needs_stack_check_ = true;
uint32_t encoded_size = WasmExceptionPackage::GetEncodedSize(exception);
Node* create_parameters[] = {
......@@ -2082,6 +2083,7 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
Node* except_obj =
BuildCallToRuntime(Runtime::kWasmThrowCreate, create_parameters,
arraysize(create_parameters));
SetSourcePosition(except_obj, position);
Node* values_array =
BuildCallToRuntime(Runtime::kWasmExceptionGetValues, &except_obj, 1);
uint32_t index = 0;
......@@ -2140,9 +2142,11 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmThrow, RelocInfo::WASM_STUB_CALL);
return SetEffect(SetControl(
Node* call = SetEffect(SetControl(
graph()->NewNode(mcgraph()->common()->Call(call_descriptor), call_target,
except_obj, Effect(), Control())));
SetSourcePosition(call, position);
return call;
}
void WasmGraphBuilder::BuildEncodeException32BitValue(Node* values_array,
......@@ -3916,8 +3920,9 @@ void WasmGraphBuilder::SimdScalarLoweringForTesting() {
void WasmGraphBuilder::SetSourcePosition(Node* node,
wasm::WasmCodePosition position) {
DCHECK_NE(position, wasm::kNoCodePosition);
if (source_position_table_)
if (source_position_table_) {
source_position_table_->SetSourcePosition(node, SourcePosition(position));
}
}
Node* WasmGraphBuilder::S128Zero() {
......
......@@ -205,7 +205,7 @@ class WasmGraphBuilder {
wasm::WasmCodePosition position = wasm::kNoCodePosition);
Node* MemoryGrow(Node* input);
Node* Throw(uint32_t exception_index, const wasm::WasmException* exception,
const Vector<Node*> values);
const Vector<Node*> values, wasm::WasmCodePosition position);
Node* Rethrow(Node* except_obj);
Node* ExceptionTagEqual(Node* caught_tag, Node* expected_tag);
Node* LoadExceptionTagFromTable(uint32_t exception_index);
......
......@@ -461,7 +461,7 @@ class WasmGraphBuildingInterface {
for (int i = 0; i < count; ++i) {
args[i] = value_args[i].node;
}
BUILD(Throw, imm.index, imm.exception, VectorOf(args));
BUILD(Throw, imm.index, imm.exception, VectorOf(args), decoder->position());
builder_->TerminateThrow(ssa_env_->effect, ssa_env_->control);
}
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-wasm --experimental-wasm-eh
load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_i);
builder.addFunction("throw0", kSig_v_v)
.addBody([
kExprI32Const, 23,
kExprThrow, except,
]).exportFunc();
let instance = builder.instantiate();
instance.exports.throw0();
wasm-function[0]:3: RuntimeError: wasm exception
RuntimeError: wasm exception
at throw0 (wasm-function[0]:3)
at *%(basename)s:17:18
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