File: dbgext.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (75 lines) | stat: -rw-r--r-- 2,389 bytes parent folder | download | duplicates (23)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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"