OLD | NEW |
| (Empty) |
1 // Copyright 2009 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can | |
3 // be found in the LICENSE file. | |
4 using System; | |
5 using System.Collections.Generic; | |
6 using System.Diagnostics; | |
7 using System.Linq; | |
8 using Google.MsAd7.BaseImpl.Ad7Enumerators; | |
9 using Google.MsAd7.BaseImpl.Interfaces; | |
10 using Microsoft.VisualStudio; | |
11 using Microsoft.VisualStudio.Debugger.Interop; | |
12 | |
13 namespace Google.MsAd7.BaseImpl { | |
14 /// <summary> | |
15 /// For documentation of IDebugPendingBreakpoint2 members, please see the VS 2
008 MSDN | |
16 /// documentation. | |
17 /// </summary> | |
18 public class PendingBreakpoint : IDebugPendingBreakpoint2 | |
19 { | |
20 /// <summary> | |
21 /// This custom constructor ensures the class gets everything it needs to kn
ow. | |
22 /// </summary> | |
23 /// <param name="dbg">A debugger for address lookups.</param> | |
24 /// <param name="rq">A request that can be queried for code context informat
ion.</param> | |
25 public PendingBreakpoint(ISimpleDebugger dbg, BreakpointRequest rq) { | |
26 dbg_ = dbg; | |
27 rq_ = rq; | |
28 breakpointInfo_ = dbg_.Symbols.GetBreakpointInfo(); | |
29 errorBreakpoints_ = null; | |
30 } | |
31 | |
32 #region Implementation of IDebugPendingBreakpoint2 | |
33 | |
34 public int CanBind(out IEnumDebugErrorBreakpoints2 ppErrorEnum) { | |
35 Debug.WriteLine("PendingBreakpoint.CanBind"); | |
36 int rValue = breakpointInfo_.GetBindErrors(rq_.DocPos, out ppErrorEnum); | |
37 if (rValue != VSConstants.S_OK) { | |
38 var typedEnum = ppErrorEnum as ErrorBreakpointEnumerator; | |
39 if (typedEnum != null) { | |
40 typedEnum.PopulateBreakpoint(this); | |
41 } | |
42 } | |
43 return rValue; | |
44 } | |
45 | |
46 public int Bind() { | |
47 Debug.WriteLine("PendingBreakpoint.Bind"); | |
48 IEnumerable<ulong> addresses; | |
49 int rValue = breakpointInfo_.GetBindAddresses( | |
50 rq_.DocPos, | |
51 out addresses, | |
52 out errorBreakpoints_); | |
53 if (rValue != VSConstants.S_OK) { | |
54 var typedEnum = errorBreakpoints_ as ErrorBreakpointEnumerator; | |
55 if (typedEnum != null) { | |
56 typedEnum.PopulateBreakpoint(this); | |
57 } | |
58 } | |
59 if (addresses != null && addresses.Count() > 0) { | |
60 foreach (UInt64 address in addresses) { | |
61 var bp = new BoundBreakpoint(this, address); | |
62 boundBreakpoints_.Add(bp); | |
63 dbg_.AddBreakpoint(address); | |
64 } | |
65 } else { | |
66 rValue = VSConstants.E_FAIL; | |
67 } | |
68 return rValue; | |
69 } | |
70 | |
71 public int GetState(PENDING_BP_STATE_INFO[] pState) { | |
72 Debug.WriteLine("PendingBreakpoint.GetState"); | |
73 if (virtualized_) { | |
74 pState[0].Flags = enum_PENDING_BP_STATE_FLAGS.PBPSF_VIRTUALIZED; | |
75 } else { | |
76 pState[0].Flags = enum_PENDING_BP_STATE_FLAGS.PBPSF_NONE; | |
77 } | |
78 | |
79 // note: not supporting "deleted" state ATM. | |
80 if (enabled_) { | |
81 pState[0].state = enum_PENDING_BP_STATE.PBPS_ENABLED; | |
82 } else { | |
83 pState[0].state = enum_PENDING_BP_STATE.PBPS_DISABLED; | |
84 } | |
85 return VSConstants.S_OK; | |
86 } | |
87 | |
88 public int GetBreakpointRequest(out IDebugBreakpointRequest2 ppBPRequest) { | |
89 Debug.WriteLine("PendingBreakpoint.GetBreakpointRequest"); | |
90 ppBPRequest = rq_; | |
91 return VSConstants.S_OK; | |
92 } | |
93 | |
94 public int Virtualize(int fVirtualize) { | |
95 Debug.WriteLine("PendingBreakpoint.Virtualize"); | |
96 virtualized_ = fVirtualize != 0; | |
97 return VSConstants.S_OK; | |
98 } | |
99 | |
100 public int Enable(int fEnable) { | |
101 Debug.WriteLine("PendingBreakpoint.Enable: " + fEnable); | |
102 enabled_ = fEnable != 0; | |
103 return VSConstants.S_OK; | |
104 } | |
105 | |
106 public int SetCondition(BP_CONDITION bpCondition) { | |
107 Debug.WriteLine("PendingBreakpoint.SetCondition"); | |
108 throw new NotImplementedException(); | |
109 } | |
110 | |
111 public int SetPassCount(BP_PASSCOUNT bpPassCount) { | |
112 Debug.WriteLine("PendingBreakpoint.SetPassCount"); | |
113 throw new NotImplementedException(); | |
114 } | |
115 | |
116 public int EnumBoundBreakpoints(out IEnumDebugBoundBreakpoints2 ppEnum) { | |
117 Debug.WriteLine("PendingBreakpoint.EnumBoundBreakpoints"); | |
118 throw new NotImplementedException(); | |
119 } | |
120 | |
121 public int EnumErrorBreakpoints(enum_BP_ERROR_TYPE bpErrorType, | |
122 out IEnumDebugErrorBreakpoints2 ppEnum) { | |
123 var matchingBreakpointErrors = new ErrorBreakpointEnumerator(); | |
124 | |
125 uint errorCount; | |
126 if (errorBreakpoints_.GetCount(out errorCount) == VSConstants.S_OK) { | |
127 var breakpointArray = new IDebugErrorBreakpoint2[errorCount]; | |
128 uint fetchedCount = 0; | |
129 errorBreakpoints_.Next(errorCount, breakpointArray, ref fetchedCount); | |
130 foreach (IDebugErrorBreakpoint2 point in breakpointArray) { | |
131 IDebugErrorBreakpointResolution2 pointResolution; | |
132 if (point.GetBreakpointResolution(out pointResolution) != | |
133 VSConstants.S_OK) { | |
134 continue; | |
135 } | |
136 var pointResolutionInfo = new BP_ERROR_RESOLUTION_INFO[1]; | |
137 if (pointResolution.GetResolutionInfo( | |
138 enum_BPERESI_FIELDS.BPERESI_TYPE, | |
139 pointResolutionInfo) != VSConstants.S_OK) { | |
140 continue; | |
141 } | |
142 if ((pointResolutionInfo[0].dwType == bpErrorType) || | |
143 ((int) bpErrorType == -1)) { | |
144 matchingBreakpointErrors.Insert(point); | |
145 } | |
146 } | |
147 } | |
148 ppEnum = matchingBreakpointErrors; | |
149 return VSConstants.S_OK; | |
150 } | |
151 | |
152 public int Delete() { | |
153 Debug.WriteLine("PendingBreakpoint.Delete"); | |
154 foreach (BoundBreakpoint bp in boundBreakpoints_) { | |
155 dbg_.RemoveBreakpoint(bp.Address); | |
156 } | |
157 boundBreakpoints_.Clear(); | |
158 enabled_ = false; | |
159 return VSConstants.S_OK; | |
160 } | |
161 | |
162 #endregion | |
163 | |
164 #region Private Implementation | |
165 | |
166 private readonly List<BoundBreakpoint> boundBreakpoints_ = | |
167 new List<BoundBreakpoint>(); | |
168 | |
169 private readonly IBreakpointInfo breakpointInfo_; | |
170 | |
171 private readonly ISimpleDebugger dbg_; | |
172 private readonly BreakpointRequest rq_; | |
173 private bool enabled_; | |
174 | |
175 private IEnumDebugErrorBreakpoints2 errorBreakpoints_; | |
176 private bool virtualized_; | |
177 | |
178 #endregion | |
179 } | |
180 } | |
OLD | NEW |