#include "src/debug/debug-wasm-objects.h"
#include <optional>
#include "src/api/api-inl.h"
#include "src/api/api-natives.h"
#include "src/base/strings.h"
#include "src/common/globals.h"
#include "src/debug/debug-wasm-objects-inl.h"
#include "src/execution/frames-inl.h"
#include "src/objects/allocation-site.h"
#include "src/objects/property-descriptor.h"
#include "src/wasm/names-provider.h"
#include "src/wasm/string-builder.h"
#include "src/wasm/wasm-debug.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-value.h"
namespace v8 {
namespace internal {
namespace {
StringBuilder;
Handle<String> ToInternalString(StringBuilder& sb, Isolate* isolate) { … }
enum DebugProxyId { … };
constexpr int kWasmValueMapIndex = …;
constexpr int kNumDebugMaps = …;
Handle<FixedArray> GetOrCreateDebugMaps(Isolate* isolate) { … }
Handle<Map> GetOrCreateDebugProxyMap(
Isolate* isolate, DebugProxyId id,
v8::Local<v8::FunctionTemplate> (*create_template_fn)(v8::Isolate*),
bool make_non_extensible = true) { … }
template <typename T, DebugProxyId id, typename Provider>
struct IndexedDebugProxy { … };
template <typename T, DebugProxyId id, typename Provider = WasmInstanceObject>
struct NamedDebugProxy : IndexedDebugProxy<T, id, Provider> { … };
struct FunctionsProxy : NamedDebugProxy<FunctionsProxy, kFunctionsProxy> { … };
struct GlobalsProxy : NamedDebugProxy<GlobalsProxy, kGlobalsProxy> { … };
struct MemoriesProxy : NamedDebugProxy<MemoriesProxy, kMemoriesProxy> { … };
struct TablesProxy : NamedDebugProxy<TablesProxy, kTablesProxy> { … };
struct LocalsProxy : NamedDebugProxy<LocalsProxy, kLocalsProxy, FixedArray> { … };
struct StackProxy : IndexedDebugProxy<StackProxy, kStackProxy, FixedArray> { … };
Handle<FixedArray> GetOrCreateInstanceProxyCache(
Isolate* isolate, Handle<WasmInstanceObject> instance) { … }
template <typename Proxy>
Handle<JSObject> GetOrCreateInstanceProxy(Isolate* isolate,
Handle<WasmInstanceObject> instance) { … }
class ContextProxyPrototype { … };
class ContextProxy { … };
class DebugWasmScopeIterator final : public debug::ScopeIterator { … };
#if V8_ENABLE_DRUMBRAKE
class DebugWasmInterpreterScopeIterator final : public debug::ScopeIterator {
public:
explicit DebugWasmInterpreterScopeIterator(WasmInterpreterEntryFrame* frame)
: frame_(frame), type_(debug::ScopeIterator::ScopeTypeModule) {
}
bool Done() override { return type_ == ScopeTypeWith; }
void Advance() override {
DCHECK(!Done());
switch (type_) {
case ScopeTypeModule:
type_ = debug::ScopeIterator::ScopeTypeWith;
break;
case ScopeTypeWasmExpressionStack:
case ScopeTypeLocal:
default:
UNREACHABLE();
}
}
ScopeType GetType() override { return type_; }
v8::Local<v8::Object> GetObject() override {
Isolate* isolate = frame_->isolate();
switch (type_) {
case debug::ScopeIterator::ScopeTypeModule: {
Handle<WasmInstanceObject> instance(frame_->wasm_instance(), isolate);
Handle<JSObject> object =
isolate->factory()->NewSlowJSObjectWithNullProto();
JSObject::AddProperty(isolate, object, "instance", instance, FROZEN);
Handle<JSObject> module_object(instance->module_object(), isolate);
JSObject::AddProperty(isolate, object, "module", module_object, FROZEN);
if (FunctionsProxy::Count(isolate, instance) != 0) {
JSObject::AddProperty(
isolate, object, "functions",
GetOrCreateInstanceProxy<FunctionsProxy>(isolate, instance),
FROZEN);
}
if (GlobalsProxy::Count(isolate, instance) != 0) {
JSObject::AddProperty(
isolate, object, "globals",
GetOrCreateInstanceProxy<GlobalsProxy>(isolate, instance),
FROZEN);
}
if (MemoriesProxy::Count(isolate, instance) != 0) {
JSObject::AddProperty(
isolate, object, "memories",
GetOrCreateInstanceProxy<MemoriesProxy>(isolate, instance),
FROZEN);
}
if (TablesProxy::Count(isolate, instance) != 0) {
JSObject::AddProperty(
isolate, object, "tables",
GetOrCreateInstanceProxy<TablesProxy>(isolate, instance), FROZEN);
}
return Utils::ToLocal(object);
}
case debug::ScopeIterator::ScopeTypeLocal:
case debug::ScopeIterator::ScopeTypeWasmExpressionStack:
default:
UNREACHABLE();
}
}
v8::Local<v8::Value> GetFunctionDebugName() override {
return Utils::ToLocal(frame_->isolate()->factory()->empty_string());
}
int GetScriptId() override { return -1; }
bool HasLocationInfo() override { return false; }
debug::Location GetStartLocation() override { return {}; }
debug::Location GetEndLocation() override { return {}; }
bool SetVariableValue(v8::Local<v8::String> name,
v8::Local<v8::Value> value) override {
return false;
}
private:
WasmInterpreterEntryFrame* const frame_;
ScopeType type_;
};
#endif
Handle<String> WasmSimd128ToString(Isolate* isolate, Simd128 s128) { … }
Handle<String> GetRefTypeName(Isolate* isolate, wasm::ValueType type,
wasm::NativeModule* module) { … }
Handle<String> GetRefTypeName(Isolate* isolate, wasm::ValueType type,
Handle<WasmModuleObject> module_object) { … }
}
Handle<WasmValueObject> WasmValueObject::New(Isolate* isolate,
DirectHandle<String> type,
DirectHandle<Object> value) { … }
struct StructProxy : NamedDebugProxy<StructProxy, kStructProxy, FixedArray> { … };
struct ArrayProxy : IndexedDebugProxy<ArrayProxy, kArrayProxy, FixedArray> { … };
Handle<WasmValueObject> WasmValueObject::New(
Isolate* isolate, const wasm::WasmValue& value,
Handle<WasmModuleObject> module_object) { … }
Handle<JSObject> GetWasmDebugProxy(WasmFrame* frame) { … }
std::unique_ptr<debug::ScopeIterator> GetWasmScopeIterator(WasmFrame* frame) { … }
#if V8_ENABLE_DRUMBRAKE
std::unique_ptr<debug::ScopeIterator> GetWasmInterpreterScopeIterator(
WasmInterpreterEntryFrame* frame) {
return std::make_unique<DebugWasmInterpreterScopeIterator>(frame);
}
#endif
Handle<String> GetWasmFunctionDebugName(
Isolate* isolate, DirectHandle<WasmTrustedInstanceData> instance_data,
uint32_t func_index) { … }
Handle<ArrayList> AddWasmInstanceObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result,
Handle<WasmInstanceObject> instance) { … }
Handle<ArrayList> AddWasmModuleObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result,
DirectHandle<WasmModuleObject> module_object) { … }
Handle<ArrayList> AddWasmTableObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result,
DirectHandle<WasmTableObject> table) { … }
}
}