forked from killswitch1111/powerguivsx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptDebugProcess.cs
More file actions
180 lines (150 loc) · 5.54 KB
/
Copy pathScriptDebugProcess.cs
File metadata and controls
180 lines (150 loc) · 5.54 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Debugger.Interop;
using PowerShellTools.Common.Logging;
using PowerShellTools.DebugEngine.Remote;
namespace PowerShellTools.DebugEngine
{
public class ScriptDebugProcess : IDebugProcess2
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ScriptDebugProcess));
private readonly IDebugPort2 _port;
private string _processName;
public ScriptDebugProcess(IDebugPort2 debugPort, uint processId, string processName, string hostname) : this(debugPort, processId)
{
_processName = processName;
HostName = hostname;
}
public ScriptDebugProcess(IDebugPort2 debugPort, uint processId) : this(debugPort)
{
ProcessId = processId;
if (_processName == null)
{
_processName = string.Empty;
}
}
public ScriptDebugProcess(IDebugPort2 debugPort)
{
Log.Debug("Process: Constructor");
Id = Guid.NewGuid();
_port = debugPort;
Node = new ScriptProgramNode(this);
}
public uint ProcessId { get; set; }
public Guid Id { get; set; }
public ScriptProgramNode Node { get; set; }
public string HostName { get; set; }
public int GetInfo(enum_PROCESS_INFO_FIELDS fields, PROCESS_INFO[] pProcessInfo)
{
if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0)
{
pProcessInfo[0].bstrFileName = Node.FileName;
pProcessInfo[0].Flags = enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_RUNNING;
if (Node.Debugger != null)
{
pProcessInfo[0].Flags = pProcessInfo[0].Flags | enum_PROCESS_INFO_FLAGS.PIFLAG_DEBUGGER_ATTACHED;
}
pProcessInfo[0].Fields = fields;
pProcessInfo[0].bstrBaseName = _processName;
pProcessInfo[0].bstrTitle = string.Empty;
pProcessInfo[0].ProcessId.dwProcessId = ProcessId;
pProcessInfo[0].dwSessionId = 0;
}
return VSConstants.S_OK;
}
public int EnumPrograms(out IEnumDebugPrograms2 ppEnum)
{
Log.Debug("Process: EnumPrograms");
ppEnum = new RemoteEnumDebugPrograms(this);
return VSConstants.S_OK;
}
public int GetName(enum_GETNAME_TYPE gnType, out string pbstrName)
{
Log.Debug("Process: GetName");
pbstrName = "PowerShell Script Process";
return VSConstants.S_OK;
}
public int GetServer(out IDebugCoreServer2 ppServer)
{
Log.Debug("Process: GetServer");
ppServer = null;
return VSConstants.S_OK;
}
public int Terminate()
{
Log.Debug("Process: Terminate");
return VSConstants.S_OK;
}
public int Attach(IDebugEventCallback2 pCallback, Guid[] rgguidSpecificEngines, uint celtSpecificEngines, int[] rghrEngineAttach)
{
Log.Debug("Process: Attach");
return VSConstants.S_OK;
}
public int CanDetach()
{
Log.Debug("Process: CanDetach");
return VSConstants.S_OK;
}
public int Detach()
{
Log.Debug("Process: Detach");
return VSConstants.S_OK;
}
public int GetPhysicalProcessId(AD_PROCESS_ID[] pProcessId)
{
Log.Debug("Process: GetPhysicalProcessId");
var pidStruct = new AD_PROCESS_ID();
// if dealing with an actual process we need to identify it with its PID
if(ProcessId != 0)
{
pidStruct.dwProcessId = (uint)ProcessId;
pidStruct.ProcessIdType = (uint)enum_AD_PROCESS_ID.AD_PROCESS_ID_SYSTEM;
}
else
{
pidStruct.guidProcessId = Id;
pidStruct.ProcessIdType = (uint)enum_AD_PROCESS_ID.AD_PROCESS_ID_GUID;
}
pProcessId[0] = pidStruct;
return VSConstants.S_OK;
}
public int GetProcessId(out Guid pguidProcessId)
{
Log.Debug("Process: GetProcessId");
pguidProcessId = Id;
return VSConstants.S_OK;
}
public int GetAttachedSessionName(out string pbstrSessionName)
{
Log.Debug("Process: GetAttachedSessionName");
pbstrSessionName = null;
return VSConstants.E_NOTIMPL;
}
public int EnumThreads(out IEnumDebugThreads2 ppEnum)
{
Log.Debug("Process: EnumThreads");
ppEnum = null;
return VSConstants.S_OK;
}
public int CauseBreak()
{
Log.Debug("Process: CauseBreak");
return VSConstants.S_OK;
}
public int GetPort(out IDebugPort2 ppPort)
{
Log.Debug("Process: GetPort");
ppPort = _port;
return VSConstants.S_OK;
}
public int QueryCanSafelyAttach()
{
return VSConstants.S_OK;
}
public int GetUserName(out string pbstrUserName)
{
pbstrUserName = string.Empty;
return VSConstants.S_OK;
}
}
}