summaryrefslogtreecommitdiff
path: root/deps/v8/tools/v8windbg/base/dbgext.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/tools/v8windbg/base/dbgext.cc')
-rw-r--r--deps/v8/tools/v8windbg/base/dbgext.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/deps/v8/tools/v8windbg/base/dbgext.cc b/deps/v8/tools/v8windbg/base/dbgext.cc
new file mode 100644
index 0000000000..e3f00951b4
--- /dev/null
+++ b/deps/v8/tools/v8windbg/base/dbgext.cc
@@ -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"