|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Drawing; |
|
19 using System.IO; |
|
20 using System.Text; |
|
21 using SymbianDebugLib.PluginAPI.Types.Symbol; |
|
22 using SymbianStructuresLib.Arm.Registers; |
|
23 using SymbianStructuresLib.Debug.Symbols; |
|
24 using SymbianStructuresLib.Debug.Symbols.Constants; |
|
25 using SymbianUtils.Range; |
|
26 using SymbianUtils.Utilities; |
|
27 |
|
28 namespace SymbianStackLib.Data.Output.Entry |
|
29 { |
|
30 public class StackOutputEntry |
|
31 { |
|
32 #region Constructors |
|
33 public StackOutputEntry( uint aAddress, uint aData, DbgViewSymbol aSymbolView ) |
|
34 : this( aAddress, aData ) |
|
35 { |
|
36 FindNearestSymbol( aSymbolView ); |
|
37 } |
|
38 |
|
39 public StackOutputEntry( uint aAddress, uint aData ) |
|
40 { |
|
41 iAddress = aAddress; |
|
42 iData = aData; |
|
43 iDataAsString = RawByteUtility.CreateCharacterisedData( aData ); |
|
44 } |
|
45 |
|
46 internal StackOutputEntry( StackOutputEntry aCopy ) |
|
47 { |
|
48 iAddress = aCopy.Address; |
|
49 iData = aCopy.Data; |
|
50 iDataAsString = aCopy.DataAsString; |
|
51 iSymbol = aCopy.Symbol; |
|
52 iFlags = aCopy.iFlags; |
|
53 iAssociatedBinary = aCopy.AssociatedBinary; |
|
54 iAssociatedRegister = aCopy.AssociatedRegister; |
|
55 iTag = aCopy.Tag; |
|
56 } |
|
57 #endregion |
|
58 |
|
59 #region API |
|
60 public void FindNearestSymbol( DbgViewSymbol aSymbolView ) |
|
61 { |
|
62 SymbolCollection collection = null; |
|
63 iSymbol = aSymbolView.Lookup( this.Data, out collection ); |
|
64 // |
|
65 if ( collection != null ) |
|
66 { |
|
67 // FIXME: should this be device file name if available, and host file name if all else fails? |
|
68 AssociatedBinary = Path.GetFileName( collection.FileName.FileNameInHost ); |
|
69 } |
|
70 } |
|
71 |
|
72 public string GetSuggestedToolTipText() |
|
73 { |
|
74 string ret = string.Empty; |
|
75 // |
|
76 if ( IsCurrentStackPointerEntry ) |
|
77 { |
|
78 ret = "Current stack pointer address"; |
|
79 } |
|
80 else if ( IsRegisterBasedEntry ) |
|
81 { |
|
82 ret = "Value obtained from register " + AssociatedRegisterName; |
|
83 } |
|
84 else if ( Symbol != null ) |
|
85 { |
|
86 ret = "From: " + Symbol.Object; |
|
87 } |
|
88 else if ( AssociatedBinary != string.Empty ) |
|
89 { |
|
90 ret = "From: " + AssociatedBinary; |
|
91 } |
|
92 // |
|
93 return ret; |
|
94 } |
|
95 |
|
96 public void GetSuggestedColours( out Color aFore, out Color aBack ) |
|
97 { |
|
98 aFore = Color.Black; |
|
99 aBack = Color.Transparent; |
|
100 // |
|
101 if ( IsRegisterBasedEntry ) |
|
102 { |
|
103 aBack = Color.LightSteelBlue; |
|
104 } |
|
105 else if ( IsCurrentStackPointerEntry ) |
|
106 { |
|
107 aBack = Color.Pink; |
|
108 } |
|
109 else if ( IsOutsideCurrentStackRange ) |
|
110 { |
|
111 aFore = Color.DarkGray; |
|
112 } |
|
113 else if ( IsGhost ) |
|
114 { |
|
115 aFore = Color.DarkGray; |
|
116 } |
|
117 else if ( Symbol != null ) |
|
118 { |
|
119 aFore = Color.DarkBlue; |
|
120 } |
|
121 } |
|
122 #endregion |
|
123 |
|
124 #region Properties |
|
125 public uint Address |
|
126 { |
|
127 get { return iAddress; } |
|
128 } |
|
129 |
|
130 public AddressRange AddressRange |
|
131 { |
|
132 get { return new AddressRange( Address, Address + 3 ); } |
|
133 } |
|
134 |
|
135 public uint Data |
|
136 { |
|
137 get { return iData; } |
|
138 } |
|
139 |
|
140 public string DataAsString |
|
141 { |
|
142 get { return iDataAsString; } |
|
143 } |
|
144 |
|
145 public Symbol Symbol |
|
146 { |
|
147 get { return iSymbol; } |
|
148 } |
|
149 |
|
150 public TArmRegisterType AssociatedRegister |
|
151 { |
|
152 get { return iAssociatedRegister; } |
|
153 set { iAssociatedRegister = value; } |
|
154 } |
|
155 |
|
156 public string AssociatedRegisterName |
|
157 { |
|
158 get { return ArmRegister.GetTypeName( iAssociatedRegister ); } |
|
159 } |
|
160 |
|
161 public string AssociatedBinary |
|
162 { |
|
163 get { return iAssociatedBinary; } |
|
164 set { iAssociatedBinary = value; } |
|
165 } |
|
166 |
|
167 public string Object |
|
168 { |
|
169 get |
|
170 { |
|
171 string ret = AssociatedBinary; |
|
172 // |
|
173 if ( Symbol != null ) |
|
174 { |
|
175 ret = Symbol.Object; |
|
176 } |
|
177 // |
|
178 return ret; |
|
179 } |
|
180 } |
|
181 |
|
182 public object Tag |
|
183 { |
|
184 get { return iTag; } |
|
185 set { iTag = value; } |
|
186 } |
|
187 |
|
188 public uint FunctionOffset |
|
189 { |
|
190 get |
|
191 { |
|
192 uint ret = 0; |
|
193 // |
|
194 if ( iSymbol != null ) |
|
195 { |
|
196 ret = iSymbol.Offset( this.Data ); |
|
197 } |
|
198 // |
|
199 return ret; |
|
200 } |
|
201 } |
|
202 #endregion |
|
203 |
|
204 #region Flag query properties |
|
205 public bool IsCurrentStackPointerEntry |
|
206 { |
|
207 get { return ( iFlags & TFlags.EFlagsIsCurrentStackPointerEntry ) == TFlags.EFlagsIsCurrentStackPointerEntry; } |
|
208 set |
|
209 { |
|
210 if ( value ) |
|
211 { |
|
212 iFlags |= TFlags.EFlagsIsCurrentStackPointerEntry; |
|
213 } |
|
214 else |
|
215 { |
|
216 iFlags &= ~TFlags.EFlagsIsCurrentStackPointerEntry; |
|
217 } |
|
218 } |
|
219 } |
|
220 |
|
221 public bool IsOutsideCurrentStackRange |
|
222 { |
|
223 get { return ( iFlags & TFlags.EFlagsIsOutsideCurrentStackRange ) == TFlags.EFlagsIsOutsideCurrentStackRange; } |
|
224 set |
|
225 { |
|
226 if ( value ) |
|
227 { |
|
228 iFlags |= TFlags.EFlagsIsOutsideCurrentStackRange; |
|
229 } |
|
230 else |
|
231 { |
|
232 iFlags &= ~TFlags.EFlagsIsOutsideCurrentStackRange; |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 public bool IsAccurate |
|
238 { |
|
239 get { return ( iFlags & TFlags.EFlagsIsAccurate ) == TFlags.EFlagsIsAccurate; } |
|
240 set |
|
241 { |
|
242 if ( value ) |
|
243 { |
|
244 iFlags |= TFlags.EFlagsIsAccurate; |
|
245 } |
|
246 else |
|
247 { |
|
248 iFlags &= ~TFlags.EFlagsIsAccurate; |
|
249 } |
|
250 } |
|
251 } |
|
252 |
|
253 public bool IsRegisterBasedEntry |
|
254 { |
|
255 get { return ( iFlags & TFlags.EFlagsIsRegisterBasedEntry ) == TFlags.EFlagsIsRegisterBasedEntry; } |
|
256 set |
|
257 { |
|
258 if ( value ) |
|
259 { |
|
260 iFlags |= TFlags.EFlagsIsRegisterBasedEntry; |
|
261 } |
|
262 else |
|
263 { |
|
264 iFlags &= ~TFlags.EFlagsIsRegisterBasedEntry; |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 public bool IsGhost |
|
270 { |
|
271 get { return ( iFlags & TFlags.EFlagsIsGhost ) == TFlags.EFlagsIsGhost; } |
|
272 set |
|
273 { |
|
274 if ( value ) |
|
275 { |
|
276 iFlags |= TFlags.EFlagsIsGhost; |
|
277 } |
|
278 else |
|
279 { |
|
280 iFlags &= ~TFlags.EFlagsIsGhost; |
|
281 } |
|
282 } |
|
283 } |
|
284 #endregion |
|
285 |
|
286 #region From System.Object |
|
287 public override string ToString() |
|
288 { |
|
289 const int KNormalAddressWidth = 10; |
|
290 |
|
291 StringBuilder ret = new StringBuilder(); |
|
292 if ( IsRegisterBasedEntry ) |
|
293 { |
|
294 string prefix = "[ " + AssociatedRegisterName; |
|
295 prefix = prefix.PadRight( KNormalAddressWidth - 2 ); |
|
296 prefix += " ]"; |
|
297 ret.AppendFormat( "{0} = {1:x8} {2} ", prefix, Data, DataAsString ); |
|
298 } |
|
299 else |
|
300 { |
|
301 ret.AppendFormat( "[{0:x8}] = {1:x8} {2} ", Address, Data, DataAsString ); |
|
302 } |
|
303 // |
|
304 if ( iSymbol != null && !iSymbol.IsDefault ) |
|
305 { |
|
306 string baseAddressOffset = Symbol.ToStringOffset( Data ); |
|
307 ret.AppendFormat( "{0} {1}", baseAddressOffset, Symbol.Name ); |
|
308 } |
|
309 else if ( AssociatedBinary != string.Empty ) |
|
310 { |
|
311 ret.AppendFormat( "{0} {1}", SymbolConstants.KUnknownOffset, AssociatedBinary ); |
|
312 } |
|
313 // |
|
314 return ret.ToString(); |
|
315 } |
|
316 #endregion |
|
317 |
|
318 #region Internal methods |
|
319 #endregion |
|
320 |
|
321 #region Internal flags |
|
322 [Flags] |
|
323 private enum TFlags |
|
324 { |
|
325 EFlagsNone = 0, |
|
326 EFlagsIsCurrentStackPointerEntry = 1, |
|
327 EFlagsIsOutsideCurrentStackRange = 2, |
|
328 EFlagsIsAccurate = 4, |
|
329 EFlagsIsRegisterBasedEntry = 8, |
|
330 EFlagsIsGhost = 16 |
|
331 } |
|
332 #endregion |
|
333 |
|
334 #region Data members |
|
335 private readonly uint iAddress; |
|
336 private readonly uint iData; |
|
337 private readonly string iDataAsString; |
|
338 private Symbol iSymbol = null; |
|
339 private TFlags iFlags = TFlags.EFlagsNone; |
|
340 private string iAssociatedBinary = string.Empty; |
|
341 private TArmRegisterType iAssociatedRegister = TArmRegisterType.EArmReg_Other; |
|
342 private object iTag = null; |
|
343 #endregion |
|
344 } |
|
345 } |