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.Text; | |
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 public class DebugPropertyBase : IDebugProperty2 { | |
15 public DebugPropertyBase( | |
16 DebugPropertyBase parent, | |
17 string name, | |
18 string typeName, | |
19 object value, | |
20 ulong address, | |
21 enum_DBG_ATTRIB_FLAGS attributes, | |
22 ISimpleDebugger dbg) { | |
23 name_ = name; | |
24 typeName_ = typeName; | |
25 value_ = value; | |
26 address_ = address; | |
27 attributes_ = attributes; | |
28 Parent = parent; | |
29 dbg_ = dbg; | |
30 } | |
31 | |
32 public string Name { | |
33 get { return name_; } | |
34 protected set { name_ = value; } | |
35 } | |
36 | |
37 public string TypeName { | |
38 get { return typeName_; } | |
39 protected set { typeName_ = value; } | |
40 } | |
41 | |
42 public object Value | |
43 { | |
44 get { | |
45 RefreshValue(ref value_); | |
46 return value_; | |
47 } | |
48 set { value_ = value; } | |
49 } | |
50 | |
51 public ulong Address { | |
52 get { return address_; } | |
53 protected set { address_ = value; } | |
54 } | |
55 | |
56 public uint Size { | |
57 get { return size_; } | |
58 protected set { size_ = value; } | |
59 } | |
60 | |
61 public ISimpleDebugger Dbg { | |
62 get { return dbg_; } | |
63 protected set { dbg_ = value; } | |
64 } | |
65 | |
66 public enum_DBG_ATTRIB_FLAGS Attributes | |
67 { | |
68 get { return attributes_; } | |
69 protected set { attributes_ = value; } | |
70 } | |
71 | |
72 public DebugPropertyBase Parent { | |
73 get { return parent_; } | |
74 set { | |
75 if (parent_ != null) { | |
76 parent_.Children.Remove(this); | |
77 } | |
78 parent_ = value; | |
79 if (parent_ != null) { | |
80 parent_.Children.Add(this); | |
81 } | |
82 } | |
83 } | |
84 | |
85 public List<DebugPropertyBase> Children { | |
86 get { return children_; } | |
87 } | |
88 | |
89 public virtual string FormatValue() { | |
90 return Convert.ToString(Value); | |
91 } | |
92 | |
93 public override string ToString() | |
94 { | |
95 return string.Format("{0} = {1}", Name, Value); | |
96 } | |
97 | |
98 #region Implementation of IDebugProperty2 | |
99 | |
100 public int GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS dwFields, | |
101 uint dwRadix, | |
102 uint dwTimeout, | |
103 IDebugReference2[] rgpArgs, | |
104 uint dwArgCount, | |
105 DEBUG_PROPERTY_INFO[] pPropertyInfo) { | |
106 Debug.WriteLine("DebugPropertyBase.GetPropertyInfo"); | |
107 | |
108 pPropertyInfo[0].dwFields = 0; | |
109 | |
110 if (dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME)) { | |
111 DebugPropertyBase parent = Parent; | |
112 Stack<DebugPropertyBase> parents = new Stack<DebugPropertyBase>(); | |
113 while (parent != null) { | |
114 parents.Push(parent); | |
115 parent = parent.parent_; | |
116 } | |
117 | |
118 StringBuilder sb = new StringBuilder(); | |
119 foreach (DebugPropertyBase parentProp in parents) { | |
120 sb.AppendFormat("{0}.", parentProp.Name); | |
121 } | |
122 sb.Append(Name); | |
123 | |
124 pPropertyInfo[0].bstrFullName = sb.ToString(); | |
125 | |
126 pPropertyInfo[0].dwFields |= | |
127 enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; | |
128 } | |
129 if (dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME)) { | |
130 pPropertyInfo[0].bstrName = Name; | |
131 pPropertyInfo[0].dwFields |= | |
132 enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; | |
133 } | |
134 if (dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE)) { | |
135 pPropertyInfo[0].bstrType = TypeName; | |
136 pPropertyInfo[0].dwFields |= | |
137 enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; | |
138 } | |
139 if (dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP)) { | |
140 pPropertyInfo[0].pProperty = this; | |
141 pPropertyInfo[0].dwFields |= | |
142 enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP; | |
143 } | |
144 if (dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB)) { | |
145 pPropertyInfo[0].dwAttrib = attributes_; | |
146 pPropertyInfo[0].dwFields |= | |
147 enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; | |
148 } | |
149 if (dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) | |
150 && Value != null) { | |
151 pPropertyInfo[0].bstrValue = FormatValue(); | |
152 pPropertyInfo[0].dwFields |= | |
153 enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE; | |
154 } | |
155 | |
156 return VSConstants.S_OK; | |
157 } | |
158 | |
159 public virtual int SetValueAsString(string pszValue, | |
160 uint dwRadix, | |
161 uint dwTimeout) { | |
162 Debug.WriteLine("DebugPropertyBase.SetValueAsString"); | |
163 throw new NotImplementedException(); | |
164 } | |
165 | |
166 public virtual int SetValueAsReference(IDebugReference2[] rgpArgs, | |
167 uint dwArgCount, | |
168 IDebugReference2 pValue, | |
169 uint dwTimeout) { | |
170 Debug.WriteLine("DebugPropertyBase.SetValueAsReference"); | |
171 throw new NotImplementedException(); | |
172 } | |
173 | |
174 public int EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, | |
175 uint dwRadix, | |
176 ref Guid guidFilter, | |
177 enum_DBG_ATTRIB_FLAGS dwAttribFilter, | |
178 string pszNameFilter, | |
179 uint dwTimeout, | |
180 out IEnumDebugPropertyInfo2 ppEnum) { | |
181 Debug.WriteLine("DebugPropertyBase.EnumChildren"); | |
182 | |
183 List<DEBUG_PROPERTY_INFO> props = new List<DEBUG_PROPERTY_INFO>(); | |
184 DEBUG_PROPERTY_INFO[] info = new DEBUG_PROPERTY_INFO[1]; | |
185 | |
186 foreach (DebugPropertyBase property in Children) | |
187 { | |
188 property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, info); | |
189 props.Add(info[0]); | |
190 } | |
191 | |
192 ppEnum = new PropertyEnumerator(props); | |
193 return VSConstants.S_OK; | |
194 } | |
195 | |
196 public int GetParent(out IDebugProperty2 ppParent) { | |
197 Debug.WriteLine("DebugPropertyBase.GetParent"); | |
198 ppParent = Parent; | |
199 return VSConstants.S_OK; | |
200 } | |
201 | |
202 public int GetDerivedMostProperty(out IDebugProperty2 ppDerivedMost) { | |
203 Debug.WriteLine("DebugPropertyBase.GetDerivedMostProperty"); | |
204 throw new NotImplementedException(); | |
205 } | |
206 | |
207 public int GetMemoryBytes(out IDebugMemoryBytes2 ppMemoryBytes) { | |
208 Debug.WriteLine("DebugPropertyBase.GetMemoryBytes"); | |
209 ppMemoryBytes = new MemoryBytes(dbg_, Address, Size); | |
210 return VSConstants.S_OK; | |
211 } | |
212 | |
213 public int GetMemoryContext(out IDebugMemoryContext2 ppMemory) { | |
214 Debug.WriteLine("DebugPropertyBase.GetMemoryContext"); | |
215 ppMemory = new MemoryContext(Name, Address, Size); | |
216 return VSConstants.S_OK; | |
217 } | |
218 | |
219 public int GetSize(out uint pdwSize) { | |
220 Debug.WriteLine("DebugPropertyBase.GetSize"); | |
221 pdwSize = size_; | |
222 return VSConstants.S_OK; | |
223 } | |
224 | |
225 public int GetReference(out IDebugReference2 ppReference) { | |
226 Debug.WriteLine("DebugPropertyBase.GetReference"); | |
227 throw new NotImplementedException(); | |
228 } | |
229 | |
230 public int GetExtendedInfo(ref Guid guidExtendedInfo, | |
231 out object pExtendedInfo) { | |
232 Debug.WriteLine("DebugPropertyBase.GetExtendedInfo"); | |
233 throw new NotImplementedException(); | |
234 } | |
235 | |
236 #endregion | |
237 | |
238 protected virtual void RefreshValue(ref object value) { | |
239 // base impl does nothing | |
240 } | |
241 | |
242 #region Private Implementation | |
243 | |
244 private enum_DBG_ATTRIB_FLAGS attributes_; | |
245 | |
246 private List<DebugPropertyBase> children_ = new List<DebugPropertyBase>(); | |
247 private DebugPropertyBase parent_; | |
248 private object value_ = null; | |
249 private ulong address_ = 0; | |
250 private uint size_ = 0; | |
251 private string name_; | |
252 private string typeName_; | |
253 private ISimpleDebugger dbg_; | |
254 | |
255 #endregion | |
256 } | |
257 } | |
OLD | NEW |