|
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.Text; |
|
19 using System.Collections.Generic; |
|
20 using CrashItemLib.Crash; |
|
21 using CrashItemLib.Crash.Base; |
|
22 using CrashItemLib.Crash.Base.DataBinding; |
|
23 using CrashItemLib.Crash.Container; |
|
24 using CrashItemLib.Crash.Threads; |
|
25 using CrashItemLib.Crash.Processes; |
|
26 using CrashItemLib.Crash.Registers; |
|
27 using CrashItemLib.Crash.Registers.Special; |
|
28 using SymbianUtils.Range; |
|
29 using SymbianUtils.Enum; |
|
30 using SymbianStructuresLib.Uids; |
|
31 using SymbianUtils.DataBuffer; |
|
32 using SymbianStructuresLib.Arm.Registers; |
|
33 |
|
34 namespace CrashItemLib.Crash.ExitInfo |
|
35 { |
|
36 [CIDBAttributeColumn( "Name", 0 )] |
|
37 [CIDBAttributeColumn( "Value", 1, true )] |
|
38 public class CIExitInfo : CIElement |
|
39 { |
|
40 #region Enumerations |
|
41 public enum TExitType |
|
42 { |
|
43 EExitTypePending = 0, |
|
44 EExitTypeKill, |
|
45 EExitTypePanic, |
|
46 EExitTypeTerminate, |
|
47 EExitTypeException |
|
48 } |
|
49 #endregion |
|
50 |
|
51 #region Constructors |
|
52 public CIExitInfo( CIElement aParent ) |
|
53 : base( aParent.Container, aParent ) |
|
54 { |
|
55 } |
|
56 #endregion |
|
57 |
|
58 #region API |
|
59 #endregion |
|
60 |
|
61 #region Properties |
|
62 public TExitType Type |
|
63 { |
|
64 get |
|
65 { |
|
66 TExitType ret = iType; |
|
67 // |
|
68 if ( !iTypeWasExplicitlySet && OwningThread != null ) |
|
69 { |
|
70 // A client did not specify an explict exit reason, so in this case |
|
71 // we'll try to work out if we're dealing with an exception based upon |
|
72 // register values. |
|
73 // |
|
74 // We can only do this if the owning object is available. |
|
75 CIThread thread = OwningThread; |
|
76 CIThreadRegisterListCollection regs = thread.Registers; |
|
77 if ( thread.Registers.Contains( TArmRegisterBank.ETypeException ) ) |
|
78 { |
|
79 // Best guess |
|
80 ret = TExitType.EExitTypeException; |
|
81 } |
|
82 } |
|
83 // |
|
84 return iType; |
|
85 } |
|
86 set |
|
87 { |
|
88 iTypeWasExplicitlySet = true; |
|
89 iType = value; |
|
90 } |
|
91 } |
|
92 |
|
93 public string TypeDescription |
|
94 { |
|
95 get |
|
96 { |
|
97 switch( Type ) |
|
98 { |
|
99 case TExitType.EExitTypeException: |
|
100 return "Exception"; |
|
101 case TExitType.EExitTypePending: |
|
102 return "Pending"; |
|
103 case TExitType.EExitTypePanic: |
|
104 return "Panic"; |
|
105 case TExitType.EExitTypeTerminate: |
|
106 return "Terminate"; |
|
107 case TExitType.EExitTypeKill: |
|
108 return "Kill"; |
|
109 default: |
|
110 return "Unknown"; |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 public bool IsAbnormalTermination |
|
116 { |
|
117 get |
|
118 { |
|
119 bool ret = false; |
|
120 // |
|
121 switch ( Type ) |
|
122 { |
|
123 case TExitType.EExitTypeException: |
|
124 case TExitType.EExitTypePanic: |
|
125 case TExitType.EExitTypeTerminate: |
|
126 ret = true; |
|
127 break; |
|
128 default: |
|
129 case TExitType.EExitTypeKill: |
|
130 case TExitType.EExitTypePending: |
|
131 break; |
|
132 } |
|
133 // |
|
134 return ret; |
|
135 } |
|
136 } |
|
137 |
|
138 public string Category |
|
139 { |
|
140 get |
|
141 { |
|
142 string ret = iCategory; |
|
143 // |
|
144 if ( Type == TExitType.EExitTypeException ) |
|
145 { |
|
146 CIRegisterExcCode code = RegisterExcCode; |
|
147 if ( code != null ) |
|
148 { |
|
149 ret = EnumUtils.ToString( ExceptionCode ); |
|
150 } |
|
151 } |
|
152 // |
|
153 return ret; |
|
154 } |
|
155 set { iCategory = value; } |
|
156 } |
|
157 |
|
158 public int Reason |
|
159 { |
|
160 get |
|
161 { |
|
162 int ret = iReason; |
|
163 // |
|
164 if ( Type == TExitType.EExitTypeException ) |
|
165 { |
|
166 ret = (int) ExceptionCode; |
|
167 } |
|
168 // |
|
169 return ret; |
|
170 } |
|
171 set { iReason = value; } |
|
172 } |
|
173 |
|
174 public CIRegisterFSR RegisterFSR |
|
175 { |
|
176 get |
|
177 { |
|
178 CIRegisterFSR ret = null; |
|
179 // |
|
180 CIRegisterList list = RegListCoProcessor; |
|
181 if ( list != null && list.Contains( TArmRegisterType.EArmReg_FSR ) ) |
|
182 { |
|
183 CIRegister reg = list[ TArmRegisterType.EArmReg_FSR ]; |
|
184 ret = reg as CIRegisterFSR; |
|
185 } |
|
186 // |
|
187 return ret; |
|
188 } |
|
189 } |
|
190 |
|
191 public CIRegisterExcCode RegisterExcCode |
|
192 { |
|
193 get |
|
194 { |
|
195 CIRegisterExcCode ret = null; |
|
196 // |
|
197 CIRegisterList list = RegListException; |
|
198 if ( list != null && list.Contains( TArmRegisterType.EArmReg_EXCCODE ) ) |
|
199 { |
|
200 CIRegister reg = list[ TArmRegisterType.EArmReg_EXCCODE ]; |
|
201 ret = reg as CIRegisterExcCode; |
|
202 } |
|
203 // |
|
204 return ret; |
|
205 } |
|
206 } |
|
207 |
|
208 public CIRegisterExcCode.TExceptionCode ExceptionCode |
|
209 { |
|
210 get |
|
211 { |
|
212 if ( Type != TExitType.EExitTypeException ) |
|
213 { |
|
214 throw new InvalidOperationException(); |
|
215 } |
|
216 |
|
217 CIRegisterExcCode.TExceptionCode code = CIRegisterExcCode.TExceptionCode.EExceptionCodeUnknown; |
|
218 CIRegisterExcCode excCode = RegisterExcCode; |
|
219 // |
|
220 if ( excCode != null ) |
|
221 { |
|
222 code = excCode; |
|
223 } |
|
224 // |
|
225 return code; |
|
226 } |
|
227 } |
|
228 |
|
229 public string ExceptionDescription |
|
230 { |
|
231 get |
|
232 { |
|
233 string ret = string.Empty; |
|
234 // |
|
235 if ( Type == TExitType.EExitTypeException ) |
|
236 { |
|
237 CIRegisterExcCode reg = RegisterExcCode; |
|
238 if ( reg != null ) |
|
239 { |
|
240 ret = reg.ExceptionCodeDescription; |
|
241 } |
|
242 } |
|
243 // |
|
244 return ret; |
|
245 } |
|
246 } |
|
247 |
|
248 public CIThread OwningThread |
|
249 { |
|
250 get { return base.Parent as CIThread; } |
|
251 } |
|
252 |
|
253 public CIProcess OwningProcess |
|
254 { |
|
255 get |
|
256 { |
|
257 CIProcess ret = base.Parent as CIProcess; |
|
258 // |
|
259 if ( ret == null && OwningThread != null ) |
|
260 { |
|
261 ret = OwningThread.OwningProcess; |
|
262 } |
|
263 // |
|
264 return ret; |
|
265 } |
|
266 } |
|
267 #endregion |
|
268 |
|
269 #region Internal methods |
|
270 private CIRegisterList RegListException |
|
271 { |
|
272 get |
|
273 { |
|
274 System.Diagnostics.Debug.Assert( OwningThread != null ); |
|
275 // |
|
276 CIThread thread = (CIThread) OwningThread; |
|
277 CIThreadRegisterListCollection registers = thread.Registers; |
|
278 // |
|
279 if ( registers.Contains( TArmRegisterBank.ETypeException ) ) |
|
280 { |
|
281 CIRegisterList list = registers[ TArmRegisterBank.ETypeException ]; |
|
282 return list; |
|
283 } |
|
284 // |
|
285 return null; |
|
286 } |
|
287 } |
|
288 |
|
289 private CIRegisterList RegListCoProcessor |
|
290 { |
|
291 get |
|
292 { |
|
293 System.Diagnostics.Debug.Assert( OwningThread != null ); |
|
294 // |
|
295 CIThread thread = (CIThread) OwningThread; |
|
296 CIThreadRegisterListCollection registers = thread.Registers; |
|
297 // |
|
298 if ( registers.Contains( TArmRegisterBank.ETypeCoProcessor ) ) |
|
299 { |
|
300 CIRegisterList list = registers[ TArmRegisterBank.ETypeCoProcessor ]; |
|
301 return list; |
|
302 } |
|
303 // |
|
304 return null; |
|
305 } |
|
306 } |
|
307 #endregion |
|
308 |
|
309 #region From CIElement |
|
310 public override void PrepareRows() |
|
311 { |
|
312 DataBindingModel.ClearRows(); |
|
313 |
|
314 // Type is common |
|
315 CIDBRow rowType= new CIDBRow(); |
|
316 rowType.Add( new CIDBCell( "Type" ) ); |
|
317 rowType.Add( new CIDBCell( TypeDescription ) ); |
|
318 DataBindingModel.Add( rowType ); |
|
319 |
|
320 // We must prepare them by hand because we show |
|
321 // different content depending on the type of exit. |
|
322 if ( Type == TExitType.EExitTypePending ) |
|
323 { |
|
324 // Nothing to add |
|
325 } |
|
326 else if ( Type == TExitType.EExitTypeException ) |
|
327 { |
|
328 string code = ExceptionDescription; |
|
329 if ( code != string.Empty ) |
|
330 { |
|
331 CIDBRow rowExcCode = new CIDBRow(); |
|
332 rowExcCode.Add( new CIDBCell( "Exception Code" ) ); |
|
333 rowExcCode.Add( new CIDBCell( code ) ); |
|
334 DataBindingModel.Add( rowExcCode ); |
|
335 } |
|
336 |
|
337 CIRegisterFSR fsr = RegisterFSR; |
|
338 if ( fsr != null ) |
|
339 { |
|
340 CIDBRow rowFSR = new CIDBRow(); |
|
341 rowFSR.Add( new CIDBCell( "Fault Type" ) ); |
|
342 rowFSR.Add( new CIDBCell( fsr.FaultDescription ) ); |
|
343 DataBindingModel.Add( rowFSR ); |
|
344 } |
|
345 } |
|
346 else |
|
347 { |
|
348 // Panic, terminate |
|
349 CIDBRow rowCategory = new CIDBRow(); |
|
350 rowCategory.Add( new CIDBCell( "Category" ) ); |
|
351 rowCategory.Add( new CIDBCell( Category ) ); |
|
352 DataBindingModel.Add( rowCategory ); |
|
353 |
|
354 CIDBRow rowReason = new CIDBRow(); |
|
355 rowReason.Add( new CIDBCell( "Reason" ) ); |
|
356 rowReason.Add( new CIDBCell( Reason.ToString() ) ); |
|
357 DataBindingModel.Add( rowReason ); |
|
358 |
|
359 CIDBRow rowFullPanic = new CIDBRow(); |
|
360 rowFullPanic.Add( new CIDBCell( "In Full" ) ); |
|
361 rowFullPanic.Add( new CIDBCell( string.Format( "{0}-{1}", Category, Reason ) ) ); |
|
362 DataBindingModel.Add( rowFullPanic ); |
|
363 } |
|
364 } |
|
365 #endregion |
|
366 |
|
367 #region From System.Object |
|
368 public override string ToString() |
|
369 { |
|
370 StringBuilder ret = new StringBuilder(); |
|
371 // |
|
372 if ( Type == TExitType.EExitTypePending ) |
|
373 { |
|
374 ret.Append( "Pending" ); |
|
375 } |
|
376 else if ( Type == TExitType.EExitTypeException ) |
|
377 { |
|
378 ret.Append( "Exception" ); |
|
379 } |
|
380 else |
|
381 { |
|
382 ret.AppendFormat( "{0}-{1}", Category, Reason ); |
|
383 } |
|
384 // |
|
385 return ret.ToString(); |
|
386 } |
|
387 #endregion |
|
388 |
|
389 #region Data members |
|
390 private int iReason = 0; |
|
391 private string iCategory = string.Empty; |
|
392 private bool iTypeWasExplicitlySet = false; |
|
393 private TExitType iType = TExitType.EExitTypePending; |
|
394 #endregion |
|
395 } |
|
396 } |