|
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.IO; |
|
19 using System.Collections; |
|
20 using System.Collections.Generic; |
|
21 using SymbolLib.Utils; |
|
22 using SymbianUtils.Range; |
|
23 |
|
24 namespace SymbolLib.Generics |
|
25 { |
|
26 public abstract class GenericSymbolCollection : IEnumerable<GenericSymbol>, IComparable<GenericSymbolCollection> |
|
27 { |
|
28 #region Construct & destruct |
|
29 protected GenericSymbolCollection( string aHostBinaryFileName ) |
|
30 { |
|
31 HostBinaryFileName = aHostBinaryFileName; |
|
32 } |
|
33 #endregion |
|
34 |
|
35 #region Virtual API |
|
36 public virtual void ClearTag() |
|
37 { |
|
38 Tagged = false; |
|
39 } |
|
40 |
|
41 public virtual void WriteToStream( StreamWriter aWriter ) |
|
42 { |
|
43 // First write the binary name |
|
44 aWriter.WriteLine( string.Empty ); |
|
45 aWriter.WriteLine( "From " + HostBinaryFileName ); |
|
46 aWriter.WriteLine( string.Empty ); |
|
47 |
|
48 foreach ( GenericSymbol symbol in this ) |
|
49 { |
|
50 aWriter.WriteLine( symbol.ToStringForStream() ); |
|
51 } |
|
52 } |
|
53 #endregion |
|
54 |
|
55 #region Abstract API - methods |
|
56 public abstract void Add( GenericSymbolEngine aEngine, GenericSymbol aSymbol ); |
|
57 |
|
58 public abstract void Remove( GenericSymbol aSymbol ); |
|
59 |
|
60 public abstract void RemoveAt( int aIndex ); |
|
61 |
|
62 public abstract IEnumerator CreateEnumerator(); |
|
63 |
|
64 public abstract IEnumerator<GenericSymbol> CreateGenericEnumerator(); |
|
65 |
|
66 public abstract GenericSymbol SymbolForAddress( long aAddress ); |
|
67 #endregion |
|
68 |
|
69 #region Abstract API - properties |
|
70 public abstract int Count |
|
71 { |
|
72 get; |
|
73 } |
|
74 |
|
75 public abstract GenericSymbol this[ int aIndex ] |
|
76 { |
|
77 get; |
|
78 } |
|
79 |
|
80 public abstract void Sort(); |
|
81 #endregion |
|
82 |
|
83 #region API |
|
84 public bool AddressFallsWithinRange( long aAddress ) |
|
85 { |
|
86 bool found = false; |
|
87 // |
|
88 if ( this.Count == 1 && this[ 0 ].IsUnknownSymbol ) |
|
89 { |
|
90 int x = 0; |
|
91 x++; |
|
92 } |
|
93 |
|
94 if ( aAddress > 0 ) |
|
95 { |
|
96 if ( iAddresses == null ) |
|
97 { |
|
98 RebuildAddressRange(); |
|
99 } |
|
100 // |
|
101 found = iAddresses.IsWithinRange( aAddress ); |
|
102 } |
|
103 // |
|
104 return found; |
|
105 } |
|
106 |
|
107 #if DEBUG |
|
108 public void Dump() |
|
109 { |
|
110 int i = 0; |
|
111 string line = string.Empty; |
|
112 foreach ( GenericSymbol entry in this ) |
|
113 { |
|
114 line = i.ToString( "d8" ) + " [" + entry.Address.ToString( "x8" ) + "-" + entry.EndAddress.ToString( "x8" ) + "] " + entry.Symbol.ToString(); |
|
115 System.Diagnostics.Debug.WriteLine( line ); |
|
116 i++; |
|
117 } |
|
118 } |
|
119 |
|
120 public void Dump( long aAddress ) |
|
121 { |
|
122 int i = 0; |
|
123 string line = string.Empty; |
|
124 foreach ( GenericSymbol entry in this ) |
|
125 { |
|
126 if ( entry.FallsWithinDomain( aAddress ) ) |
|
127 { |
|
128 line = i.ToString( "d8" ) + " * [" + entry.Address.ToString( "x8" ) + "-" + entry.EndAddress.ToString( "x8" ) + "] " + entry.Symbol.ToString(); |
|
129 } |
|
130 else |
|
131 { |
|
132 line = i.ToString( "d8" ) + " [" + entry.Address.ToString( "x8" ) + "-" + entry.EndAddress.ToString( "x8" ) + "] " + entry.Symbol.ToString(); |
|
133 } |
|
134 System.Diagnostics.Debug.WriteLine( line ); |
|
135 i++; |
|
136 } |
|
137 } |
|
138 #endif |
|
139 #endregion |
|
140 |
|
141 #region Symbol Properties |
|
142 public GenericSymbol FirstSymbol |
|
143 { |
|
144 get |
|
145 { |
|
146 GenericSymbol ret = null; |
|
147 if ( Count > 0 ) |
|
148 { |
|
149 ret = this[ 0 ]; |
|
150 } |
|
151 return ret; |
|
152 } |
|
153 } |
|
154 |
|
155 public GenericSymbol LastSymbol |
|
156 { |
|
157 get |
|
158 { |
|
159 GenericSymbol ret = null; |
|
160 if ( Count > 0 ) |
|
161 { |
|
162 ret = this[ Count - 1 ]; |
|
163 } |
|
164 return ret; |
|
165 } |
|
166 } |
|
167 #endregion |
|
168 |
|
169 #region Misc Properties |
|
170 public bool Tagged |
|
171 { |
|
172 get { return iTagged; } |
|
173 set { iTagged = value; } |
|
174 } |
|
175 |
|
176 public long BaseAddress |
|
177 { |
|
178 get { return iBaseAddress; } |
|
179 internal set { iBaseAddress = value; } |
|
180 } |
|
181 |
|
182 public string HostBinaryFileName |
|
183 { |
|
184 get { return iHostBinaryFileName; } |
|
185 set |
|
186 { |
|
187 System.Diagnostics.Debug.Assert( !value.ToLower().Contains( ".map" ) ); |
|
188 iHostBinaryFileName = value; |
|
189 } |
|
190 } |
|
191 |
|
192 public bool HostBinaryExists |
|
193 { |
|
194 get { return File.Exists( HostBinaryFileName ); } |
|
195 } |
|
196 |
|
197 public virtual long AddressRangeStart |
|
198 { |
|
199 get |
|
200 { |
|
201 long ret = 0; |
|
202 // |
|
203 if ( Count > 0 ) |
|
204 { |
|
205 ret = FirstSymbol.Address; |
|
206 } |
|
207 // |
|
208 return ret; |
|
209 } |
|
210 } |
|
211 |
|
212 public virtual long AddressRangeEnd |
|
213 { |
|
214 get |
|
215 { |
|
216 long ret = 0xffffffff; |
|
217 // |
|
218 if ( Count > 0 ) |
|
219 { |
|
220 ret = LastSymbol.EndAddress; |
|
221 } |
|
222 // |
|
223 return ret; |
|
224 } |
|
225 } |
|
226 |
|
227 public virtual AddressRange AddressRange |
|
228 { |
|
229 get { return new AddressRange( AddressRangeStart, AddressRangeEnd ); } |
|
230 } |
|
231 |
|
232 public string SourceFile |
|
233 { |
|
234 get { return iSourceFile; } |
|
235 internal set { iSourceFile = value; } |
|
236 } |
|
237 #endregion |
|
238 |
|
239 #region Internal methods |
|
240 protected void RebuildAddressRange() |
|
241 { |
|
242 iAddresses = new SymbolAddressRange( this ); |
|
243 } |
|
244 #endregion |
|
245 |
|
246 #region From IEnumerable |
|
247 IEnumerator IEnumerable.GetEnumerator() |
|
248 { |
|
249 return CreateEnumerator(); |
|
250 } |
|
251 |
|
252 IEnumerator<GenericSymbol> IEnumerable<GenericSymbol>.GetEnumerator() |
|
253 { |
|
254 return CreateGenericEnumerator(); |
|
255 } |
|
256 #endregion |
|
257 |
|
258 #region From IComparable |
|
259 public int CompareTo( GenericSymbolCollection aOther ) |
|
260 { |
|
261 int ret = 1; |
|
262 // |
|
263 if ( aOther != null ) |
|
264 { |
|
265 ret = string.Compare( HostBinaryFileName, aOther.HostBinaryFileName, true ); |
|
266 // |
|
267 if ( aOther is GenericSymbolCollection ) |
|
268 { |
|
269 GenericSymbolCollection otherCol = (GenericSymbolCollection) aOther; |
|
270 // |
|
271 if ( BaseAddress == otherCol.BaseAddress ) |
|
272 { |
|
273 ret = 0; |
|
274 } |
|
275 else if ( BaseAddress > otherCol.BaseAddress ) |
|
276 { |
|
277 ret = 1; |
|
278 } |
|
279 else |
|
280 { |
|
281 ret = -1; |
|
282 } |
|
283 } |
|
284 } |
|
285 |
|
286 // Debug check |
|
287 if ( aOther == this ) |
|
288 { |
|
289 System.Diagnostics.Debug.Assert( ret == 0 ); |
|
290 } |
|
291 // |
|
292 return ret; |
|
293 } |
|
294 #endregion |
|
295 |
|
296 #region From System.Object |
|
297 public override string ToString() |
|
298 { |
|
299 return string.Format( "{0} {1}", AddressRange, iHostBinaryFileName ); |
|
300 } |
|
301 #endregion |
|
302 |
|
303 #region Data members |
|
304 private bool iTagged = false; |
|
305 private long iBaseAddress = 0; |
|
306 private string iHostBinaryFileName = string.Empty; |
|
307 private string iSourceFile = string.Empty; |
|
308 private SymbolAddressRange iAddresses = null; |
|
309 #endregion |
|
310 } |
|
311 } |