af76dd6e7e
Please take a look at tools/v8windbg/README.md for an overview of what v8windbg can do and how it's structured. This platform-specific debugging plugin makes use of the data provided by the V8 postmortem debugging API in tools/debug_helper. Note: This code began as https://github.com/billti/v8dbg and then moved into the Edge repository, where I added features gradually and got code reviews for individual changes. Now, taken in its entirety, it's an obnoxiously large CL. I'm open to breaking it up into a few chunks if that would be preferable. Bug: v8:9376 Change-Id: I3e503de00bb1aea870ae83e9bd99e4e2eab9ef98 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2031700 Reviewed-by: Michael Stanton <mvstanton@chromium.org> Reviewed-by: Tamer Tas <tmrts@chromium.org> Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Commit-Queue: Seth Brenith <seth.brenith@microsoft.com> Cr-Commit-Position: refs/heads/master@{#66319}
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
// 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"
|