|
1 /* |
|
2 * Copyright (c) 2004-2008 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 |
|
18 using System; |
|
19 using System.Collections.Generic; |
|
20 using CrashDebuggerLib.Structures.Chunk; |
|
21 using CrashDebuggerLib.Structures.CodeSeg; |
|
22 using CrashDebuggerLib.Structures.Cpu; |
|
23 using CrashDebuggerLib.Structures.DebugMask; |
|
24 using CrashDebuggerLib.Structures.Fault; |
|
25 using CrashDebuggerLib.Structures.KernelObjects; |
|
26 using CrashDebuggerLib.Structures.Library; |
|
27 using CrashDebuggerLib.Structures.Process; |
|
28 using CrashDebuggerLib.Structures.Scheduler; |
|
29 using CrashDebuggerLib.Structures.Thread; |
|
30 using CrashDebuggerLib.Structures.UserContextTable; |
|
31 using CrashDebuggerLib.Threading; |
|
32 using SymbianDebugLib.Engine; |
|
33 using SymbianStructuresLib.Debug.Symbols; |
|
34 using SymbianUtils; |
|
35 |
|
36 namespace CrashDebuggerLib.Structures |
|
37 { |
|
38 public class CrashDebuggerInfo : DisposableObject, IEnumerable<DObjectCon> |
|
39 { |
|
40 #region Constructors |
|
41 public CrashDebuggerInfo( DbgEngine aDebugEngine ) |
|
42 { |
|
43 iDebugEngine = aDebugEngine; |
|
44 iDebugEngineView = aDebugEngine.CreateView( "CrashDebugger" ); |
|
45 // |
|
46 iTheCurrentProcess = new DProcess( this ); |
|
47 iTheCurrentThread = new DThread( this ); |
|
48 iCodeSegs = new CodeSegCollection( this ); |
|
49 iInfoCpu = new CpuInfo( this ); |
|
50 iInfoFault = new FaultInfo( this ); |
|
51 iInfoScheduler = new SchedulerInfo( this ); |
|
52 iInfoDebugMask = new DebugMaskInfo( this ); |
|
53 // |
|
54 MakeEmptyContainers(); |
|
55 } |
|
56 #endregion |
|
57 |
|
58 #region API |
|
59 public void Clear() |
|
60 { |
|
61 iTheCurrentProcess = new DProcess( this ); |
|
62 iTheCurrentThread = new DThread( this ); |
|
63 iCodeSegs.Clear(); |
|
64 iInfoCpu.Clear(); |
|
65 iInfoFault.Clear(); |
|
66 iInfoScheduler.Clear(); |
|
67 iInfoDebugMask.Clear(); |
|
68 |
|
69 iUserContextTableManager = new UserContextTableManager(); |
|
70 iAsyncOperationManager.Clear(); |
|
71 |
|
72 MakeEmptyContainers(); |
|
73 } |
|
74 |
|
75 public DObjectCon ContainerByType( DObject.TObjectType aType ) |
|
76 { |
|
77 DObjectCon ret = null; |
|
78 // |
|
79 foreach ( DObjectCon container in iContainers ) |
|
80 { |
|
81 if ( container.Type == aType ) |
|
82 { |
|
83 ret = container; |
|
84 break; |
|
85 } |
|
86 } |
|
87 // |
|
88 if ( ret == null ) |
|
89 { |
|
90 throw new ArgumentException( "Bad container type: " + aType ); |
|
91 } |
|
92 // |
|
93 return ret; |
|
94 } |
|
95 |
|
96 public DObject ObjectByAddress( uint aAddress ) |
|
97 { |
|
98 DObject ret = null; |
|
99 // |
|
100 foreach ( DObjectCon container in iContainers ) |
|
101 { |
|
102 DObject conObject = container[ aAddress ]; |
|
103 if ( conObject != null ) |
|
104 { |
|
105 ret = conObject; |
|
106 break; |
|
107 } |
|
108 } |
|
109 // |
|
110 return ret; |
|
111 } |
|
112 |
|
113 public DThread ThreadByAddress( uint aAddress ) |
|
114 { |
|
115 DObjectCon con = ContainerByType( DObject.TObjectType.EThread ); |
|
116 DObject ret = con[ aAddress ]; |
|
117 return ( ret != null )? ret as DThread : null; |
|
118 } |
|
119 |
|
120 public DProcess ProcessByAddress( uint aAddress ) |
|
121 { |
|
122 DObjectCon con = ContainerByType( DObject.TObjectType.EProcess ); |
|
123 DObject ret = con[ aAddress ]; |
|
124 return ( ret != null ) ? ret as DProcess : null; |
|
125 } |
|
126 |
|
127 public DChunk ChunkByAddress( uint aAddress ) |
|
128 { |
|
129 DObjectCon con = ContainerByType( DObject.TObjectType.EChunk ); |
|
130 DObject ret = con[ aAddress ]; |
|
131 return ( ret != null ) ? ret as DChunk : null; |
|
132 } |
|
133 |
|
134 public DLibrary LibraryByAddress( uint aAddress ) |
|
135 { |
|
136 DObjectCon con = ContainerByType( DObject.TObjectType.ELibrary ); |
|
137 DObject ret = con[ aAddress ]; |
|
138 return ( ret != null ) ? ret as DLibrary : null; |
|
139 } |
|
140 |
|
141 public CodeSegEntry CodeSegByAddress( uint aAddress ) |
|
142 { |
|
143 return iCodeSegs[ aAddress ]; |
|
144 } |
|
145 #endregion |
|
146 |
|
147 #region Properties |
|
148 public DProcess TheCurrentProcess |
|
149 { |
|
150 get { return iTheCurrentProcess; } |
|
151 } |
|
152 |
|
153 public DThread TheCurrentThread |
|
154 { |
|
155 get { return iTheCurrentThread; } |
|
156 } |
|
157 |
|
158 public CpuInfo InfoCpu |
|
159 { |
|
160 get { return iInfoCpu; } |
|
161 } |
|
162 |
|
163 public FaultInfo InfoFault |
|
164 { |
|
165 get { return iInfoFault; } |
|
166 } |
|
167 |
|
168 public SchedulerInfo InfoScheduler |
|
169 { |
|
170 get { return iInfoScheduler; } |
|
171 } |
|
172 |
|
173 public DebugMaskInfo InfoDebugMask |
|
174 { |
|
175 get { return iInfoDebugMask; } |
|
176 } |
|
177 |
|
178 public CodeSegCollection CodeSegs |
|
179 { |
|
180 get { return iCodeSegs; } |
|
181 } |
|
182 |
|
183 public DObjectCon this[ DObject.TObjectType aType ] |
|
184 { |
|
185 get |
|
186 { |
|
187 return ContainerByType( aType ); |
|
188 } |
|
189 } |
|
190 |
|
191 public DbgEngine DebugEngine |
|
192 { |
|
193 get { return iDebugEngine; } |
|
194 } |
|
195 #endregion |
|
196 |
|
197 #region Internal methods |
|
198 internal UserContextTableManager UserContextTableManager |
|
199 { |
|
200 get { return iUserContextTableManager; } |
|
201 } |
|
202 |
|
203 internal Symbol LookUpSymbol( uint aAddress ) |
|
204 { |
|
205 Symbol symbol = null; |
|
206 // |
|
207 if ( iDebugEngineView != null ) |
|
208 { |
|
209 symbol = iDebugEngineView.Symbols[ aAddress ]; |
|
210 } |
|
211 // |
|
212 return symbol; |
|
213 } |
|
214 |
|
215 internal AsyncOperationManager AsyncOperationManager |
|
216 { |
|
217 get { return iAsyncOperationManager; } |
|
218 } |
|
219 |
|
220 internal bool IsCurrentThread( DThread aThread ) |
|
221 { |
|
222 return ( aThread.KernelAddress == TheCurrentThread.KernelAddress && TheCurrentThread.KernelAddress != 0 ); |
|
223 } |
|
224 |
|
225 internal bool IsCurrentProcess( DProcess aProcess ) |
|
226 { |
|
227 return ( aProcess.KernelAddress == TheCurrentProcess.KernelAddress && TheCurrentProcess.KernelAddress != 0 ); |
|
228 } |
|
229 |
|
230 private void MakeEmptyContainers() |
|
231 { |
|
232 iContainers.Clear(); |
|
233 // |
|
234 for ( int i = 0; i < (int) DObject.TObjectType.ENumObjectTypes; i++ ) |
|
235 { |
|
236 DObject.TObjectType type = (DObject.TObjectType) i; |
|
237 DObjectCon container = new DObjectCon( this, type ); |
|
238 iContainers.Add( container ); |
|
239 } |
|
240 } |
|
241 #endregion |
|
242 |
|
243 #region Internal constants |
|
244 #endregion |
|
245 |
|
246 #region From System.Object |
|
247 public override string ToString() |
|
248 { |
|
249 return base.ToString(); |
|
250 } |
|
251 #endregion |
|
252 |
|
253 #region From DisposableObject |
|
254 protected override void CleanupManagedResources() |
|
255 { |
|
256 try |
|
257 { |
|
258 base.CleanupManagedResources(); |
|
259 } |
|
260 finally |
|
261 { |
|
262 if ( iDebugEngineView != null ) |
|
263 { |
|
264 iDebugEngineView.Dispose(); |
|
265 iDebugEngineView = null; |
|
266 } |
|
267 } |
|
268 } |
|
269 #endregion |
|
270 |
|
271 #region From IEnumerable<DObjectCon> |
|
272 public IEnumerator<DObjectCon> GetEnumerator() |
|
273 { |
|
274 foreach ( DObjectCon entry in iContainers ) |
|
275 { |
|
276 yield return entry; |
|
277 } |
|
278 } |
|
279 |
|
280 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
281 { |
|
282 foreach ( DObjectCon entry in iContainers ) |
|
283 { |
|
284 yield return entry; |
|
285 } |
|
286 } |
|
287 #endregion |
|
288 |
|
289 #region Data members |
|
290 private DbgEngineView iDebugEngineView; |
|
291 private DProcess iTheCurrentProcess; |
|
292 private DThread iTheCurrentThread; |
|
293 private readonly CodeSegCollection iCodeSegs; |
|
294 private readonly CpuInfo iInfoCpu; |
|
295 private readonly FaultInfo iInfoFault; |
|
296 private readonly SchedulerInfo iInfoScheduler; |
|
297 private readonly DebugMaskInfo iInfoDebugMask; |
|
298 private readonly DbgEngine iDebugEngine; |
|
299 private List<DObjectCon> iContainers = new List<DObjectCon>(); |
|
300 private UserContextTableManager iUserContextTableManager = new UserContextTableManager(); |
|
301 private AsyncOperationManager iAsyncOperationManager = new AsyncOperationManager(); |
|
302 #endregion |
|
303 } |
|
304 } |