-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathglobals.cpp
123 lines (100 loc) · 2.7 KB
/
globals.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*++
Copyright (c) 2017 Vincent Semeria
--*/
#include "globals.h"
#include "CLRInterfaces.h"
#define KDEXT_64BIT
// Structures that describe structures (fPointer, fStruct, fArray, ...)
#include "wdbgexts.h"
WINDBG_EXTENSION_APIS ExtensionApis;
// Global variables to call CDB
PDEBUG_CONTROL g_ExtControl = 0;
PDEBUG_SYMBOLS2 g_ExtSymbols = 0;
IDebugAdvanced2* g_ExtAdvanced = 0;
IDebugSystemObjects* g_ExtSystem = 0;
ISymUnmanagedBinder2* g_SymBinder = 0;
void DestroyDebuggerGlobals()
{
g_ExtControl->Release(); g_ExtControl = 0;
g_ExtSymbols->Release(); g_ExtSymbols = 0;
g_ExtAdvanced->Release(); g_ExtAdvanced = 0;
g_ExtSystem->Release(); g_ExtSystem = 0;
}
HRESULT InitDebuggerGlobals(PDEBUG_CLIENT4 Client)
{
HRESULT Status;
if ((Status = Client->QueryInterface(__uuidof(IDebugControl),
(void **)&g_ExtControl)) != S_OK)
{
goto Fail;
}
if ((Status = Client->QueryInterface(__uuidof(IDebugSymbols2),
(void **)&g_ExtSymbols)) != S_OK)
{
goto Fail;
}
if ((Status = Client->QueryInterface(__uuidof(IDebugAdvanced2),
(void **)&g_ExtAdvanced)) != S_OK)
{
goto Fail;
}
if ((Status = Client->QueryInterface(__uuidof(IDebugSystemObjects),
(void **)&g_ExtSystem)) != S_OK)
{
goto Fail;
}
return S_OK;
Fail:
DestroyDebuggerGlobals();
return Status;
}
NativeDbgEngAPIManager::NativeDbgEngAPIManager(PDEBUG_CLIENT4 client)
{
this->initialized = (S_OK == InitDebuggerGlobals(client));
}
NativeDbgEngAPIManager::~NativeDbgEngAPIManager()
{
DestroyDebuggerGlobals();
}
extern "C"
HRESULT
CALLBACK
DebugExtensionInitialize(PULONG Version, PULONG Flags)
{
IDebugClient *DebugClient;
PDEBUG_CONTROL DebugControl;
HRESULT Hr;
*Version = DEBUG_EXTENSION_VERSION(1, 0);
*Flags = 0;
Hr = S_OK;
// DebugCreate requires a link to dbgeng.dll, try to remove it : Client is provided to each CDB extension method as an argument
if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) != S_OK)
{
return Hr;
}
if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
(void **)&DebugControl)) == S_OK)
{
ExtensionApis.nSize = sizeof(ExtensionApis);
Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis);
// Route CLR Notifications (thrown as exceptions) to function HandleCLRNotification
DebugControl->Execute(DEBUG_OUTCTL_ALL_CLIENTS |
DEBUG_OUTCTL_OVERRIDE_MASK |
DEBUG_OUTCTL_NOT_LOGGED,
"sxd -c \"!HandleCLRNotification\" clrn",
DEBUG_EXECUTE_DEFAULT);
DebugControl->Release();
}
CoInitializeEx(0, 0);
CoCreateInstance(__uuidof(CorSymBinder_SxS), 0, 1,
__uuidof(ISymUnmanagedBinder2), (void **)&g_SymBinder); // link to ole32.dll
DebugClient->Release();
return Hr;
}
extern "C"
void
CALLBACK
DebugExtensionUninitialize(void)
{
return;
}