|
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.pi.instr; |
|
19 |
|
20 import java.util.Enumeration; |
|
21 import java.util.Vector; |
|
22 |
|
23 import com.nokia.carbide.cpp.internal.pi.model.Binary; |
|
24 import com.nokia.carbide.cpp.internal.pi.model.Function; |
|
25 import com.nokia.carbide.cpp.internal.pi.model.FunctionResolver; |
|
26 |
|
27 |
|
28 public class AdvancedMemoryMap implements FunctionResolver |
|
29 { |
|
30 private boolean debug = false; |
|
31 private UndecidedPool unDecided; |
|
32 private DecidedPool decided; |
|
33 private BinaryReader binReader; |
|
34 |
|
35 private IttTrace122 ittTrace122; |
|
36 private BinaryReader122 binaryReader122; |
|
37 |
|
38 // whether the resolver has enough information to resolve anything |
|
39 protected boolean ableToResolve = true; |
|
40 |
|
41 public AdvancedMemoryMap(BinaryReader122 binaryReader122,IttTrace122 ittTrace122) |
|
42 { |
|
43 this.binaryReader122 = binaryReader122; |
|
44 this.ittTrace122 = ittTrace122; |
|
45 } |
|
46 |
|
47 public AdvancedMemoryMap(BinaryReader myBinaryReader) |
|
48 { |
|
49 this.binReader = myBinaryReader; |
|
50 this.decided = new DecidedPool(this); |
|
51 this.unDecided = new UndecidedPool(this); |
|
52 } |
|
53 |
|
54 public UndecidedPool getUndecidedPool() |
|
55 { |
|
56 return this.unDecided; |
|
57 } |
|
58 |
|
59 public DecidedPool getDecidedPool() |
|
60 { |
|
61 return this.decided; |
|
62 } |
|
63 |
|
64 public BinaryReader getBinaryReader() |
|
65 { |
|
66 return this.binReader; |
|
67 } |
|
68 |
|
69 public void InsertSample(IttSample sample) |
|
70 { |
|
71 if (this.ittTrace122 == null) |
|
72 { |
|
73 // first check whether there is any binary in the location |
|
74 // the sample is |
|
75 boolean memStat = this.decided.isThereAnyBinaryInMemoryIn(sample.programCounter); |
|
76 |
|
77 if (memStat == true) |
|
78 { |
|
79 // there is a binary / binaries |
|
80 // in the memory at the location |
|
81 // where the sample is located |
|
82 |
|
83 this.decided.insertSample(sample); |
|
84 // result tells whether the sample was binary compatible |
|
85 // with any of the binaries. It is not important here though, as |
|
86 // the sample should have a match also with its correct binary if |
|
87 // it is present - consequent samples will then strenghten the |
|
88 // position of the binary |
|
89 } |
|
90 |
|
91 else if (memStat == false) |
|
92 { |
|
93 // no, this sample has to be inserted to the |
|
94 // undecided pool |
|
95 |
|
96 this.unDecided.insertSample(sample,10); |
|
97 } |
|
98 |
|
99 if (this.unDecided.getUnprocessed().size() > 0) |
|
100 { |
|
101 //System.out.println("Unprocessed "+this.unDecided.getUnprocessed().size()); |
|
102 Vector unProcVec = this.unDecided.getUnprocessed(); |
|
103 Enumeration enumer = unProcVec.elements(); |
|
104 while(enumer.hasMoreElements()) |
|
105 { |
|
106 IttSample s = (IttSample)enumer.nextElement(); |
|
107 // try the undecided samples again |
|
108 this.decided.insertSample(s); |
|
109 } |
|
110 } |
|
111 } |
|
112 else |
|
113 { |
|
114 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
115 } |
|
116 } |
|
117 |
|
118 public void postProcess() |
|
119 { |
|
120 if (this.ittTrace122 == null) |
|
121 { |
|
122 |
|
123 for (int i=9;i>0;i--) |
|
124 { |
|
125 Vector undecided = unDecided.getUndecided(); |
|
126 if (debug) System.out.println(Messages.getString("AdvancedMemoryMap.unmatchedSize")+undecided.size()); //$NON-NLS-1$ |
|
127 |
|
128 Enumeration enumer = undecided.elements(); |
|
129 while(enumer.hasMoreElements()) |
|
130 { |
|
131 IttSample is = (IttSample)enumer.nextElement(); |
|
132 |
|
133 if (this.decided.insertSample(is) == false) |
|
134 this.unDecided.insertSample(is,i); |
|
135 |
|
136 } |
|
137 } |
|
138 } |
|
139 else |
|
140 { |
|
141 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
142 } |
|
143 } |
|
144 |
|
145 public Binary findBinaryForSample(IttSample sample) |
|
146 { |
|
147 if (this.ittTrace122 == null) |
|
148 { |
|
149 Binary b = this.decided.findBinaryForSample(sample); |
|
150 if (b != null) |
|
151 { |
|
152 return b; |
|
153 } |
|
154 else |
|
155 { |
|
156 b = new Binary(Messages.getString("AdvancedMemoryMap.binaryForAddressNotFound1")+Long.toHexString(sample.programCounter)+Messages.getString("AdvancedMemoryMap.binaryForAddressNotFound2")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
157 b.length = 0; |
|
158 b.offsetToCodeStart = 0; |
|
159 b.startAddress = sample.programCounter+4; |
|
160 b.type = null; |
|
161 return b; |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
167 } |
|
168 } |
|
169 |
|
170 public Function findFunctionForSample(IttSample sample) |
|
171 { |
|
172 if (this.ittTrace122 == null) |
|
173 { |
|
174 Function f; |
|
175 ProcessedBinary pb = null; |
|
176 |
|
177 Binary b = this.decided.findBinaryForSample(sample); |
|
178 if (b != null) |
|
179 { |
|
180 int offset = (int)(sample.programCounter+4-(b.startAddress+b.offsetToCodeStart)); |
|
181 pb = this.binReader.getProcessedBinaryForName(b.binaryName); |
|
182 if (pb != null) |
|
183 { |
|
184 f = pb.getFunctionForOffset(offset); |
|
185 if (f != null) |
|
186 { |
|
187 f.startAddress = new Long(b.startAddress+f.offsetFromBinaryStart+pb.offsetToCodeStart); |
|
188 // function found ok |
|
189 // System.out.println(f.toString()); |
|
190 return f; |
|
191 } |
|
192 |
|
193 // function not found in processed binary |
|
194 f = new Function(Messages.getString("AdvancedMemoryMap.functionForAddressNotFound1")+Long.toHexString(sample.programCounter)+Messages.getString("AdvancedMemoryMap.functionForAddressNotFound2"), //$NON-NLS-1$ //$NON-NLS-2$ |
|
195 new Long(pb.startAddress), |
|
196 pb.binaryName); |
|
197 return f; |
|
198 } |
|
199 } |
|
200 |
|
201 // in all other cases |
|
202 f = new Function(Messages.getString("AdvancedMemoryMap.functionForAddressNotFound1")+Long.toHexString(sample.programCounter)+Messages.getString("AdvancedMemoryMap.functionForAddressNotFound2"), //$NON-NLS-1$ //$NON-NLS-2$ |
|
203 new Long(sample.programCounter), |
|
204 Messages.getString("AdvancedMemoryMap.binaryForAddressNotFound1")+Long.toHexString(sample.programCounter)+Messages.getString("AdvancedMemoryMap.binaryForAddressNotFound2")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
205 return f; |
|
206 } |
|
207 else |
|
208 { |
|
209 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
210 } |
|
211 } |
|
212 |
|
213 public Function findFunctionForAddress(long address) |
|
214 { |
|
215 if (this.ittTrace122 == null) |
|
216 { |
|
217 return this.decided.getFunctionForAddress(address); |
|
218 } |
|
219 else |
|
220 { |
|
221 return this.ittTrace122.getFunctionForAddress(address,this.binaryReader122); |
|
222 } |
|
223 } |
|
224 |
|
225 public String findFunctionNameForAddress(long address) |
|
226 { |
|
227 Function f = this.findFunctionForAddress(address); |
|
228 if (f != null) |
|
229 { |
|
230 return f.functionName; |
|
231 } |
|
232 else |
|
233 { |
|
234 return Messages.getString("AdvancedMemoryMap.functionNotFound"); //$NON-NLS-1$ |
|
235 } |
|
236 } |
|
237 |
|
238 public String findBinaryNameForAddress(long address) |
|
239 { |
|
240 Function f = this.findFunctionForAddress(address); |
|
241 if (f != null) |
|
242 { |
|
243 return f.functionBinary.binaryName; |
|
244 } |
|
245 else |
|
246 { |
|
247 return Messages.getString("AdvancedMemoryMap.binaryNotFound"); //$NON-NLS-1$ |
|
248 } |
|
249 } |
|
250 |
|
251 public String getResolverName() |
|
252 { |
|
253 return "ITT"; //$NON-NLS-1$ |
|
254 } |
|
255 |
|
256 public String getResolverString() |
|
257 { |
|
258 return Messages.getString("AdvancedMemoryMap.resolverITT"); //$NON-NLS-1$ |
|
259 } |
|
260 |
|
261 public Binary findBinaryForAddress(long address) |
|
262 { |
|
263 if (this.ittTrace122 == null) |
|
264 { |
|
265 Function f = this.findFunctionForAddress(address); |
|
266 |
|
267 if (f != null) |
|
268 return f.functionBinary; |
|
269 else |
|
270 return null; |
|
271 } |
|
272 else |
|
273 { |
|
274 Function f = this.ittTrace122.getFunctionForAddress(address,this.binaryReader122); |
|
275 |
|
276 if (f != null) |
|
277 return f.functionBinary; |
|
278 else |
|
279 return null; |
|
280 } |
|
281 } |
|
282 |
|
283 public String findFunctionNameForSample(IttSample sample) |
|
284 { |
|
285 if (this.ittTrace122 == null) |
|
286 { |
|
287 Binary b = this.decided.findBinaryForSample(sample); |
|
288 if (b != null) |
|
289 { |
|
290 int offset = (int)(sample.programCounter+4-(b.startAddress+b.offsetToCodeStart)); |
|
291 return this.binReader.getFunctionName(b.binaryName,offset); |
|
292 } |
|
293 else |
|
294 { |
|
295 return Messages.getString("AdvancedMemoryMap.functionForAddressNotFound1")+Long.toHexString(sample.programCounter)+Messages.getString("AdvancedMemoryMap.functionForAddressNotFound2"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
296 } |
|
297 } |
|
298 else |
|
299 { |
|
300 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
301 } |
|
302 } |
|
303 |
|
304 public Enumeration getSupportingSamples(Binary b) |
|
305 { |
|
306 if (this.ittTrace122 == null) |
|
307 { |
|
308 |
|
309 return this.decided.getSupportingSamplesForBinary(b); |
|
310 } |
|
311 else |
|
312 { |
|
313 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
314 } |
|
315 |
|
316 } |
|
317 |
|
318 public Enumeration getNonSupportingSamples(Binary b) |
|
319 { |
|
320 if (this.ittTrace122 == null) |
|
321 { |
|
322 |
|
323 return this.decided.getNonSupportingSamplesForBinary(b); |
|
324 } |
|
325 else |
|
326 { |
|
327 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
328 } |
|
329 |
|
330 } |
|
331 |
|
332 public Binary getBinary(String binaryName) |
|
333 { |
|
334 if (this.ittTrace122 == null) |
|
335 { |
|
336 return this.decided.getBinaryWithName(binaryName); |
|
337 } |
|
338 else |
|
339 { |
|
340 throw new ArrayIndexOutOfBoundsException(Messages.getString("AdvancedMemoryMap.notSupportedInV.1.22")); //$NON-NLS-1$ |
|
341 } |
|
342 } |
|
343 |
|
344 public boolean canResolve() { |
|
345 return this.ableToResolve; |
|
346 } |
|
347 } |