Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

75
deps/v8/tools/v8windbg/base/dbgext.cc vendored Normal file
View File

@ -0,0 +1,75 @@
// Copyright 2020 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.
#include "tools/v8windbg/base/dbgext.h"
#include <crtdbg.h>
#include <wrl/module.h>
#include "tools/v8windbg/base/utilities.h"
// See
// https://docs.microsoft.com/en-us/visualstudio/debugger/crt-debugging-techniques
// for the memory leak and debugger reporting macros used from <crtdbg.h>
_CrtMemState mem_old, mem_new, mem_diff;
int original_crt_dbg_flag = 0;
WRL::ComPtr<IDataModelManager> sp_data_model_manager;
WRL::ComPtr<IDebugHost> sp_debug_host;
WRL::ComPtr<IDebugControl5> sp_debug_control;
WRL::ComPtr<IDebugHostMemory2> sp_debug_host_memory;
WRL::ComPtr<IDebugHostSymbols> sp_debug_host_symbols;
WRL::ComPtr<IDebugHostExtensibility> sp_debug_host_extensibility;
extern "C" {
HRESULT
__stdcall DebugExtensionInitialize(PULONG /*pVersion*/, PULONG /*pFlags*/) {
original_crt_dbg_flag = _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF);
_CrtMemCheckpoint(&mem_old);
WRL::ComPtr<IDebugClient> sp_debug_client;
WRL::ComPtr<IHostDataModelAccess> sp_data_model_access;
RETURN_IF_FAIL(DebugCreate(__uuidof(IDebugClient), &sp_debug_client));
RETURN_IF_FAIL(sp_debug_client.As(&sp_data_model_access));
RETURN_IF_FAIL(sp_debug_client.As(&sp_debug_control));
RETURN_IF_FAIL(sp_data_model_access->GetDataModel(&sp_data_model_manager,
&sp_debug_host));
RETURN_IF_FAIL(sp_debug_host.As(&sp_debug_host_memory));
RETURN_IF_FAIL(sp_debug_host.As(&sp_debug_host_symbols));
RETURN_IF_FAIL(sp_debug_host.As(&sp_debug_host_extensibility));
return CreateExtension();
}
void __stdcall DebugExtensionUninitialize() {
DestroyExtension();
sp_debug_host = nullptr;
sp_data_model_manager = nullptr;
sp_debug_host_memory = nullptr;
sp_debug_host_symbols = nullptr;
sp_debug_host_extensibility = nullptr;
_CrtMemCheckpoint(&mem_new);
if (_CrtMemDifference(&mem_diff, &mem_old, &mem_new)) {
_CrtMemDumpStatistics(&mem_diff);
}
_CrtSetDbgFlag(original_crt_dbg_flag);
}
HRESULT __stdcall DebugExtensionCanUnload(void) {
if (!WRL::Module<WRL::InProc>::GetModule().Terminate()) {
_RPTF0(_CRT_WARN, "Failed to unload WRL\n");
return S_FALSE;
}
return S_OK;
}
void __stdcall DebugExtensionUnload() { return; }
} // extern "C"

View File

@ -0,0 +1,5 @@
EXPORTS
DebugExtensionInitialize
DebugExtensionUninitialize
DebugExtensionCanUnload
DebugExtensionUnload

37
deps/v8/tools/v8windbg/base/dbgext.h vendored Normal file
View File

@ -0,0 +1,37 @@
// Copyright 2020 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.
#ifndef V8_TOOLS_V8WINDBG_BASE_DBGEXT_H_
#define V8_TOOLS_V8WINDBG_BASE_DBGEXT_H_
#if !defined(UNICODE) || !defined(_UNICODE)
#error Unicode not defined
#endif
// Must be included before DbgModel.h.
#include <new>
#include <DbgEng.h>
#include <DbgModel.h>
#include <Windows.h>
#include <crtdbg.h>
#include <wrl/client.h>
#include <string>
namespace WRL = Microsoft::WRL;
// Globals for use throughout the extension. (Populated on load).
extern WRL::ComPtr<IDataModelManager> sp_data_model_manager;
extern WRL::ComPtr<IDebugHost> sp_debug_host;
extern WRL::ComPtr<IDebugControl5> sp_debug_control;
extern WRL::ComPtr<IDebugHostMemory2> sp_debug_host_memory;
extern WRL::ComPtr<IDebugHostSymbols> sp_debug_host_symbols;
extern WRL::ComPtr<IDebugHostExtensibility> sp_debug_host_extensibility;
// To be implemented by the custom extension code. (Called on load).
HRESULT CreateExtension();
void DestroyExtension();
#endif // V8_TOOLS_V8WINDBG_BASE_DBGEXT_H_

255
deps/v8/tools/v8windbg/base/utilities.cc vendored Normal file
View File

@ -0,0 +1,255 @@
// Copyright 2020 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.
#include "tools/v8windbg/base/utilities.h"
#include <comutil.h>
#include <oleauto.h>
#include <vector>
namespace {
HRESULT BoxObject(IDataModelManager* p_manager, IUnknown* p_object,
ModelObjectKind kind, IModelObject** pp_model_object) {
*pp_model_object = nullptr;
VARIANT vt_val;
vt_val.vt = VT_UNKNOWN;
vt_val.punkVal = p_object;
HRESULT hr = p_manager->CreateIntrinsicObject(kind, &vt_val, pp_model_object);
return hr;
}
} // namespace
HRESULT CreateProperty(IDataModelManager* p_manager,
IModelPropertyAccessor* p_property,
IModelObject** pp_property_object) {
return BoxObject(p_manager, p_property, ObjectPropertyAccessor,
pp_property_object);
}
HRESULT CreateMethod(IDataModelManager* p_manager, IModelMethod* p_method,
IModelObject** pp_method_object) {
return BoxObject(p_manager, p_method, ObjectMethod, pp_method_object);
}
HRESULT UnboxProperty(IModelObject* object, IModelPropertyAccessor** result) {
ModelObjectKind kind = (ModelObjectKind)-1;
RETURN_IF_FAIL(object->GetKind(&kind));
if (kind != ObjectPropertyAccessor) return E_FAIL;
_variant_t variant;
RETURN_IF_FAIL(object->GetIntrinsicValue(&variant));
if (variant.vt != VT_UNKNOWN) return E_FAIL;
WRL::ComPtr<IModelPropertyAccessor> accessor;
RETURN_IF_FAIL(WRL::ComPtr<IUnknown>(variant.punkVal).As(&accessor));
*result = accessor.Detach();
return S_OK;
}
HRESULT CreateTypedIntrinsic(uint64_t value, IDebugHostType* type,
IModelObject** result) {
// Figure out what kind of VARIANT we need to make.
IntrinsicKind kind;
VARTYPE carrier;
RETURN_IF_FAIL(type->GetIntrinsicType(&kind, &carrier));
VARIANT vt_val;
switch (carrier) {
case VT_BOOL:
vt_val.boolVal = value ? VARIANT_TRUE : VARIANT_FALSE;
break;
case VT_I1:
vt_val.cVal = static_cast<int8_t>(value);
break;
case VT_UI1:
vt_val.bVal = static_cast<uint8_t>(value);
break;
case VT_I2:
vt_val.iVal = static_cast<int16_t>(value);
break;
case VT_UI2:
vt_val.uiVal = static_cast<uint16_t>(value);
break;
case VT_INT:
vt_val.intVal = static_cast<int>(value);
break;
case VT_UINT:
vt_val.uintVal = static_cast<unsigned int>(value);
break;
case VT_I4:
vt_val.lVal = static_cast<int32_t>(value);
break;
case VT_UI4:
vt_val.ulVal = static_cast<uint32_t>(value);
break;
case VT_INT_PTR:
vt_val.llVal = static_cast<intptr_t>(value);
break;
case VT_UINT_PTR:
vt_val.ullVal = static_cast<uintptr_t>(value);
break;
case VT_I8:
vt_val.llVal = static_cast<int64_t>(value);
break;
case VT_UI8:
vt_val.ullVal = static_cast<uint64_t>(value);
break;
default:
return E_FAIL;
}
vt_val.vt = carrier;
return sp_data_model_manager->CreateTypedIntrinsicObject(&vt_val, type,
result);
}
HRESULT CreateULong64(ULONG64 value, IModelObject** pp_int) {
HRESULT hr = S_OK;
*pp_int = nullptr;
VARIANT vt_val;
vt_val.vt = VT_UI8;
vt_val.ullVal = value;
hr = sp_data_model_manager->CreateIntrinsicObject(ObjectIntrinsic, &vt_val,
pp_int);
return hr;
}
HRESULT UnboxULong64(IModelObject* object, ULONG64* value, bool convert) {
ModelObjectKind kind = (ModelObjectKind)-1;
RETURN_IF_FAIL(object->GetKind(&kind));
if (kind != ObjectIntrinsic) return E_FAIL;
_variant_t variant;
RETURN_IF_FAIL(object->GetIntrinsicValue(&variant));
if (convert) {
RETURN_IF_FAIL(VariantChangeType(&variant, &variant, 0, VT_UI8));
}
if (variant.vt != VT_UI8) return E_FAIL;
*value = variant.ullVal;
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.lVal;
return S_OK;
}
HRESULT CreateInt32(int value, IModelObject** pp_int) {
HRESULT hr = S_OK;
*pp_int = nullptr;
VARIANT vt_val;
vt_val.vt = VT_I4;
vt_val.intVal = value;
hr = sp_data_model_manager->CreateIntrinsicObject(ObjectIntrinsic, &vt_val,
pp_int);
return hr;
}
HRESULT CreateUInt32(uint32_t value, IModelObject** pp_int) {
HRESULT hr = S_OK;
*pp_int = nullptr;
VARIANT vt_val;
vt_val.vt = VT_UI4;
vt_val.uintVal = value;
hr = sp_data_model_manager->CreateIntrinsicObject(ObjectIntrinsic, &vt_val,
pp_int);
return hr;
}
HRESULT CreateBool(bool value, IModelObject** pp_val) {
HRESULT hr = S_OK;
*pp_val = nullptr;
VARIANT vt_val;
vt_val.vt = VT_BOOL;
vt_val.boolVal = value;
hr = sp_data_model_manager->CreateIntrinsicObject(ObjectIntrinsic, &vt_val,
pp_val);
return hr;
}
HRESULT CreateNumber(double value, IModelObject** pp_val) {
HRESULT hr = S_OK;
*pp_val = nullptr;
VARIANT vt_val;
vt_val.vt = VT_R8;
vt_val.dblVal = value;
hr = sp_data_model_manager->CreateIntrinsicObject(ObjectIntrinsic, &vt_val,
pp_val);
return hr;
}
HRESULT CreateString(std::u16string value, IModelObject** pp_val) {
HRESULT hr = S_OK;
*pp_val = nullptr;
VARIANT vt_val;
vt_val.vt = VT_BSTR;
vt_val.bstrVal =
::SysAllocString(reinterpret_cast<const OLECHAR*>(value.c_str()));
hr = sp_data_model_manager->CreateIntrinsicObject(ObjectIntrinsic, &vt_val,
pp_val);
return hr;
}
HRESULT UnboxString(IModelObject* object, BSTR* value) {
ModelObjectKind kind = (ModelObjectKind)-1;
RETURN_IF_FAIL(object->GetKind(&kind));
if (kind != ObjectIntrinsic) return E_FAIL;
_variant_t variant;
RETURN_IF_FAIL(object->GetIntrinsicValue(&variant));
if (variant.vt != VT_BSTR) return E_FAIL;
*value = variant.Detach().bstrVal;
return S_OK;
}
HRESULT GetModelAtIndex(WRL::ComPtr<IModelObject>& sp_parent,
WRL::ComPtr<IModelObject>& sp_index,
IModelObject** p_result) {
WRL::ComPtr<IIndexableConcept> sp_indexable_concept;
RETURN_IF_FAIL(sp_parent->GetConcept(__uuidof(IIndexableConcept),
&sp_indexable_concept, nullptr));
std::vector<IModelObject*> p_indexers{sp_index.Get()};
return sp_indexable_concept->GetAt(sp_parent.Get(), 1, p_indexers.data(),
p_result, nullptr);
}
HRESULT GetCurrentThread(WRL::ComPtr<IDebugHostContext>& sp_host_context,
IModelObject** p_current_thread) {
WRL::ComPtr<IModelObject> sp_boxed_context, sp_root_namespace;
WRL::ComPtr<IModelObject> sp_debugger, sp_sessions, sp_processes, sp_threads;
WRL::ComPtr<IModelObject> sp_curr_session, sp_curr_process;
RETURN_IF_FAIL(BoxObject(sp_data_model_manager.Get(), sp_host_context.Get(),
ObjectContext, &sp_boxed_context));
RETURN_IF_FAIL(sp_data_model_manager->GetRootNamespace(&sp_root_namespace));
RETURN_IF_FAIL(
sp_root_namespace->GetKeyValue(L"Debugger", &sp_debugger, nullptr));
RETURN_IF_FAIL(sp_debugger->GetKeyValue(L"Sessions", &sp_sessions, nullptr));
RETURN_IF_FAIL(
GetModelAtIndex(sp_sessions, sp_boxed_context, &sp_curr_session));
RETURN_IF_FAIL(
sp_curr_session->GetKeyValue(L"Processes", &sp_processes, nullptr));
RETURN_IF_FAIL(
GetModelAtIndex(sp_processes, sp_boxed_context, &sp_curr_process));
RETURN_IF_FAIL(
sp_curr_process->GetKeyValue(L"Threads", &sp_threads, nullptr));
return GetModelAtIndex(sp_threads, sp_boxed_context, p_current_thread);
}

103
deps/v8/tools/v8windbg/base/utilities.h vendored Normal file
View File

@ -0,0 +1,103 @@
// Copyright 2020 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.
#ifndef V8_TOOLS_V8WINDBG_BASE_UTILITIES_H_
#define V8_TOOLS_V8WINDBG_BASE_UTILITIES_H_
#include "tools/v8windbg/base/dbgext.h"
inline const wchar_t* U16ToWChar(const char16_t* p_u16) {
static_assert(sizeof(wchar_t) == sizeof(char16_t), "wrong wchar size");
return reinterpret_cast<const wchar_t*>(p_u16);
}
inline const wchar_t* U16ToWChar(std::u16string& str) {
return U16ToWChar(str.data());
}
#if defined(WIN32)
inline std::u16string ConvertToU16String(std::string utf8_string) {
int len_chars =
::MultiByteToWideChar(CP_UTF8, 0, utf8_string.c_str(), -1, nullptr, 0);
char16_t* p_buff =
static_cast<char16_t*>(malloc(len_chars * sizeof(char16_t)));
// On Windows wchar_t is the same a char16_t
static_assert(sizeof(wchar_t) == sizeof(char16_t), "wrong wchar size");
len_chars =
::MultiByteToWideChar(CP_UTF8, 0, utf8_string.c_str(), -1,
reinterpret_cast<wchar_t*>(p_buff), len_chars);
std::u16string result{p_buff};
free(p_buff);
return result;
}
inline std::string ConvertFromU16String(std::u16string u16string) {
int len_chars =
::WideCharToMultiByte(CP_UTF8, 0, U16ToWChar(u16string.c_str()), -1,
nullptr, 0, nullptr, nullptr);
char* p_buff = static_cast<char*>(malloc(len_chars * sizeof(char)));
len_chars = ::WideCharToMultiByte(CP_UTF8, 0, U16ToWChar(u16string.c_str()),
-1, p_buff, len_chars, nullptr, nullptr);
std::string result{p_buff};
free(p_buff);
return result;
}
#else
#error String encoding conversion must be provided for the target platform.
#endif
HRESULT CreateProperty(IDataModelManager* p_manager,
IModelPropertyAccessor* p_property,
IModelObject** pp_property_object);
HRESULT CreateMethod(IDataModelManager* p_manager, IModelMethod* p_method,
IModelObject** pp_method_object);
HRESULT UnboxProperty(IModelObject* object, IModelPropertyAccessor** result);
HRESULT CreateTypedIntrinsic(uint64_t value, IDebugHostType* type,
IModelObject** result);
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);
HRESULT CreateBool(bool value, IModelObject** pp_val);
HRESULT CreateNumber(double value, IModelObject** pp_val);
HRESULT CreateString(std::u16string value, IModelObject** pp_val);
HRESULT UnboxString(IModelObject* object, BSTR* value);
HRESULT GetModelAtIndex(WRL::ComPtr<IModelObject>& sp_parent,
WRL::ComPtr<IModelObject>& sp_index,
IModelObject** p_result);
HRESULT GetCurrentThread(WRL::ComPtr<IDebugHostContext>& sp_host_context,
IModelObject** p_current_thread);
#define RETURN_IF_FAIL(expression) \
do { \
HRESULT hr = expression; \
if (FAILED(hr)) { \
return hr; \
} \
} while (false)
#endif // V8_TOOLS_V8WINDBG_BASE_UTILITIES_H_