|
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.Registers; |
|
24 using CrashItemLib.Crash.Container; |
|
25 using CrashItemLib.Crash.Threads; |
|
26 using CrashItemLib.Crash.Processes; |
|
27 using SymbianStructuresLib.Arm.Registers; |
|
28 |
|
29 namespace CrashItemLib.Crash.Registers |
|
30 { |
|
31 #region Attributes |
|
32 [CIDBAttributeColumn( "Name", 0 )] |
|
33 [CIDBAttributeColumn( "Value", 1 )] |
|
34 [CIDBAttributeColumn( "Symbol", 2, true )] |
|
35 #endregion |
|
36 public class CIRegisterList : CIElement, IARCBackingStore, IEnumerable<CIRegister> |
|
37 { |
|
38 #region Constructors |
|
39 public CIRegisterList( CIContainer aContainer, TArmRegisterBank aBank ) |
|
40 : base( aContainer ) |
|
41 { |
|
42 iCollection = new ArmRegisterCollection( aBank ); |
|
43 iCollection.Tag = this; |
|
44 iCollection.BackingStore = this; |
|
45 |
|
46 // Restrict children |
|
47 base.AddSupportedChildType( typeof( CIRegister ) ); |
|
48 base.AddSupportedChildType( typeof( CrashItemLib.Crash.Messages.CIMessage ) ); |
|
49 } |
|
50 |
|
51 /// <summary> |
|
52 /// Internal constructor called by CIRegisterListForThread which sets a thread up as a parent |
|
53 /// of the register list. |
|
54 /// </summary> |
|
55 internal CIRegisterList( CIContainer aContainer, CIElement aParent, TArmRegisterBank aBank ) |
|
56 : base( aContainer, aParent ) |
|
57 { |
|
58 iCollection = new ArmRegisterCollection( aBank ); |
|
59 iCollection.Tag = this; |
|
60 iCollection.BackingStore = this; |
|
61 |
|
62 // Restrict children |
|
63 base.AddSupportedChildType( typeof( CIRegister ) ); |
|
64 base.AddSupportedChildType( typeof( CrashItemLib.Crash.Messages.CIMessage ) ); |
|
65 } |
|
66 #endregion |
|
67 |
|
68 #region API |
|
69 public CIRegister Add( TArmRegisterType aType, uint aValue ) |
|
70 { |
|
71 // Will cause a call back to create the entries in iRegisters... |
|
72 ArmRegister entry = iCollection.Add( aType, aValue ); |
|
73 // |
|
74 System.Diagnostics.Debug.Assert( entry.Tag != null && entry.Tag is CIRegister ); |
|
75 System.Diagnostics.Debug.Assert( iCollection.Count == base.Count ); |
|
76 // |
|
77 CIRegister ret = (CIRegister) entry.Tag; |
|
78 return ret; |
|
79 } |
|
80 |
|
81 public void Add( ArmRegisterCollection aArmRegisterCollection ) |
|
82 { |
|
83 // Will cause a call back to create the entries in iRegisters... |
|
84 iCollection.Copy( aArmRegisterCollection ); |
|
85 System.Diagnostics.Debug.Assert( iCollection.Count == base.Count ); |
|
86 } |
|
87 |
|
88 public bool Contains( TArmRegisterType aType ) |
|
89 { |
|
90 System.Diagnostics.Debug.Assert( iCollection.Count == base.Count ); |
|
91 return iCollection.Contains( aType ); |
|
92 } |
|
93 |
|
94 public void Remove( TArmRegisterType aType ) |
|
95 { |
|
96 iCollection.Remove( aType ); |
|
97 } |
|
98 |
|
99 public override void Clear() |
|
100 { |
|
101 // This calls IARCBackingStore.ARCBSClear(), which in turn calls base.Clear(). |
|
102 iCollection.Clear(); |
|
103 } |
|
104 #endregion |
|
105 |
|
106 #region Properties |
|
107 public override int Count |
|
108 { |
|
109 get |
|
110 { |
|
111 int ret = base.Count; |
|
112 System.Diagnostics.Debug.Assert( iCollection.Count == ret ); |
|
113 return iCollection.Count; |
|
114 } |
|
115 } |
|
116 |
|
117 public bool IsCurrentProcessorMode |
|
118 { |
|
119 get |
|
120 { |
|
121 bool ret = false; |
|
122 // |
|
123 if ( Contains( TArmRegisterType.EArmReg_CPSR ) ) |
|
124 { |
|
125 CIRegister cpsr = this[ TArmRegisterType.EArmReg_CPSR ]; |
|
126 TArmRegisterBank currentBank = ArmRegisterBankUtils.ExtractBank( cpsr.Value ); |
|
127 // |
|
128 ret = ( currentBank == Bank ); |
|
129 } |
|
130 // |
|
131 return ret; |
|
132 } |
|
133 } |
|
134 |
|
135 public override string Name |
|
136 { |
|
137 get { return BankName; } |
|
138 } |
|
139 |
|
140 public TArmRegisterBank Bank |
|
141 { |
|
142 get { return iCollection.Bank; } |
|
143 } |
|
144 |
|
145 public string BankName |
|
146 { |
|
147 get { return ArmRegisterBankUtils.BankAsStringLong( Bank ); } |
|
148 } |
|
149 |
|
150 public string BankAbbreviation |
|
151 { |
|
152 get { return ArmRegisterBankUtils.BankAsString( Bank ); } |
|
153 } |
|
154 |
|
155 public CIThread OwningThread |
|
156 { |
|
157 get |
|
158 { |
|
159 CIThread ret = base.Parent as CIThread; |
|
160 return ret; |
|
161 } |
|
162 } |
|
163 |
|
164 public CIProcess OwningProcess |
|
165 { |
|
166 get |
|
167 { |
|
168 CIProcess ret = null; |
|
169 // |
|
170 if ( OwningThread != null ) |
|
171 { |
|
172 ret = OwningThread.OwningProcess; |
|
173 } |
|
174 // |
|
175 return ret; |
|
176 } |
|
177 } |
|
178 |
|
179 public CIRegister[] Registers |
|
180 { |
|
181 get |
|
182 { |
|
183 CIElementList<CIRegister> registers = base.ChildrenByType<CIRegister>(); |
|
184 return registers.ToArray(); |
|
185 } |
|
186 } |
|
187 |
|
188 public CIRegister this[ TArmRegisterType aType ] |
|
189 { |
|
190 get |
|
191 { |
|
192 System.Diagnostics.Debug.Assert( iCollection.Count == base.Count ); |
|
193 ArmRegister reg = iCollection[ aType ]; |
|
194 System.Diagnostics.Debug.Assert( reg.Tag != null && reg.Tag is CIRegister ); |
|
195 CIRegister ret = (CIRegister) reg.Tag; |
|
196 return ret; |
|
197 } |
|
198 } |
|
199 |
|
200 public CIRegister this[ string aName ] |
|
201 { |
|
202 get |
|
203 { |
|
204 System.Diagnostics.Debug.Assert( iCollection.Count == base.Count ); |
|
205 ArmRegister reg = iCollection[ aName ]; |
|
206 CIRegister ret = (CIRegister) reg.Tag; |
|
207 return ret; |
|
208 } |
|
209 } |
|
210 #endregion |
|
211 |
|
212 #region Operators |
|
213 public static implicit operator ArmRegisterCollection( CIRegisterList aSelf ) |
|
214 { |
|
215 return aSelf.Collection; |
|
216 } |
|
217 #endregion |
|
218 |
|
219 #region Internal methods |
|
220 internal ArmRegisterCollection Collection |
|
221 { |
|
222 get { return iCollection; } |
|
223 } |
|
224 #endregion |
|
225 |
|
226 #region IARCBackingStore Members |
|
227 void IARCBackingStore.ARCBSClear() |
|
228 { |
|
229 base.Clear(); |
|
230 } |
|
231 |
|
232 ArmRegister IARCBackingStore.ARCBSCreate( TArmRegisterType aType, string aName, uint aValue ) |
|
233 { |
|
234 // Go via factory to deal with special registers... |
|
235 CIRegister reg = Factory.CIRegisterFactory.New( aType, aValue, aName, this ); |
|
236 base.AddChild( reg ); |
|
237 |
|
238 // Set up two-way association |
|
239 ArmRegister ret = reg.Register; |
|
240 ret.Tag = reg; |
|
241 return ret; |
|
242 } |
|
243 |
|
244 void IARCBackingStore.ARCBSRemove( ArmRegister aRegister ) |
|
245 { |
|
246 CIRegister reg = aRegister.Tag as CIRegister; |
|
247 if ( reg != null ) |
|
248 { |
|
249 base.RemoveChild( reg ); |
|
250 } |
|
251 } |
|
252 #endregion |
|
253 |
|
254 #region From IEnumerable<CIRegister> |
|
255 public new IEnumerator<CIRegister> GetEnumerator() |
|
256 { |
|
257 foreach ( CIElement element in base.Children ) |
|
258 { |
|
259 if ( element is CIRegister ) |
|
260 { |
|
261 CIRegister reg = (CIRegister) element; |
|
262 yield return reg; |
|
263 } |
|
264 } |
|
265 } |
|
266 |
|
267 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
268 { |
|
269 foreach ( CIElement element in base.Children ) |
|
270 { |
|
271 if ( element is CIRegister ) |
|
272 { |
|
273 CIRegister reg = (CIRegister) element; |
|
274 yield return reg; |
|
275 } |
|
276 } |
|
277 } |
|
278 #endregion |
|
279 |
|
280 #region From System.Object |
|
281 public override string ToString() |
|
282 { |
|
283 return ArmRegisterBankUtils.BankAsString( Bank ); |
|
284 } |
|
285 #endregion |
|
286 |
|
287 #region From CIElement |
|
288 public override void PrepareRows() |
|
289 { |
|
290 DataBindingModel.ClearRows(); |
|
291 |
|
292 // Our data binding model is based upon the register object, rather |
|
293 // than any key-value-pair properties. |
|
294 foreach ( CIRegister reg in this ) |
|
295 { |
|
296 DataBindingModel.Add( reg ); |
|
297 } |
|
298 } |
|
299 #endregion |
|
300 |
|
301 #region Data members |
|
302 private readonly ArmRegisterCollection iCollection; |
|
303 #endregion |
|
304 } |
|
305 } |