|
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 the License "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 package com.nokia.carbide.cpp.internal.pi.resolvers; |
|
19 |
|
20 import java.io.BufferedReader; |
|
21 import java.io.File; |
|
22 import java.io.FileNotFoundException; |
|
23 import java.io.FileReader; |
|
24 import java.io.IOException; |
|
25 import java.util.ArrayList; |
|
26 import java.util.regex.Matcher; |
|
27 import java.util.regex.Pattern; |
|
28 |
|
29 import com.nokia.carbide.cpp.pi.util.GeneralMessages; |
|
30 |
|
31 public class SymbolFileFunctionResolver extends CachedFunctionResolver { |
|
32 private boolean debug = false; |
|
33 |
|
34 @Override |
|
35 public void parseAndProcessSymbolFile(File symbolFile) { |
|
36 { |
|
37 /* |
|
38 * From \\epoc32\\release\\armv5\\urel\\foobar.exe |
|
39 * f80130b4 0000 __some_func k_entry_.o(.emb_text) |
|
40 * f8013e5c 0014 NKern::SomeFunc(unsigned long&, unsigned long&) _reka2_ekern.in(.emb_text) |
|
41 * f9165ea8 0008 thunk{-4} to SomeClass::SomeFunc(CustType*, int(*)(const void*)) SVGEngine.in(.text) |
|
42 */ |
|
43 |
|
44 Pattern binaryLinePattern = Pattern.compile("From\\p{Blank}+(\\S.+)\\p{Blank}*"); //$NON-NLS-1$ |
|
45 Pattern symbolLinePattern1 = Pattern.compile("(\\p{XDigit}+)\\p{Blank}+(\\p{XDigit}+)\\p{Blank}+((?!\\d)\\S.+)\\p{Blank}+(\\S.+)"); //$NON-NLS-1$ |
|
46 |
|
47 ArrayList<SymbolFileDllItem> dllTable = new ArrayList<SymbolFileDllItem>(); |
|
48 SymbolFileDllItem currentDll = null; |
|
49 |
|
50 BufferedReader br; |
|
51 try { |
|
52 SymbolFileFunctionItem pendingItem = null; |
|
53 SymbolFileFunctionItem previousItem = null; |
|
54 |
|
55 Matcher symbolLineMatcher; |
|
56 |
|
57 long lineNumber = 0; |
|
58 br = new BufferedReader(new FileReader(symbolFile)); |
|
59 this.ableToResolve = true; |
|
60 |
|
61 while(br.ready()) |
|
62 { |
|
63 String line = br.readLine(); |
|
64 ++lineNumber; |
|
65 if (line == null) |
|
66 continue; |
|
67 |
|
68 symbolLineMatcher = symbolLinePattern1.matcher(line); |
|
69 |
|
70 if (symbolLineMatcher.matches()) { |
|
71 |
|
72 long address = Long.parseLong(symbolLineMatcher.group(1),16); |
|
73 long length = Long.parseLong(symbolLineMatcher.group(2),16); |
|
74 String name = symbolLineMatcher.group(3).trim(); |
|
75 String section = symbolLineMatcher.group(4); |
|
76 |
|
77 if (skipSymbolFromSection(section, length)) { |
|
78 continue; |
|
79 } |
|
80 |
|
81 if (currentDll.uninitialised == true) |
|
82 { |
|
83 currentDll.uninitialised = false; |
|
84 currentDll.start = address; |
|
85 } |
|
86 |
|
87 if ((address+length) <= (currentDll.start+(1024*1024*20)) |
|
88 && (address+length) >= currentDll.end |
|
89 && address != 0xffffffffL ) |
|
90 { |
|
91 if (pendingItem != null) |
|
92 { |
|
93 // the pending item has to be completed with the |
|
94 // address known about this function |
|
95 long pendingLength = address-pendingItem.address; |
|
96 pendingItem.length = pendingLength; |
|
97 // the pending item could be completed, add it to the function list |
|
98 currentDll.data.add(pendingItem); |
|
99 |
|
100 pendingItem = null; |
|
101 } |
|
102 |
|
103 if (previousItem != null) |
|
104 { |
|
105 if (previousItem.address+previousItem.length < address) |
|
106 { |
|
107 long gapAddress = previousItem.address+previousItem.length; |
|
108 long gapLength = address-previousItem.address-previousItem.length; |
|
109 |
|
110 String gapName = Messages.getString("SymbolFileFunctionResolver.possibleStaticFunction1")+(gapLength)+Messages.getString("SymbolFileFunctionResolver.possibleStaticFunction2")+ //$NON-NLS-1$ //$NON-NLS-2$ |
|
111 Long.toHexString(gapAddress)+Messages.getString("SymbolFileFunctionResolver.possibleStaticFunction3")+ //$NON-NLS-1$ |
|
112 Long.toHexString(address); |
|
113 SymbolFileFunctionItem gapItem = new SymbolFileFunctionItem(gapName,gapAddress,gapLength,currentDll); |
|
114 |
|
115 currentDll.data.add(gapItem); |
|
116 } |
|
117 |
|
118 else if (previousItem.address+previousItem.length > address) |
|
119 { |
|
120 //These overlaps happen in symbol files from some device's ROM |
|
121 //and don't seems to be a problem in our code. |
|
122 if (debug) { |
|
123 String outString = Messages.getString("SymbolFileFunctionResolver.debugOverlap1")+ //$NON-NLS-1$ |
|
124 Long.toHexString(previousItem.address+previousItem.length)+ |
|
125 Messages.getString("SymbolFileFunctionResolver.debugOverlap2")+ //$NON-NLS-1$ |
|
126 Long.toHexString(address)+Messages.getString("SymbolFileFunctionResolver.debugOverlap3")+previousItem.name+Messages.getString("SymbolFileFunctionResolver.debugOverlap4")+name; //$NON-NLS-1$ //$NON-NLS-2$ |
|
127 //GeneralMessages.showWarningMessage(outString); |
|
128 System.out.println(outString); |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 if (length == 0) |
|
134 { |
|
135 currentDll.end = address; |
|
136 |
|
137 // if the length of this function is not known, |
|
138 // add it to be completed when the next function is parsed |
|
139 // this assumes that the length of the function is the space |
|
140 // between this function and the next function |
|
141 pendingItem = new SymbolFileFunctionItem(name,address,length,currentDll); |
|
142 |
|
143 // update the previous item |
|
144 previousItem = pendingItem; |
|
145 } |
|
146 else |
|
147 { |
|
148 currentDll.end = address+length; |
|
149 SymbolFileFunctionItem function = new SymbolFileFunctionItem(name,address,length,currentDll); |
|
150 currentDll.data.add(function); |
|
151 |
|
152 // update the previous item |
|
153 previousItem = function; |
|
154 |
|
155 // there is no pending item since the function was added here |
|
156 pendingItem = null; |
|
157 } |
|
158 } |
|
159 |
|
160 } else if (binaryLinePattern.matcher(line).matches()) { |
|
161 |
|
162 pendingItem = null; |
|
163 previousItem = null; |
|
164 |
|
165 currentDll = new SymbolFileDllItem(); |
|
166 if (line.indexOf('\\') != -1) |
|
167 { |
|
168 currentDll.name = line.substring(line.indexOf('\\'),line.length()); |
|
169 } |
|
170 else |
|
171 { |
|
172 currentDll.name = line.substring(0,line.length()); |
|
173 } |
|
174 dllTable.add(currentDll); |
|
175 |
|
176 } else { |
|
177 |
|
178 if (debug) System.out.println(Messages.getString("SymbolFileFunctionResolver.skippingLine")+line); //$NON-NLS-1$ |
|
179 } |
|
180 } |
|
181 |
|
182 if (br != null) |
|
183 br.close(); |
|
184 } catch (FileNotFoundException e) { |
|
185 GeneralMessages.PiLog(Messages.getString("SymbolFileFunctionResolver.symbol.file1") + symbolFile + Messages.getString("SymbolFileFunctionResolver.not.found"), GeneralMessages.ERROR); //$NON-NLS-1$ //$NON-NLS-2$ |
|
186 } catch (IOException e) { |
|
187 String myMessage = Messages.getString("SymbolFileFunctionResolver.symbol.file2") + symbolFile + Messages.getString("SymbolFileFunctionResolver.ioexception"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
188 GeneralMessages.showErrorMessage(myMessage); |
|
189 GeneralMessages.PiLog(myMessage, GeneralMessages.ERROR); |
|
190 } |
|
191 |
|
192 // this breaks the symbol file parser, use for testing itt trace |
|
193 //dllTable.clear(); |
|
194 |
|
195 if (debug) System.out.println(Messages.getString("SymbolFileFunctionResolver.dllCount")+dllTable.size()); //$NON-NLS-1$ |
|
196 addAllToDllList(dllTable); |
|
197 } |
|
198 } |
|
199 |
|
200 private boolean skipSymbolFromSection(String section, long length) { |
|
201 |
|
202 if (section.endsWith("(.data)") || section.endsWith("(.bss)") || section.endsWith("(linker$$defined$$symbols)")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
203 return true; |
|
204 } |
|
205 |
|
206 if (length == 0 && section.endsWith("(.init_array)")) { //$NON-NLS-1$ |
|
207 return true; |
|
208 } |
|
209 |
|
210 if (section.contains("(.data_")) { // (.data__ZZ33ifPowerTraceIdIsEnabledCallCbOncePFvPvES_mE9isPrinted) //$NON-NLS-1$ |
|
211 return true; |
|
212 } |
|
213 |
|
214 return false; |
|
215 } |
|
216 } |