|
1 /* |
|
2 * Copyright (c) 2004-2008 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 |
|
18 using System; |
|
19 using System.IO; |
|
20 using System.Collections.Generic; |
|
21 using System.Text; |
|
22 using System.Text.RegularExpressions; |
|
23 using SymbianStructuresLib.Debug.Symbols; |
|
24 using SymbianSymbolLib.SourceManagement.Source; |
|
25 using SymbianSymbolLib.SourceManagement.Provisioning; |
|
26 using SymbianUtils; |
|
27 using SymbianUtils.FileTypes; |
|
28 using SymbianUtils.Tracer; |
|
29 |
|
30 namespace SLPluginMap.Reader.RVCT |
|
31 { |
|
32 internal class RVCTSymbolCreator |
|
33 { |
|
34 #region Enumerations |
|
35 public enum TType |
|
36 { |
|
37 EUnknown = 0, |
|
38 EARMCode, |
|
39 EThumbCode, |
|
40 EData, |
|
41 ENumber, |
|
42 ESection |
|
43 } |
|
44 #endregion |
|
45 |
|
46 #region Constructors |
|
47 public RVCTSymbolCreator( MapReader aReader, SymbolCollection aCollection ) |
|
48 { |
|
49 iReader = aReader; |
|
50 iCollection = aCollection; |
|
51 } |
|
52 #endregion |
|
53 |
|
54 #region Properties |
|
55 #endregion |
|
56 |
|
57 #region API |
|
58 public Symbol Parse( string aLine ) |
|
59 { |
|
60 Symbol ret = null; |
|
61 // |
|
62 Match m = KMapParserRegex.Match( aLine ); |
|
63 if ( m.Success ) |
|
64 { |
|
65 GroupCollection groups = m.Groups; |
|
66 // |
|
67 uint globalBaseAddress = iReader.GlobalBaseAddress; |
|
68 string typeString = groups[ "Type" ].Value; |
|
69 // |
|
70 string objectName = groups[ "Binary" ].Value; |
|
71 uint size = uint.Parse( groups[ "Size" ].Value ); |
|
72 string symbol = groups[ "Function" ].Value; |
|
73 uint offsetAddress = uint.Parse( groups[ "Address" ].Value, System.Globalization.NumberStyles.HexNumber ) - globalBaseAddress; |
|
74 TSymbolType type = TypeByString( typeString ); |
|
75 // |
|
76 ret = Symbol.New( iCollection ); |
|
77 ret.OffsetAddress = offsetAddress; |
|
78 ret.Size = size; |
|
79 ret.Object = objectName; |
|
80 ret.Name = symbol; |
|
81 ret.Type = type; |
|
82 |
|
83 TSymbolType tt = ret.Type; |
|
84 |
|
85 // If the MAP file indicated thumb code then ensure our symbol library agrees. |
|
86 if ( typeString == "Thumb Code" ) |
|
87 { |
|
88 System.Diagnostics.Debug.Assert( ret.InstructionSet == SymbianStructuresLib.Arm.TArmInstructionSet.ETHUMB ); |
|
89 } |
|
90 } |
|
91 // |
|
92 return ret; |
|
93 } |
|
94 #endregion |
|
95 |
|
96 #region Internal constants |
|
97 // <summary> |
|
98 // Regular expression built for C# on: Fri, Aug 15, 2008, 11:19:15 AM |
|
99 // Using Expresso Version: 3.0.2766, http://www.ultrapico.com |
|
100 // |
|
101 // A description of the regular expression: |
|
102 // |
|
103 // Match expression but don't capture it. [\s+] |
|
104 // Whitespace, one or more repetitions |
|
105 // [Function]: A named capture group. [.+?] |
|
106 // Any character, one or more repetitions, as few as possible |
|
107 // Match expression but don't capture it. [\s+] |
|
108 // Whitespace, one or more repetitions |
|
109 // 0x |
|
110 // 0x |
|
111 // [Address]: A named capture group. [[A-Fa-f0-9]{8}] |
|
112 // Any character in this class: [A-Fa-f0-9], exactly 8 repetitions |
|
113 // Match expression but don't capture it. [\s+] |
|
114 // Whitespace, one or more repetitions |
|
115 // [Type]: A named capture group. [(?:Data|Section|Number|ARM Code|Thumb Code)] |
|
116 // Match expression but don't capture it. [Data|Section|Number|ARM Code|Thumb Code] |
|
117 // Select from 5 alternatives |
|
118 // Data |
|
119 // Data |
|
120 // Section |
|
121 // Section |
|
122 // Number |
|
123 // Number |
|
124 // ARM Code |
|
125 // ARM |
|
126 // Space |
|
127 // Code |
|
128 // Thumb Code |
|
129 // Thumb |
|
130 // Space |
|
131 // Code |
|
132 // Match expression but don't capture it. [\s+] |
|
133 // Whitespace, one or more repetitions |
|
134 // [Size]: A named capture group. [\d+] |
|
135 // Any digit, one or more repetitions |
|
136 // Match expression but don't capture it. [\s+] |
|
137 // Whitespace, one or more repetitions |
|
138 // [Binary]: A named capture group. [.+] |
|
139 // Any character, one or more repetitions |
|
140 // |
|
141 // |
|
142 // </summary> |
|
143 private static readonly Regex KMapParserRegex = new Regex( |
|
144 "(?:\\s*)(?<Function>.+?)(?:\\s+)0x(?<Address>[A-Fa-f0-9]{8})"+ |
|
145 "(?:\\s+)(?<Type>(?:Data|Section|Number|ARM Code|Thumb Code))"+ |
|
146 "(?:\\s+)(?<Size>\\d+)(?:\\s+)(?<Binary>.+)", |
|
147 RegexOptions.IgnoreCase |
|
148 | RegexOptions.Singleline |
|
149 | RegexOptions.Compiled |
|
150 ); |
|
151 #endregion |
|
152 |
|
153 #region Internal methods |
|
154 private static TSymbolType TypeByString( string aTypeAsString ) |
|
155 { |
|
156 TSymbolType ret = TSymbolType.EUnknown; |
|
157 // |
|
158 if ( aTypeAsString == "ARM Code" ) |
|
159 ret = TSymbolType.ECode; |
|
160 else if ( aTypeAsString == "Thumb Code" ) |
|
161 ret = TSymbolType.ECode; |
|
162 else if ( aTypeAsString == "Section" ) |
|
163 ret = TSymbolType.ESection; |
|
164 else if ( aTypeAsString == "Data" ) |
|
165 ret = TSymbolType.EData; |
|
166 else if ( aTypeAsString == "Number" ) |
|
167 ret = TSymbolType.ENumber; |
|
168 // |
|
169 return ret; |
|
170 } |
|
171 #endregion |
|
172 |
|
173 #region Data members |
|
174 private readonly MapReader iReader; |
|
175 private readonly SymbolCollection iCollection; |
|
176 #endregion |
|
177 } |
|
178 } |