|
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; |
|
20 using System.Collections.Generic; |
|
21 using SymbolLib.CodeSegDef; |
|
22 using SymbolLib.Generics; |
|
23 using SymbolLib.Sources.Map.Symbol; |
|
24 using SymbianUtils.Range; |
|
25 |
|
26 namespace SymbolLib.Sources.Map.File |
|
27 { |
|
28 internal class MapFile : GenericSymbolCollection |
|
29 { |
|
30 #region Static constructors |
|
31 public static MapFile NewByHostMapFileName( string aMapFileNameAndPath ) |
|
32 { |
|
33 // The specified file should end in .map |
|
34 System.Diagnostics.Debug.Assert( aMapFileNameAndPath.ToUpper().EndsWith( ".MAP" ) ); |
|
35 |
|
36 // Get rid of map file extension. |
|
37 string binaryFileName = aMapFileNameAndPath.Substring( 0, aMapFileNameAndPath.Length - 4 ); |
|
38 MapFile ret = new MapFile( binaryFileName, aMapFileNameAndPath ); |
|
39 return ret; |
|
40 } |
|
41 |
|
42 #endregion |
|
43 |
|
44 #region Constructors |
|
45 private MapFile( string aHostBinaryName, string aHostMapFileName ) |
|
46 : base( aHostBinaryName ) |
|
47 { |
|
48 base.SourceFile = aHostMapFileName; |
|
49 |
|
50 // Make the dummy entry in case we obtain no further symbols |
|
51 MapSymbol dummy = MapSymbol.NewUnknown( this ); |
|
52 iEntries.Add( dummy ); |
|
53 } |
|
54 #endregion |
|
55 |
|
56 #region API |
|
57 public void EnsureAllEntriesHaveSize() |
|
58 { |
|
59 int count = Count; |
|
60 |
|
61 #if DEBUG |
|
62 // Debug support |
|
63 int x = 0; |
|
64 if ( x != 0 ) |
|
65 { |
|
66 string line = string.Empty; |
|
67 for ( int i = 0; i < count; i++ ) |
|
68 { |
|
69 GenericSymbol entry = iEntries[ i ]; |
|
70 line = i.ToString( "d8" ) + " [" + entry.Address.ToString( "x8" ) + "-" + entry.EndAddress.ToString( "x8" ) + "] " + entry.Symbol.ToString(); |
|
71 System.Diagnostics.Debug.WriteLine( line ); |
|
72 } |
|
73 } |
|
74 #endif |
|
75 |
|
76 // Now go through the entries and update their sizes (if they don't have one) |
|
77 for ( int i = 1; i < count; i++ ) |
|
78 { |
|
79 GenericSymbol entry = iEntries[ i ]; |
|
80 GenericSymbol previousEntry = iEntries[ i - 1 ]; |
|
81 // |
|
82 if ( previousEntry.Size == 0 ) |
|
83 { |
|
84 long calculatedPreviousEntrySize = ( entry.Address - previousEntry.Address ) - 1; |
|
85 if ( calculatedPreviousEntrySize > 0 ) |
|
86 { |
|
87 previousEntry.Size = calculatedPreviousEntrySize; |
|
88 } |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 public void Fixup( CodeSegDefinition aDefinition ) |
|
94 { |
|
95 // Work out base address offset based upon global address and code segment |
|
96 // placement address. |
|
97 uint baseAddress = aDefinition.AddressStart; |
|
98 BaseAddress = baseAddress; |
|
99 iFixedUpRange = aDefinition.AddressRange; |
|
100 |
|
101 base.RebuildAddressRange(); |
|
102 } |
|
103 #endregion |
|
104 |
|
105 #region Properties |
|
106 public override AddressRange AddressRange |
|
107 { |
|
108 get { return iFixedUpRange; } |
|
109 } |
|
110 |
|
111 internal uint GlobalBaseAddress |
|
112 { |
|
113 get { return iGlobalBaseAddress; } |
|
114 set |
|
115 { |
|
116 iGlobalBaseAddress = value; |
|
117 } |
|
118 } |
|
119 #endregion |
|
120 |
|
121 #region From GenericSymbolCollection |
|
122 public override void Add( GenericSymbolEngine aEngine, GenericSymbol aSymbol ) |
|
123 { |
|
124 // We don't take data symbols, just code |
|
125 MapSymbol symbol = (MapSymbol) aSymbol; |
|
126 MapSymbol.TType type = symbol.Type; |
|
127 |
|
128 if ( type == MapSymbol.TType.EThumbCode || type == MapSymbol.TType.EARMCode ) |
|
129 { |
|
130 // Don't take code entries with no size |
|
131 if ( aSymbol.Size > 0 ) |
|
132 { |
|
133 // Make sure we remove the null symbol if this is the first 'valid' symbol for |
|
134 // the collection. |
|
135 if ( Count == 1 && this[ 0 ].IsUnknownSymbol ) |
|
136 { |
|
137 RemoveAt( 0 ); |
|
138 } |
|
139 |
|
140 iEntries.Add( aSymbol ); |
|
141 } |
|
142 else |
|
143 { |
|
144 #if TRACE |
|
145 System.Diagnostics.Debug.WriteLine( "Discarding zero size entry: " + aSymbol.ToString() ); |
|
146 #endif |
|
147 } |
|
148 } |
|
149 } |
|
150 |
|
151 public override void Remove( GenericSymbol aSymbol ) |
|
152 { |
|
153 iEntries.Remove( aSymbol ); |
|
154 } |
|
155 |
|
156 public override void RemoveAt( int aIndex ) |
|
157 { |
|
158 iEntries.RemoveAt( aIndex ); |
|
159 } |
|
160 |
|
161 public override void Sort() |
|
162 { |
|
163 iEntries.Sort( new GenericSymbolComparer() ); |
|
164 } |
|
165 |
|
166 public override int Count |
|
167 { |
|
168 get { return iEntries.Count; } |
|
169 } |
|
170 |
|
171 public override System.Collections.IEnumerator CreateEnumerator() |
|
172 { |
|
173 return new MapFileEnumerator( this ); |
|
174 } |
|
175 |
|
176 public override System.Collections.Generic.IEnumerator<GenericSymbol> CreateGenericEnumerator() |
|
177 { |
|
178 return new MapFileEnumerator( this ); |
|
179 } |
|
180 |
|
181 public override GenericSymbol this[ int aIndex ] |
|
182 { |
|
183 get |
|
184 { |
|
185 return iEntries[ aIndex ]; |
|
186 } |
|
187 } |
|
188 |
|
189 public override long AddressRangeStart |
|
190 { |
|
191 get { return iFixedUpRange.Min; } |
|
192 } |
|
193 |
|
194 public override long AddressRangeEnd |
|
195 { |
|
196 get { return iFixedUpRange.Max; } |
|
197 } |
|
198 |
|
199 public override GenericSymbol SymbolForAddress( long aAddress ) |
|
200 { |
|
201 #if DEBUG |
|
202 int x = 0; |
|
203 if ( x > 0 ) |
|
204 { |
|
205 base.Dump( aAddress ); |
|
206 } |
|
207 #endif |
|
208 GenericSymbol ret = null; |
|
209 // |
|
210 foreach ( GenericSymbol symbol in this ) |
|
211 { |
|
212 if ( symbol.FallsWithinDomain( aAddress ) ) |
|
213 { |
|
214 ret = symbol; |
|
215 break; |
|
216 } |
|
217 } |
|
218 // |
|
219 return ret; |
|
220 } |
|
221 #endregion |
|
222 |
|
223 #region From System.Object |
|
224 public override string ToString() |
|
225 { |
|
226 StringBuilder ret = new StringBuilder(); |
|
227 ret.Append( iFixedUpRange.ToString() ); |
|
228 return ret.ToString(); |
|
229 } |
|
230 #endregion |
|
231 |
|
232 #region Data members |
|
233 private uint iGlobalBaseAddress = 0; |
|
234 private AddressRange iFixedUpRange = new AddressRange(); |
|
235 private List<GenericSymbol> iEntries = new List<GenericSymbol>( 50 ); |
|
236 #endregion |
|
237 } |
|
238 } |