Commit 28b0df66 authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

[v8windbg] Display node_id for compiler node

For better Turbofan debugging.

Change-Id: I79010632b1355e2a4c1a017d64db5ccbb97fa776
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2252539
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarSeth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#68469}
parent 895c52dd
......@@ -133,6 +133,15 @@ HRESULT UnboxULong64(IModelObject* object, ULONG64* value, bool convert) {
return S_OK;
}
HRESULT GetInt32(IDebugHostConstant* object, int* value) {
variant_t variant;
RETURN_IF_FAIL(object->GetValue(&variant));
if (variant.vt != VT_I4) return E_FAIL;
*value = variant.ullVal;
return S_OK;
}
HRESULT CreateInt32(int value, IModelObject** pp_int) {
HRESULT hr = S_OK;
*pp_int = nullptr;
......
......@@ -55,6 +55,8 @@ HRESULT CreateULong64(ULONG64 value, IModelObject** pp_int);
HRESULT UnboxULong64(IModelObject* object, ULONG64* value,
bool convert = false);
HRESULT GetInt32(IDebugHostConstant* object, int* value);
HRESULT CreateInt32(int value, IModelObject** pp_int);
HRESULT CreateUInt32(uint32_t value, IModelObject** pp_int);
......
......@@ -585,6 +585,54 @@ IFACEMETHODIMP V8LocalValueProperty::SetValue(
return E_NOTIMPL;
}
IFACEMETHODIMP V8InternalCompilerNodeIdProperty::GetValue(
PCWSTR pwsz_key, IModelObject* p_v8_compiler_node_instance,
IModelObject** pp_value) noexcept {
WRL::ComPtr<IModelObject> sp_bit_field;
RETURN_IF_FAIL(p_v8_compiler_node_instance->GetRawValue(
SymbolKind::SymbolField, L"bit_field_", RawSearchNone, &sp_bit_field));
uint64_t bit_field_value;
RETURN_IF_FAIL(
UnboxULong64(sp_bit_field.Get(), &bit_field_value, true /*convert*/));
WRL::ComPtr<IDebugHostContext> sp_host_context;
RETURN_IF_FAIL(p_v8_compiler_node_instance->GetContext(&sp_host_context));
WRL::ComPtr<IDebugHostType> sp_id_field_type;
RETURN_IF_FAIL(Extension::Current()
->GetV8Module(sp_host_context)
->FindTypeByName(L"v8::internal::compiler::Node::IdField",
&sp_id_field_type));
// Get 2nd template parameter as 24 in class.
// v8::base::BitField<v8::internal::compiler::NodeId, 0, 24>.
bool is_generic;
RETURN_IF_FAIL(sp_id_field_type->IsGeneric(&is_generic));
if (!is_generic) return E_FAIL;
WRL::ComPtr<IDebugHostSymbol> sp_k_size_arg;
RETURN_IF_FAIL(sp_id_field_type->GetGenericArgumentAt(2, &sp_k_size_arg));
WRL::ComPtr<IDebugHostConstant> sp_k_size_constant;
RETURN_IF_FAIL(sp_k_size_arg.As(&sp_k_size_constant));
int k_size;
RETURN_IF_FAIL(GetInt32(sp_k_size_constant.Get(), &k_size));
// Compute node_id.
uint32_t node_id = bit_field_value & (0xFFFFFFFF >> k_size);
RETURN_IF_FAIL(CreateUInt32(node_id, pp_value));
return S_OK;
}
IFACEMETHODIMP V8InternalCompilerNodeIdProperty::SetValue(
PCWSTR /*pwsz_key*/, IModelObject* /*p_process_instance*/,
IModelObject* /*p_value*/) noexcept {
return E_NOTIMPL;
}
constexpr wchar_t usage[] =
LR"(Invalid arguments.
First argument should be a uint64 representing the tagged value to investigate.
......
......@@ -245,6 +245,22 @@ class V8LocalValueProperty
IModelObject* /*p_value*/);
};
// The implemention of the "NodeId" getter for v8::internal::compiler::Node
// type.
class V8InternalCompilerNodeIdProperty
: public WRL::RuntimeClass<
WRL::RuntimeClassFlags<WRL::RuntimeClassType::ClassicCom>,
IModelPropertyAccessor> {
public:
IFACEMETHOD(GetValue)
(PCWSTR pwsz_key, IModelObject* p_v8_object_instance,
IModelObject** pp_value);
IFACEMETHOD(SetValue)
(PCWSTR /*pwsz_key*/, IModelObject* /*p_process_instance*/,
IModelObject* /*p_value*/);
};
// A way that someone can directly inspect a tagged value, even if that value
// isn't in memory (from a register, or the user's imagination, etc.).
class InspectV8ObjectMethod
......
......@@ -215,7 +215,8 @@ HRESULT Extension::Initialize() {
&sp_object_type_signature));
RETURN_IF_FAIL(sp_data_model_manager->RegisterModelForTypeSignature(
sp_object_type_signature.Get(), sp_object_data_model_.Get()));
registered_object_types_.push_back(sp_object_type_signature);
registered_types_.push_back(
{sp_object_type_signature.Get(), sp_object_data_model_.Get()});
}
// Create an instance of the DataModel parent for custom iterable fields.
......@@ -244,7 +245,7 @@ HRESULT Extension::Initialize() {
sp_debug_host_symbols->CreateTypeSignature(name, nullptr, &signature));
RETURN_IF_FAIL(sp_data_model_manager->RegisterModelForTypeSignature(
signature.Get(), sp_local_data_model_.Get()));
registered_handle_types_.push_back(signature);
registered_types_.push_back({signature.Get(), sp_local_data_model_.Get()});
}
// Add the 'Value' property to the parent model.
......@@ -279,6 +280,32 @@ HRESULT Extension::Initialize() {
RETURN_IF_FAIL(OverrideLocalsGetter(stack_frame.Get(), L"Parameters",
/*is_parameters=*/true));
/* v8::internal::compiler::Node */
// Create an instance of the DataModel parent class for
// v8::internal::compiler::Node type.
auto compiler_node_data_model{WRL::Make<V8LocalDataModel>()};
RETURN_IF_FAIL(sp_data_model_manager->CreateDataModelObject(
compiler_node_data_model.Get(), &sp_compiler_node_data_model_));
// Register that parent model for v8::internal::compiler::Node.
const wchar_t* compiler_node_class_name = L"v8::internal::compiler::Node";
WRL::ComPtr<IDebugHostTypeSignature> compiler_node_class_signature;
RETURN_IF_FAIL(sp_debug_host_symbols->CreateTypeSignature(
compiler_node_class_name, nullptr, &compiler_node_class_signature));
RETURN_IF_FAIL(sp_data_model_manager->RegisterModelForTypeSignature(
compiler_node_class_signature.Get(), sp_compiler_node_data_model_.Get()));
registered_types_.push_back({compiler_node_class_signature.Get(),
sp_compiler_node_data_model_.Get()});
// Add the 'node_id' property to the parent model.
auto node_id_property{WRL::Make<V8InternalCompilerNodeIdProperty>()};
WRL::ComPtr<IModelObject> sp_node_id_property_model;
RETURN_IF_FAIL(CreateProperty(sp_data_model_manager.Get(),
node_id_property.Get(),
&sp_node_id_property_model));
RETURN_IF_FAIL(sp_compiler_node_data_model_->SetKey(
L"node_id", sp_node_id_property_model.Get(), nullptr));
return S_OK;
}
......@@ -318,18 +345,24 @@ Extension::PropertyOverride::PropertyOverride(const PropertyOverride&) =
Extension::PropertyOverride& Extension::PropertyOverride::operator=(
const PropertyOverride&) = default;
Extension::RegistrationType::RegistrationType() = default;
Extension::RegistrationType::RegistrationType(
IDebugHostTypeSignature* sp_signature, IModelObject* sp_data_model)
: sp_signature(sp_signature), sp_data_model(sp_data_model) {}
Extension::RegistrationType::~RegistrationType() = default;
Extension::RegistrationType::RegistrationType(const RegistrationType&) =
default;
Extension::RegistrationType& Extension::RegistrationType::operator=(
const RegistrationType&) = default;
Extension::~Extension() {
sp_debug_host_extensibility->DestroyFunctionAlias(pcur_isolate);
sp_debug_host_extensibility->DestroyFunctionAlias(plist_chunks);
sp_debug_host_extensibility->DestroyFunctionAlias(pv8_object);
for (const auto& registered : registered_object_types_) {
sp_data_model_manager->UnregisterModelForTypeSignature(
sp_object_data_model_.Get(), registered.Get());
}
for (const auto& registered : registered_handle_types_) {
for (const auto& registered : registered_types_) {
sp_data_model_manager->UnregisterModelForTypeSignature(
sp_local_data_model_.Get(), registered.Get());
registered.sp_data_model.Get(), registered.sp_signature.Get());
}
for (const auto& override : overridden_properties_) {
......
......@@ -62,20 +62,31 @@ class Extension {
WRL::ComPtr<IKeyStore> original_metadata;
};
struct RegistrationType {
RegistrationType();
RegistrationType(IDebugHostTypeSignature* sp_signature,
IModelObject* sp_data_model);
~RegistrationType();
RegistrationType(const RegistrationType&);
RegistrationType& operator=(const RegistrationType&);
WRL::ComPtr<IDebugHostTypeSignature> sp_signature;
WRL::ComPtr<IModelObject> sp_data_model;
};
static std::unique_ptr<Extension> current_extension_;
WRL::ComPtr<IModelObject> sp_object_data_model_;
WRL::ComPtr<IModelObject> sp_local_data_model_;
WRL::ComPtr<IModelObject> sp_compiler_node_data_model_;
WRL::ComPtr<IModelObject> sp_indexed_field_model_;
WRL::ComPtr<IDebugHostModule> sp_v8_module_;
std::unordered_map<std::u16string, WRL::ComPtr<IDebugHostType>>
cached_v8_module_types_;
std::vector<WRL::ComPtr<IDebugHostTypeSignature>> registered_object_types_;
std::vector<WRL::ComPtr<IDebugHostTypeSignature>> registered_handle_types_;
std::vector<RegistrationType> registered_types_;
std::vector<PropertyOverride> overridden_properties_;
WRL::ComPtr<IDebugHostContext> sp_v8_module_ctx_;
ULONG v8_module_proc_id_;
};
#endif // V8_TOOLS_V8WINDBG_SRC_V8WINDBG_EXTENSION_H_
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