|
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.Collections; |
|
19 using System.IO; |
|
20 using SymbianUtils; |
|
21 using SymbianUtils.Tracer; |
|
22 using SymbolLib.Generics; |
|
23 using SymbolLib.Sources.Map.File; |
|
24 using SymbolLib.Sources.Map.Symbol; |
|
25 using SymbolLib.Sources.Map.Engine; |
|
26 |
|
27 namespace SymbolLib.Sources.Map.Parser |
|
28 { |
|
29 #region SymbolEntryCreator interface |
|
30 internal interface SymbolEntryCreator |
|
31 { |
|
32 MapSymbol CreateSymbol(); |
|
33 } |
|
34 #endregion |
|
35 |
|
36 internal class MapFileParser : AsyncTextFileReader |
|
37 { |
|
38 #region Delegates & events |
|
39 public delegate void SymbolCreatedHandler( MapSymbol aSymbol ); |
|
40 public event SymbolCreatedHandler SymbolCreated; |
|
41 |
|
42 public delegate void MapFileBaseAddressHandler( uint aBaseAddress ); |
|
43 public event MapFileBaseAddressHandler BaseAddressHandler; |
|
44 #endregion |
|
45 |
|
46 #region Constructors & destructor |
|
47 public MapFileParser( SymbolEntryCreator aEntryCreator, string aMapFileName, ITracer aTracer ) |
|
48 : base( aMapFileName, aTracer ) |
|
49 { |
|
50 iEntryCreator = aEntryCreator; |
|
51 } |
|
52 #endregion |
|
53 |
|
54 #region API |
|
55 public void Read( TSynchronicity aSynchronicity ) |
|
56 { |
|
57 base.StartRead( aSynchronicity ); |
|
58 } |
|
59 #endregion |
|
60 |
|
61 #region Properties |
|
62 #endregion |
|
63 |
|
64 #region From AsyncTextReaderBase |
|
65 protected override void HandleFilteredLine( string aLine ) |
|
66 { |
|
67 if ( aLine == "Global Symbols" ) |
|
68 { |
|
69 iState = TState.EInGlobalRegion; |
|
70 } |
|
71 else if ( aLine == "Local Symbols" ) |
|
72 { |
|
73 iState = TState.EInLocalRegion; |
|
74 } |
|
75 else |
|
76 { |
|
77 switch( iState ) |
|
78 { |
|
79 case TState.EInUnknownRegion: |
|
80 break; |
|
81 case TState.EInLocalRegion: |
|
82 ParseLineRegionLocal( aLine ); |
|
83 break; |
|
84 case TState.EInGlobalRegion: |
|
85 ParseLineRegionGlobal( aLine ); |
|
86 break; |
|
87 case TState.EComplete: |
|
88 System.Diagnostics.Debug.Assert(false); |
|
89 break; |
|
90 } |
|
91 } |
|
92 } |
|
93 #endregion |
|
94 |
|
95 #region Local & global (high level) line handlers |
|
96 private void ParseLineRegionLocal( string aLine ) |
|
97 { |
|
98 } |
|
99 |
|
100 private void ParseLineRegionGlobal( string aLine ) |
|
101 { |
|
102 switch( iStateGlobal ) |
|
103 { |
|
104 case TGlobalState.EWaitingForImage_ER_RO_Base: |
|
105 ParseGlobalBaseAddress( aLine ); |
|
106 break; |
|
107 case TGlobalState.EProcessingSymbols: |
|
108 ParseGlobalSymbol( aLine ); |
|
109 break; |
|
110 default: |
|
111 break; |
|
112 } |
|
113 } |
|
114 #endregion |
|
115 |
|
116 #region Global section line parse methods |
|
117 private void ParseGlobalBaseAddress( string aLine ) |
|
118 { |
|
119 try |
|
120 { |
|
121 // Image$$ER_RO$$Base 0x00008000 Number 0 anon$$obj.o(linker$$defined$$symbols) |
|
122 MapSymbol baseOffsetEntry = iEntryCreator.CreateSymbol(); |
|
123 |
|
124 // Keep trying to parse until we are successful. First time we succeed |
|
125 // we use the symbol address as the global offset address within the map |
|
126 // file (typically 0x8000) |
|
127 bool parsedOkay = baseOffsetEntry.Parse( aLine ); |
|
128 if ( parsedOkay && baseOffsetEntry.Address > 0 && BaseAddressHandler != null ) |
|
129 { |
|
130 BaseAddressHandler( (uint) baseOffsetEntry.Address ); |
|
131 iStateGlobal = TGlobalState.EProcessingSymbols; |
|
132 } |
|
133 } |
|
134 catch(GenericSymbolicCreationException) |
|
135 { |
|
136 } |
|
137 } |
|
138 |
|
139 private void ParseGlobalSymbol( string aLine ) |
|
140 { |
|
141 try |
|
142 { |
|
143 // Image$$ER_RO$$Base 0x00008000 Number 0 anon$$obj.o(linker$$defined$$symbols) |
|
144 MapSymbol symbol = iEntryCreator.CreateSymbol(); |
|
145 bool parsedOkay = symbol.Parse( aLine ); |
|
146 if ( parsedOkay && SymbolCreated != null ) |
|
147 { |
|
148 SymbolCreated( symbol ); |
|
149 } |
|
150 } |
|
151 catch(GenericSymbolicCreationException) |
|
152 { |
|
153 } |
|
154 } |
|
155 #endregion |
|
156 |
|
157 #region Internal enumerations |
|
158 private enum TState |
|
159 { |
|
160 EInUnknownRegion = 0, |
|
161 EInLocalRegion, |
|
162 EInGlobalRegion, |
|
163 EComplete |
|
164 } |
|
165 |
|
166 private enum TGlobalState |
|
167 { |
|
168 EWaitingForImage_ER_RO_Base = 0, |
|
169 EProcessingSymbols |
|
170 } |
|
171 #endregion |
|
172 |
|
173 #region Data members |
|
174 private readonly SymbolEntryCreator iEntryCreator; |
|
175 private TState iState = TState.EInUnknownRegion; |
|
176 private TGlobalState iStateGlobal = TGlobalState.EWaitingForImage_ER_RO_Base; |
|
177 #endregion |
|
178 } |
|
179 } |