-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpyext.cpp
More file actions
99 lines (81 loc) · 2 KB
/
pyext.cpp
File metadata and controls
99 lines (81 loc) · 2 KB
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
#include "pyext.h"
#include "pyembed.h"
#define VER_MAJ 1
#define VER_MIN 0
// For Callbacks
IDebugClient *gDebugClient = NULL;
IDebugControl *gPyDebugControl = NULL;
// Current scope
IDebugControl *gDebugControl = NULL;
HRESULT ExtQuery(IN IDebugClient *Client)
{
return Client->QueryInterface(__uuidof(IDebugControl),
(void **)&gDebugControl);
}
void ExtRelease(void)
{
if (gDebugControl != NULL) {
gDebugControl->Release();
gDebugControl = NULL;
}
}
HRESULT CALLBACK
DebugExtensionInitialize(OUT PULONG Version, OUT PULONG Flags)
{
HRESULT hr = S_FALSE;
*Version = DEBUG_EXTENSION_VERSION(VER_MAJ, VER_MIN);
*Flags = 0;
if ((hr = DebugCreate(__uuidof(IDebugClient), (void**)&gDebugClient)) != S_OK)
return hr;
if ((hr = gDebugClient->QueryInterface(__uuidof(IDebugControl),
(void**)&gPyDebugControl)) != S_OK)
goto fail;
if (python_init() != S_OK)
{
hr = E_FAIL;
goto fail;
}
return S_OK;
fail:
if (gPyDebugControl) {
gPyDebugControl->Release();
gPyDebugControl = NULL;
}
if (gDebugClient) {
gDebugClient->Release();
gDebugClient = NULL;
}
return hr;
}
void CALLBACK
DebugExtensionUninitialize(void)
{
python_fini();
if (gPyDebugControl) {
gPyDebugControl->Release();
gPyDebugControl = NULL;
}
if (gDebugClient) {
gDebugClient->Release();
gDebugClient = NULL;
}
return;
}
HRESULT CALLBACK
help(IN IDebugClient *Client, IN OPTIONAL PCSTR args)
{
char help_msg[] =
"\n PyExt - Windbg Python Extension\n"
"\teval [expr]\n"
"\t\t- Evaluate an expression\n"
"\texec [filename]\n"
"\t\t- Run a script\n"
"\tpython\n"
"\t\t- Interactive Python interpreter\n"
"";
UNREFERENCED_PARAMETER(args);
ENTER_CALLBACK(Client);
gDebugControl->Output(DEBUG_OUTPUT_NORMAL, "%s\n", help_msg);
LEAVE_CALLBACK();
return S_OK;
}