|
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.Text; |
|
20 using System.Text.RegularExpressions; |
|
21 using SymbolLib.Generics; |
|
22 using SymbolLib.Sources.Map.File; |
|
23 using SymbolLib.Sources.Map.Engine; |
|
24 |
|
25 namespace SymbolLib.Sources.Map.Symbol |
|
26 { |
|
27 internal class MapSymbol : GenericSymbol |
|
28 { |
|
29 #region Enumerations |
|
30 public enum TType |
|
31 { |
|
32 EUnknown = 0, |
|
33 EARMCode, |
|
34 EThumbCode, |
|
35 EData, |
|
36 ENumber, |
|
37 ESection |
|
38 } |
|
39 #endregion |
|
40 |
|
41 #region Static Constructors |
|
42 public static MapSymbol New( MapFile aFile ) |
|
43 { |
|
44 return new MapSymbol( aFile ); |
|
45 } |
|
46 |
|
47 public static MapSymbol NewUnknown( MapFile aFile ) |
|
48 { |
|
49 MapSymbol symbol = new MapSymbol( aFile ); |
|
50 // |
|
51 symbol.iType = TType.EARMCode; |
|
52 symbol.Size = 0; |
|
53 symbol.OffsetAddress = GenericSymbol.KNullEntryAddress; |
|
54 symbol.Symbol = GenericSymbol.KNonMatchingSymbolName; |
|
55 // |
|
56 if ( aFile.HostBinaryFileName.Length > 0 ) |
|
57 { |
|
58 symbol.Object = Path.GetFileName( aFile.HostBinaryFileName ); |
|
59 } |
|
60 else |
|
61 { |
|
62 symbol.Object = GenericSymbol.KNonMatchingObjectName; |
|
63 } |
|
64 // |
|
65 return symbol; |
|
66 } |
|
67 #endregion |
|
68 |
|
69 #region Constructors & destructor |
|
70 private MapSymbol( MapFile aFile ) |
|
71 : base( aFile ) |
|
72 { |
|
73 } |
|
74 #endregion |
|
75 |
|
76 #region Properties |
|
77 public TType Type |
|
78 { |
|
79 get { return iType; } |
|
80 private set { iType = value; } |
|
81 } |
|
82 #endregion |
|
83 |
|
84 #region From GenericSymbol |
|
85 public override bool Parse( string aLine ) |
|
86 { |
|
87 Match m = KMapParserRegex.Match( aLine ); |
|
88 if ( m.Success ) |
|
89 { |
|
90 GroupCollection groups = m.Groups; |
|
91 // |
|
92 uint globalBaseAddress = MapFile.GlobalBaseAddress; |
|
93 // |
|
94 Object = groups[ "Binary" ].Value; |
|
95 Type = TypeByString( groups[ "Type" ].Value ); |
|
96 Symbol = groups[ "Function" ].Value; |
|
97 OffsetAddress = long.Parse( groups[ "Address" ].Value, System.Globalization.NumberStyles.HexNumber ) - globalBaseAddress; |
|
98 Size = long.Parse( groups[ "Size" ].Value ); |
|
99 } |
|
100 // |
|
101 return m.Success; |
|
102 } |
|
103 |
|
104 public override TSourceType SourceType |
|
105 { |
|
106 get { return GenericSymbol.TSourceType.ESourceTypeFileMap; } |
|
107 } |
|
108 #endregion |
|
109 |
|
110 #region Internal constants |
|
111 private const string KDummySymbolName = "[Unknown Symbol]"; |
|
112 private static readonly Regex KMapParserRegex = new Regex( |
|
113 "(?:\\s*)(?<Function>.+?)(?:\\s+)0x(?<Address>[A-Fa-f0-9]{8})"+ |
|
114 "(?:\\s+)(?<Type>(?:Data|Section|Number|ARM Code|Thumb Code))"+ |
|
115 "(?:\\s+)(?<Size>\\d+)(?:\\s+)(?<Binary>.+)", |
|
116 RegexOptions.IgnoreCase |
|
117 | RegexOptions.Singleline |
|
118 ); |
|
119 #endregion |
|
120 |
|
121 #region Internal methods |
|
122 private static TType TypeByString( string aTypeAsString ) |
|
123 { |
|
124 TType ret = TType.EUnknown; |
|
125 // |
|
126 if ( aTypeAsString == "ARM Code" ) |
|
127 ret = TType.EARMCode; |
|
128 else if ( aTypeAsString == "Thumb Code" ) |
|
129 ret = TType.EThumbCode; |
|
130 else if ( aTypeAsString == "Section" ) |
|
131 ret = TType.ESection; |
|
132 else if ( aTypeAsString == "Data" ) |
|
133 ret = TType.EData; |
|
134 else if ( aTypeAsString == "Number" ) |
|
135 ret = TType.ENumber; |
|
136 // |
|
137 return ret; |
|
138 } |
|
139 #endregion |
|
140 |
|
141 #region Internal properties |
|
142 private MapFile MapFile |
|
143 { |
|
144 get { return (Sources.Map.File.MapFile) Collection; } |
|
145 } |
|
146 #endregion |
|
147 |
|
148 #region Data members |
|
149 private TType iType = TType.EUnknown; |
|
150 #endregion |
|
151 } |
|
152 } |