forked from killswitch1111/powerguivsx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptBreakpoint.cs
More file actions
274 lines (228 loc) · 8.75 KB
/
Copy pathScriptBreakpoint.cs
File metadata and controls
274 lines (228 loc) · 8.75 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System.Management.Automation.Runspaces;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Debugger.Interop;
using System.Runtime.InteropServices;
using System;
using PowerShellTools.Common.Logging;
namespace PowerShellTools.DebugEngine
{
/// <summary>
/// The Visual Studio implmentation of a breakpoint for PowerShell.
/// </summary>
public class ScriptBreakpoint : IDebugBoundBreakpoint2, IEnumDebugBoundBreakpoints2, IDebugPendingBreakpoint2, IDebugBreakpointResolution2
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ScriptBreakpoint));
private readonly IEngineEvents _callback;
private readonly ScriptProgramNode _node;
private bool _enabled;
private uint _hitCount;
/// <summary>
/// Line where this breakpoint is set.
/// </summary>
public int Line { get; private set; }
/// <summary>
/// Column where this breakpoint is set.
/// </summary>
public int Column { get; private set; }
/// <summary>
/// Full path to the file this breakpoint is set within.
/// </summary>
public string File { get; private set; }
public ScriptBreakpoint(ScriptProgramNode node, string file, int line, int column, IEngineEvents callback)
{
Log.InfoFormat("ScriptBreakPoint: {0} {1} {2}", file, line, column);
_node = node;
_callback = callback;
_enabled = true;
Line = line;
Column = column;
File = file;
_hitCount = 0;
}
public override bool Equals(object obj)
{
if (obj != null)
{
ScriptBreakpoint other = obj as ScriptBreakpoint;
if (other != null)
{
return other.Column == Column && other.Line == Line &&
File.Equals(other.File, StringComparison.InvariantCultureIgnoreCase) &&
_node.Equals(other._node);
}
}
return false;
}
public override int GetHashCode()
{
return _node.GetHashCode()
^ Line.GetHashCode()
^ Column.GetHashCode()
^ File.GetHashCode();
}
public void IncrementHitCount()
{
_hitCount++;
}
#region Implementation of IDebugBoundBreakpoint2
public int GetPendingBreakpoint(out IDebugPendingBreakpoint2 ppPendingBreakpoint)
{
Log.Debug("ScriptBreakpoint: GetPendingBreakpoint");
ppPendingBreakpoint = this;
return VSConstants.S_OK;
}
public int GetState(enum_BP_STATE[] pState)
{
Log.Debug("ScriptBreakpoint: IDebugBoundBreakpoint2:GetState");
pState[0] = _enabled ? enum_BP_STATE.BPS_ENABLED : enum_BP_STATE.BPS_DISABLED;
return VSConstants.S_OK;
}
public int GetHitCount(out uint pdwHitCount)
{
Log.Debug("ScriptBreakpoint: GetHitCount");
pdwHitCount = _hitCount;
return VSConstants.S_OK;
}
public int GetBreakpointResolution(out IDebugBreakpointResolution2 ppBPResolution)
{
Log.Debug("ScriptBreakpoint: GetBreakpointResolution");
ppBPResolution = this;
return VSConstants.S_OK;
}
public int Enable(int fEnable)
{
Log.Debug("ScriptBreakpoint: Enable");
_enabled = fEnable == 0 ? false : true;
_callback.BreakpointEnabled(this, fEnable);
return VSConstants.S_OK;
}
public int SetHitCount(uint dwHitCount)
{
Log.Debug("ScriptBreakpoint: SetHitCount");
_hitCount = dwHitCount;
return VSConstants.S_OK;
}
public int SetCondition(BP_CONDITION bpCondition)
{
Log.Debug("ScriptBreakpoint: SetCondition");
return VSConstants.E_NOTIMPL;
}
public int SetPassCount(BP_PASSCOUNT bpPassCount)
{
Log.Debug("ScriptBreakpoint: SetPassCount");
return VSConstants.E_NOTIMPL;
}
public int Delete()
{
Log.Debug("ScriptBreakpoint: Delete");
_callback.BreakpointRemoved(this);
return VSConstants.S_OK;
}
#endregion
#region Implementation of IEnumDebugBoundBreakpoints2
public int Next(uint celt, IDebugBoundBreakpoint2[] rgelt, ref uint pceltFetched)
{
Log.Debug("ScriptBreakpoint: Next");
rgelt[0] = this;
pceltFetched = 1;
return VSConstants.S_OK;
}
public int Skip(uint celt)
{
Log.Debug("ScriptBreakpoint: Skip");
return VSConstants.E_NOTIMPL;
}
public int Reset()
{
Log.Debug("ScriptBreakpoint: Reset");
return VSConstants.S_OK;
}
public int Clone(out IEnumDebugBoundBreakpoints2 ppEnum)
{
Log.Debug("ScriptBreakpoint: Clone");
ppEnum = null;
return VSConstants.E_NOTIMPL;
}
public int GetCount(out uint pcelt)
{
Log.Debug("ScriptBreakpoint: GetCount");
pcelt = 1;
return VSConstants.S_OK;
}
#endregion
#region Implementation of IDebugPendingBreakpoint2
public int CanBind(out IEnumDebugErrorBreakpoints2 ppErrorEnum)
{
Log.Debug("ScriptBreakpoint: CanBind");
ppErrorEnum = null;
return VSConstants.S_OK;
}
public int Bind()
{
Log.Debug("ScriptBreakpoint: Bind");
_callback.Breakpoint(_node, this);
return VSConstants.S_OK;
}
public int GetState(PENDING_BP_STATE_INFO[] pState)
{
Log.Debug("ScriptBreakpoint: IDebugPendingBreakpoint2:GetState");
var state = new PENDING_BP_STATE_INFO
{
state = _enabled ? enum_PENDING_BP_STATE.PBPS_ENABLED : enum_PENDING_BP_STATE.PBPS_DISABLED,
Flags = enum_PENDING_BP_STATE_FLAGS.PBPSF_NONE
};
pState[0] = state;
return VSConstants.S_OK;
}
public int GetBreakpointRequest(out IDebugBreakpointRequest2 ppBPRequest)
{
Log.Debug("ScriptBreakpoint: GetBreakpointRequest");
ppBPRequest = null;
return VSConstants.S_OK;
}
public int Virtualize(int fVirtualize)
{
Log.Debug("ScriptBreakpoint: Virtualize");
return VSConstants.S_OK;
}
public int EnumBoundBreakpoints(out IEnumDebugBoundBreakpoints2 ppEnum)
{
Log.Debug("ScriptBreakpoint: EnumBoundBreakpoints");
ppEnum = this;
return VSConstants.S_OK;
}
public int EnumErrorBreakpoints(enum_BP_ERROR_TYPE bpErrorType, out IEnumDebugErrorBreakpoints2 ppEnum)
{
Log.Debug("ScriptBreakpoint: EnumErrorBreakpoints");
ppEnum = null;
return VSConstants.S_OK;
}
#endregion
#region Implementation of IDebugBreakpointResolution2
public int GetBreakpointType(enum_BP_TYPE[] pBPType)
{
Log.Debug("ScriptBreakpoint: GetBreakpointType");
pBPType[0] = enum_BP_TYPE.BPT_CODE;
return VSConstants.S_OK;
}
public int GetResolutionInfo(enum_BPRESI_FIELDS dwFields, BP_RESOLUTION_INFO[] pBPResolutionInfo)
{
//VS line\column is zero based. PowerShell is 1
var documentContext = new ScriptDocumentContext(File, "", Line - 1, Column);
Log.Debug("ScriptBreakpoint: GetResolutionInfo");
if (dwFields == enum_BPRESI_FIELDS.BPRESI_ALLFIELDS)
{
var loc = new BP_RESOLUTION_LOCATION
{
bpType = (uint)enum_BP_TYPE.BPT_CODE,
unionmember1 = Marshal.GetComInterfaceForObject(documentContext, typeof(IDebugCodeContext2))
};
pBPResolutionInfo[0].bpResLocation = loc;
pBPResolutionInfo[0].pProgram = _node;
pBPResolutionInfo[0].pThread = _node;
}
return VSConstants.S_OK;
}
#endregion
}
}