Commit f47009a8 authored by Philip Pfaffe's avatar Philip Pfaffe Committed by Commit Bot

[wasm-debug-eval] Reland: Implement additional evaluator API

This CL relands the implementation of the __getLocal and __sbrk APIs of
the evaluator interface reverted in efea7407. Update the original
commit to account for a changes to the import function name tracking and
defaulting to debugging with liftoff.

Change-Id: I9674aad419fb1dab0a9ecbb5d3fd4c33186b127a
Bug: chromium:1020120
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2151353
Commit-Queue: Philip Pfaffe <pfaffe@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67178}
parent d6b8f0b3
......@@ -5,15 +5,19 @@
#include "src/wasm/wasm-debug-evaluate.h"
#include <algorithm>
#include <limits>
#include "src/api/api-inl.h"
#include "src/codegen/machine-type.h"
#include "src/execution/frames-inl.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-arguments.h"
#include "src/wasm/wasm-constants.h"
#include "src/wasm/wasm-debug.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-value.h"
namespace v8 {
namespace internal {
......@@ -76,7 +80,8 @@ static bool CheckRangeOutOfBounds(uint32_t offset, uint32_t size,
class DebugEvaluatorProxy {
public:
explicit DebugEvaluatorProxy(Isolate* isolate) : isolate_(isolate) {}
explicit DebugEvaluatorProxy(Isolate* isolate, StandardFrame* frame)
: isolate_(isolate), frame_(frame) {}
static void GetMemoryTrampoline(
const v8::FunctionCallbackInfo<v8::Value>& args) {
......@@ -103,17 +108,68 @@ class DebugEvaluatorProxy {
&debuggee_->memory_start()[offset], size);
}
template <typename CallableT>
Handle<JSReceiver> WrapAsV8Function(CallableT callback) {
v8::Isolate* api_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
v8::Local<v8::Context> context = api_isolate->GetCurrentContext();
std::string data;
v8::Local<v8::Function> func =
v8::Function::New(context, callback,
v8::External::New(api_isolate, this))
.ToLocalChecked();
// void* __sbrk(intptr_t increment);
uint32_t Sbrk(uint32_t increment) {
if (increment > 0 && evaluator_->memory_size() <=
std::numeric_limits<uint32_t>::max() - increment) {
Handle<WasmMemoryObject> memory(evaluator_->memory_object(), isolate_);
uint32_t new_pages =
(increment - 1 + wasm::kWasmPageSize) / wasm::kWasmPageSize;
WasmMemoryObject::Grow(isolate_, memory, new_pages);
}
return static_cast<uint32_t>(evaluator_->memory_size());
}
return Utils::OpenHandle(*func);
static void SbrkTrampoline(const v8::FunctionCallbackInfo<v8::Value>& args) {
auto& proxy = GetProxy(args);
uint32_t size = proxy.GetArgAsUInt32(args, 0);
uint32_t result = proxy.Sbrk(size);
args.GetReturnValue().Set(result);
}
template <typename T>
void write_result(const WasmValue& result, uint32_t result_offset) {
wasm::ScheduledErrorThrower thrower(isolate_, "debug evaluate proxy");
T val = result.to<T>();
static_assert(static_cast<uint32_t>(sizeof(T)) == sizeof(T),
"Unexpected size");
if (CheckRangeOutOfBounds(result_offset, sizeof(T),
evaluator_->memory_size(), &thrower)) {
return;
}
memcpy(&evaluator_->memory_start()[result_offset], &val, sizeof(T));
}
// void __getLocal(uint32_t local, void* result);
void GetLocal(uint32_t local, uint32_t result_offset) {
WasmValue result = LoadLocalValue(local);
switch (result.type().kind()) {
case ValueType::kI32:
write_result<uint32_t>(result, result_offset);
break;
case ValueType::kI64:
write_result<int64_t>(result, result_offset);
break;
case ValueType::kF32:
write_result<float>(result, result_offset);
break;
case ValueType::kF64:
write_result<double>(result, result_offset);
break;
default:
UNIMPLEMENTED();
}
}
static void GetLocalTrampoline(
const v8::FunctionCallbackInfo<v8::Value>& args) {
auto& proxy = GetProxy(args);
uint32_t local = proxy.GetArgAsUInt32(args, 0);
uint32_t result = proxy.GetArgAsUInt32(args, 1);
proxy.GetLocal(local, result);
}
Handle<JSObject> CreateImports() {
......@@ -121,14 +177,16 @@ class DebugEvaluatorProxy {
isolate_->factory()->NewJSObject(isolate_->object_function());
Handle<JSObject> import_module_obj =
isolate_->factory()->NewJSObject(isolate_->object_function());
Object::SetProperty(isolate_, imports_obj,
isolate_->factory()->empty_string(), import_module_obj)
Object::SetProperty(isolate_, imports_obj, V8String(isolate_, "env"),
import_module_obj)
.Assert();
Object::SetProperty(
isolate_, import_module_obj, V8String(isolate_, "__getMemory"),
WrapAsV8Function(DebugEvaluatorProxy::GetMemoryTrampoline))
.Assert();
AddImport(import_module_obj, "__getLocal",
DebugEvaluatorProxy::GetLocalTrampoline);
AddImport(import_module_obj, "__getMemory",
DebugEvaluatorProxy::GetMemoryTrampoline);
AddImport(import_module_obj, "__sbrk", DebugEvaluatorProxy::SbrkTrampoline);
return imports_obj;
}
......@@ -139,6 +197,21 @@ class DebugEvaluatorProxy {
}
private:
WasmValue LoadLocalValue(uint32_t local) {
if (frame_->is_wasm_interpreter_entry()) {
i::wasm::WasmInterpreter::FramePtr framePtr =
debuggee_->debug_info().GetInterpretedFrame(frame_->fp(),
inlined_frame_);
return framePtr->GetLocalValue(local);
}
DCHECK(frame_->is_wasm_compiled());
wasm::DebugInfo* debug_info =
WasmCompiledFrame::cast(frame_)->native_module()->GetDebugInfo();
return debug_info->GetLocalValue(local, isolate_, frame_->pc(),
frame_->fp(), frame_->callee_fp());
}
uint32_t GetArgAsUInt32(const v8::FunctionCallbackInfo<v8::Value>& args,
int index) {
// No type/range checks needed on his because this is only called for {args}
......@@ -153,7 +226,27 @@ class DebugEvaluatorProxy {
args.Data().As<v8::External>()->Value());
}
template <typename CallableT>
void AddImport(Handle<JSObject> import_module_obj, const char* function_name,
CallableT callback) {
v8::Isolate* api_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
v8::Local<v8::Context> context = api_isolate->GetCurrentContext();
std::string data;
v8::Local<v8::Function> v8_function =
v8::Function::New(context, callback,
v8::External::New(api_isolate, this))
.ToLocalChecked();
auto wrapped_function = Utils::OpenHandle(*v8_function);
Object::SetProperty(isolate_, import_module_obj,
V8String(isolate_, function_name), wrapped_function)
.Assert();
}
Isolate* isolate_;
StandardFrame* frame_;
int inlined_frame_ = 0;
Handle<WasmInstanceObject> evaluator_;
Handle<WasmInstanceObject> debuggee_;
};
......@@ -161,31 +254,62 @@ class DebugEvaluatorProxy {
static bool VerifyEvaluatorInterface(const WasmModule* raw_module,
const ModuleWireBytes& bytes,
ErrorThrower* thrower) {
for (const WasmFunction& F : raw_module->functions) {
WireBytesRef name_ref =
raw_module->lazily_generated_names.LookupFunctionName(
bytes, F.func_index, VectorOf(raw_module->export_table));
std::string name(bytes.start() + name_ref.offset(),
bytes.start() + name_ref.end_offset());
if (F.exported && name == "wasm_format") {
if (!CheckSignature(kWasmI32, {}, F.sig, thrower)) return false;
} else if (F.imported) {
if (name == "__getMemory") {
if (!CheckSignature(kWasmBottom, {kWasmI32, kWasmI32, kWasmI32}, F.sig,
for (const WasmImport imported : raw_module->import_table) {
if (imported.kind != ImportExportKindCode::kExternalFunction) continue;
const WasmFunction& F = raw_module->functions.at(imported.index);
std::string module_name(bytes.start() + imported.module_name.offset(),
bytes.start() + imported.module_name.end_offset());
std::string field_name(bytes.start() + imported.field_name.offset(),
bytes.start() + imported.field_name.end_offset());
if (module_name == "env") {
if (field_name == "__getMemory") {
// void __getMemory(uint32_t offset, uint32_t size, void* result);
if (CheckSignature(kWasmBottom, {kWasmI32, kWasmI32, kWasmI32}, F.sig,
thrower)) {
return false;
continue;
}
} else if (field_name == "__getLocal") {
// void __getLocal(uint32_t local, void* result)
if (CheckSignature(kWasmBottom, {kWasmI32, kWasmI32}, F.sig, thrower)) {
continue;
}
} else if (field_name == "__debug") {
// void __debug(uint32_t flag, uint32_t value)
if (CheckSignature(kWasmBottom, {kWasmI32, kWasmI32}, F.sig, thrower)) {
continue;
}
} else if (field_name == "__sbrk") {
// uint32_t __sbrk(uint32_t increment)
if (CheckSignature(kWasmI32, {kWasmI32}, F.sig, thrower)) {
continue;
}
}
}
if (!thrower->error()) {
thrower->LinkError("Unknown import \"%s\" \"%s\"", module_name.c_str(),
field_name.c_str());
}
return false;
}
for (const WasmExport& exported : raw_module->export_table) {
if (exported.kind != ImportExportKindCode::kExternalFunction) continue;
const WasmFunction& F = raw_module->functions.at(exported.index);
std::string field_name(bytes.start() + exported.name.offset(),
bytes.start() + exported.name.end_offset());
if (field_name == "wasm_format") {
if (!CheckSignature(kWasmI32, {}, F.sig, thrower)) return false;
}
}
return true;
}
} // namespace
Maybe<std::string> DebugEvaluateImpl(
Vector<const byte> snippet, Handle<WasmInstanceObject> debuggee_instance,
WasmInterpreter::FramePtr frame) {
StandardFrame* frame) {
Isolate* isolate = debuggee_instance->GetIsolate();
HandleScope handle_scope(isolate);
WasmEngine* engine = isolate->wasm_engine();
......@@ -207,7 +331,7 @@ Maybe<std::string> DebugEvaluateImpl(
}
// Set up imports.
DebugEvaluatorProxy proxy(isolate);
DebugEvaluatorProxy proxy(isolate, frame);
Handle<JSObject> imports = proxy.CreateImports();
// Instantiate Module.
......@@ -262,9 +386,9 @@ Maybe<std::string> DebugEvaluateImpl(
MaybeHandle<String> DebugEvaluate(Vector<const byte> snippet,
Handle<WasmInstanceObject> debuggee_instance,
WasmInterpreter::FramePtr frame) {
StandardFrame* frame) {
Maybe<std::string> result =
DebugEvaluateImpl(snippet, debuggee_instance, std::move(frame));
DebugEvaluateImpl(snippet, debuggee_instance, frame);
if (result.IsNothing()) return {};
std::string result_str = result.ToChecked();
return V8String(debuggee_instance->GetIsolate(), result_str.c_str());
......
......@@ -16,7 +16,7 @@ namespace wasm {
MaybeHandle<String> V8_EXPORT_PRIVATE DebugEvaluate(
Vector<const byte> snippet, Handle<WasmInstanceObject> debuggee_instance,
WasmInterpreter::FramePtr frame);
StandardFrame* frame);
} // namespace wasm
} // namespace internal
......
......@@ -24,6 +24,7 @@
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-value.h"
#include "src/zone/accounting-allocator.h"
namespace v8 {
......@@ -548,6 +549,17 @@ class DebugInfoImpl {
explicit DebugInfoImpl(NativeModule* native_module)
: native_module_(native_module) {}
WasmValue GetLocalValue(int local, Isolate* isolate, Address pc, Address fp,
Address debug_break_fp) {
wasm::WasmCodeRefScope wasm_code_ref_scope;
wasm::WasmCode* code =
isolate->wasm_engine()->code_manager()->LookupCode(pc);
auto* debug_side_table = GetDebugSideTable(code, isolate->allocator());
int pc_offset = static_cast<int>(pc - code->instruction_start());
auto* debug_side_table_entry = debug_side_table->GetEntry(pc_offset);
return GetValue(debug_side_table_entry, local, fp, debug_break_fp);
}
Handle<JSObject> GetLocalScopeObject(Isolate* isolate, Address pc, Address fp,
Address debug_break_fp) {
Handle<JSObject> local_scope_object =
......@@ -957,6 +969,11 @@ DebugInfo::DebugInfo(NativeModule* native_module)
DebugInfo::~DebugInfo() = default;
WasmValue DebugInfo::GetLocalValue(int local, Isolate* isolate, Address pc,
Address fp, Address debug_break_fp) {
return impl_->GetLocalValue(local, isolate, pc, fp, debug_break_fp);
}
Handle<JSObject> DebugInfo::GetLocalScopeObject(Isolate* isolate, Address pc,
Address fp,
Address debug_break_fp) {
......
......@@ -33,6 +33,7 @@ class LocalNames;
class NativeModule;
class WasmCode;
class WireBytesRef;
class WasmValue;
// Side table storing information used to inspect Liftoff frames at runtime.
// This table is only created on demand for debugging, so it is not optimized
......@@ -143,6 +144,9 @@ class DebugInfo {
// {fp} is the frame pointer of the Liftoff frame, {debug_break_fp} that of
// the {WasmDebugBreak} frame (if any).
WasmValue GetLocalValue(int local, Isolate*, Address pc, Address fp,
Address debug_break_fp);
Handle<JSObject> GetLocalScopeObject(Isolate*, Address pc, Address fp,
Address debug_break_fp);
......
......@@ -2,21 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/codegen/signature.h"
#include "src/wasm/wasm-module-builder.h"
#include "src/base/memory.h"
#include "src/codegen/signature.h"
#include "src/handles/handles.h"
#include "src/init/v8.h"
#include "src/objects/objects-inl.h"
#include "src/zone/zone-containers.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/leb-helper.h"
#include "src/wasm/wasm-constants.h"
#include "src/wasm/wasm-module-builder.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/base/memory.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
......@@ -336,16 +334,17 @@ uint32_t WasmModuleBuilder::AddTable(ValueType type, uint32_t min_size,
return static_cast<uint32_t>(tables_.size() - 1);
}
uint32_t WasmModuleBuilder::AddImport(Vector<const char> name,
FunctionSig* sig) {
uint32_t WasmModuleBuilder::AddImport(Vector<const char> name, FunctionSig* sig,
Vector<const char> module) {
DCHECK(adding_imports_allowed_);
function_imports_.push_back({name, AddSignature(sig)});
function_imports_.push_back({module, name, AddSignature(sig)});
return static_cast<uint32_t>(function_imports_.size() - 1);
}
uint32_t WasmModuleBuilder::AddGlobalImport(Vector<const char> name,
ValueType type, bool mutability) {
global_imports_.push_back({name, type.value_type_code(), mutability});
ValueType type, bool mutability,
Vector<const char> module) {
global_imports_.push_back({module, name, type.value_type_code(), mutability});
return static_cast<uint32_t>(global_imports_.size() - 1);
}
......@@ -424,14 +423,14 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer* buffer) const {
size_t start = EmitSection(kImportSectionCode, buffer);
buffer->write_size(global_imports_.size() + function_imports_.size());
for (auto import : global_imports_) {
buffer->write_u32v(0); // module name (length)
buffer->write_string(import.module); // module name
buffer->write_string(import.name); // field name
buffer->write_u8(kExternalGlobal);
buffer->write_u8(import.type_code);
buffer->write_u8(import.mutability ? 1 : 0);
}
for (auto import : function_imports_) {
buffer->write_u32v(0); // module name (length)
buffer->write_string(import.module); // module name
buffer->write_string(import.name); // field name
buffer->write_u8(kExternalFunction);
buffer->write_u32v(import.sig_index);
......
......@@ -5,16 +5,15 @@
#ifndef V8_WASM_WASM_MODULE_BUILDER_H_
#define V8_WASM_WASM_MODULE_BUILDER_H_
#include "src/codegen/signature.h"
#include "src/zone/zone-containers.h"
#include "src/base/memory.h"
#include "src/codegen/signature.h"
#include "src/utils/vector.h"
#include "src/wasm/leb-helper.h"
#include "src/wasm/local-decl-encoder.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/wasm-result.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
......@@ -233,12 +232,13 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
explicit WasmModuleBuilder(Zone* zone);
// Building methods.
uint32_t AddImport(Vector<const char> name, FunctionSig* sig);
uint32_t AddImport(Vector<const char> name, FunctionSig* sig,
Vector<const char> module = {});
WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr);
uint32_t AddGlobal(ValueType type, bool mutability = true,
const WasmInitExpr& init = WasmInitExpr());
uint32_t AddGlobalImport(Vector<const char> name, ValueType type,
bool mutability);
bool mutability, Vector<const char> module = {});
void AddDataSegment(const byte* data, uint32_t size, uint32_t dest);
uint32_t AddSignature(FunctionSig* sig);
// In the current implementation, it's supported to have uninitialized slots
......@@ -272,11 +272,13 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
private:
struct WasmFunctionImport {
Vector<const char> module;
Vector<const char> name;
uint32_t sig_index;
};
struct WasmGlobalImport {
Vector<const char> module;
Vector<const char> name;
ValueTypeCode type_code;
bool mutability;
......
......@@ -43,14 +43,20 @@ namespace {
template <typename... FunctionArgsT>
class TestCode {
public:
TestCode(WasmRunnerBase* runner, std::initializer_list<byte> code)
: compiler_(&runner->NewFunction<FunctionArgsT...>()), code_(code) {
TestCode(WasmRunnerBase* runner, std::initializer_list<byte> code,
std::initializer_list<ValueType::Kind> locals = {})
: compiler_(&runner->NewFunction<FunctionArgsT...>()),
code_(code),
locals_(static_cast<uint32_t>(locals.size())) {
for (ValueType::Kind T : locals) {
compiler_->AllocateLocal(ValueType(T));
}
compiler_->Build(code.begin(), code.end());
}
Handle<BreakPoint> BreakOnReturn(WasmRunnerBase* runner) {
runner->TierDown();
uint32_t return_offset_in_function = FindReturn();
uint32_t return_offset_in_function = locals_ + FindReturn();
int function_index = compiler_->function_index();
int function_offset =
......@@ -98,6 +104,7 @@ class TestCode {
WasmFunctionCompiler* compiler_;
std::vector<byte> code_;
uint32_t locals_;
};
class WasmEvaluatorBuilder {
......@@ -108,6 +115,9 @@ class WasmEvaluatorBuilder {
: zone_(&allocator_, ZONE_NAME), builder_(&zone_) {
get_memory_function_index = AddImport<void, uint32_t, uint32_t, uint32_t>(
CStrVector("__getMemory"));
get_local_function_index =
AddImport<void, uint32_t, uint32_t>(CStrVector("__getLocal"));
sbrk_function_index = AddImport<uint32_t, uint32_t>(CStrVector("__sbrk"));
wasm_format_function =
builder_.AddFunction(WasmRunnerBase::CreateSig<uint32_t>(&zone_));
wasm_format_function->SetName(CStrVector("wasm_format"));
......@@ -119,7 +129,8 @@ class WasmEvaluatorBuilder {
template <typename ReturnT, typename... ArgTs>
uint32_t AddImport(Vector<const char> name) {
return builder_.AddImport(
name, WasmRunnerBase::CreateSig<ReturnT, ArgTs...>(&zone_));
name, WasmRunnerBase::CreateSig<ReturnT, ArgTs...>(&zone_),
CStrVector("env"));
}
void push_back(std::initializer_list<byte> code) {
......@@ -127,6 +138,16 @@ class WasmEvaluatorBuilder {
static_cast<uint32_t>(code.size()));
}
void CallSbrk(std::initializer_list<byte> args) {
push_back(args);
push_back({WASM_CALL_FUNCTION0(sbrk_function_index)});
}
void CallGetLocal(std::initializer_list<byte> args) {
push_back(args);
push_back({WASM_CALL_FUNCTION0(get_local_function_index)});
}
void CallGetMemory(std::initializer_list<byte> args) {
push_back(args);
push_back({WASM_CALL_FUNCTION0(get_memory_function_index)});
......@@ -143,6 +164,8 @@ class WasmEvaluatorBuilder {
Zone zone_;
WasmModuleBuilder builder_;
uint32_t get_memory_function_index = 0;
uint32_t get_local_function_index = 0;
uint32_t sbrk_function_index = 0;
WasmFunctionBuilder* wasm_format_function = nullptr;
};
......@@ -192,12 +215,10 @@ class WasmBreakHandler : public debug::DebugDelegate {
FrameSummary::WasmInterpretedFrameSummary summary =
FrameSummary::GetTop(frame_it.frame()).AsWasmInterpreted();
Handle<WasmInstanceObject> instance = summary.wasm_instance();
WasmInterpreter::FramePtr frame =
instance->debug_info().GetInterpretedFrame(frame_it.frame()->fp(), 0);
MaybeHandle<String> result_handle = v8::internal::wasm::DebugEvaluate(
{evaluator_bytes_.begin(), evaluator_bytes_.size()}, instance,
std::move(frame));
frame_it.frame());
Maybe<std::string> error_message = GetPendingExceptionAsString();
Maybe<std::string> result_message =
......@@ -218,7 +239,7 @@ WASM_COMPILED_EXEC_TEST(WasmDebugEvaluate_CompileFailed) {
code.BreakOnReturn(&runner);
WasmEvaluatorBuilder evaluator(execution_tier);
// Create a module that doesn't compile by missing the END bytecode
// Create a module that doesn't compile by missing the END bytecode.
evaluator.push_back({WASM_RETURN1(WASM_I32V_1(33))});
Isolate* isolate = runner.main_isolate();
......@@ -262,11 +283,12 @@ WASM_COMPILED_EXEC_TEST(WasmDebugEvaluate_ExecuteFailed_SEGV) {
TestCode<int> code(&runner, {WASM_RETURN1(WASM_I32V_1(32))});
// Create a module that doesn't compile by missing the END bytecode
WasmEvaluatorBuilder evaluator(execution_tier);
// Use a max memory size of 2 here to verify the precondition for the
// GrowMemory test below.
WasmEvaluatorBuilder evaluator(execution_tier, 1, 2);
code.BreakOnReturn(&runner);
// Load 1 byte from an address that's too high
// Load 1 byte from an address that's too high.
evaluator.CallGetMemory(
{WASM_I32V_1(32), WASM_I32V_1(1), WASM_I32V_3((1 << 16) + 1)});
evaluator.push_back({WASM_RETURN1(WASM_I32V_1(33)), WASM_END});
......@@ -283,6 +305,34 @@ WASM_COMPILED_EXEC_TEST(WasmDebugEvaluate_ExecuteFailed_SEGV) {
std::string::npos);
}
WASM_COMPILED_EXEC_TEST(WasmDebugEvaluate_GrowMemory) {
WasmRunner<int> runner(execution_tier);
runner.builder().AddMemoryElems<int32_t>(64);
TestCode<int> code(
&runner,
{WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(32), WASM_I32V_2('A')),
WASM_RETURN1(WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(32)))});
code.BreakOnReturn(&runner);
WasmEvaluatorBuilder evaluator(execution_tier, 1, 2);
// Grow the memory.
evaluator.CallSbrk({WASM_I32V_1(1)});
// Load 1 byte from an address that's too high for the default memory.
evaluator.CallGetMemory(
{WASM_I32V_1(32), WASM_I32V_1(1), WASM_I32V_3((1 << 16) + 1)});
evaluator.push_back({WASM_RETURN1(WASM_I32V_3((1 << 16) + 1)), WASM_END});
Isolate* isolate = runner.main_isolate();
WasmBreakHandler break_handler(isolate, evaluator.bytes());
CHECK(!code.Run(&runner).is_null());
WasmBreakHandler::EvaluationResult result =
break_handler.result().ToChecked();
CHECK(result.error.IsNothing());
CHECK_EQ(result.result.ToChecked(), "A");
}
WASM_COMPILED_EXEC_TEST(WasmDebugEvaluate_LinearMemory) {
WasmRunner<int> runner(execution_tier);
runner.builder().AddMemoryElems<int32_t>(64);
......@@ -309,6 +359,30 @@ WASM_COMPILED_EXEC_TEST(WasmDebugEvaluate_LinearMemory) {
CHECK_EQ(result.result.ToChecked(), "A");
}
WASM_COMPILED_EXEC_TEST(WasmDebugEvaluate_Locals) {
WasmRunner<int> runner(execution_tier);
runner.builder().AddMemoryElems<int32_t>(64);
TestCode<int> code(
&runner,
{WASM_SET_LOCAL(0, WASM_I32V_2('A')), WASM_RETURN1(WASM_GET_LOCAL(0))},
{ValueType::kI32});
code.BreakOnReturn(&runner);
WasmEvaluatorBuilder evaluator(execution_tier);
evaluator.CallGetLocal({WASM_I32V_1(0), WASM_I32V_1(33)});
evaluator.push_back({WASM_RETURN1(WASM_I32V_1(33)), WASM_END});
Isolate* isolate = runner.main_isolate();
WasmBreakHandler break_handler(isolate, evaluator.bytes());
CHECK(!code.Run(&runner).is_null());
WasmBreakHandler::EvaluationResult result =
break_handler.result().ToChecked();
CHECK(result.error.IsNothing());
CHECK_EQ(result.result.ToChecked(), "A");
}
} // namespace
} // namespace wasm
} // namespace internal
......
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