|
1 /* |
|
2 * Copyright (c) 2008-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: Definitions for the class SymReader |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.s60tools.analyzetool.engine.statistic; |
|
20 |
|
21 import java.io.File; |
|
22 import java.util.AbstractList; |
|
23 import java.util.ArrayList; |
|
24 import java.util.HashMap; |
|
25 import java.util.Iterator; |
|
26 import java.util.Set; |
|
27 |
|
28 import org.eclipse.core.resources.IProject; |
|
29 import org.eclipse.core.runtime.IPath; |
|
30 |
|
31 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
|
32 import com.nokia.carbide.cdt.builder.DefaultMMPViewConfiguration; |
|
33 import com.nokia.carbide.cdt.builder.EpocEngineHelper; |
|
34 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration; |
|
35 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; |
|
36 import com.nokia.carbide.cpp.epoc.engine.EpocEnginePlugin; |
|
37 import com.nokia.carbide.cpp.epoc.engine.MMPDataRunnableAdapter; |
|
38 import com.nokia.carbide.cpp.epoc.engine.model.mmp.EMMPStatement; |
|
39 import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPData; |
|
40 import com.nokia.carbide.cpp.epoc.engine.preprocessor.AcceptedNodesViewFilter; |
|
41 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISymbolFile; |
|
42 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISymbolReaderManager; |
|
43 import com.nokia.cdt.debug.cw.symbian.symbolreader.SymbolReaderManager; |
|
44 import com.nokia.s60tools.analyzetool.global.Constants; |
|
45 |
|
46 /** |
|
47 * Opens and closes symbol files. |
|
48 * @author kihe |
|
49 * |
|
50 */ |
|
51 @SuppressWarnings("restriction") |
|
52 public class SymReader { |
|
53 |
|
54 /**Selected project*/ |
|
55 IProject project; |
|
56 |
|
57 /**List of opened symbol files */ |
|
58 HashMap<String, ISymbolFile> allreayOpen; |
|
59 |
|
60 /**Project target list*/ |
|
61 AbstractList<String> targets; |
|
62 |
|
63 /**SymbolReaderManager*/ |
|
64 ISymbolReaderManager manager; |
|
65 |
|
66 /**Build target*/ |
|
67 String buildTarget; |
|
68 |
|
69 /** |
|
70 * Constructor |
|
71 * @param projectRef Active project reference |
|
72 */ |
|
73 public SymReader( IProject projectRef ) |
|
74 { |
|
75 project = projectRef; |
|
76 targets = new ArrayList<String>(); |
|
77 manager = SymbolReaderManager.getSymbolReaderManager(); |
|
78 allreayOpen = new HashMap<String, ISymbolFile>(); |
|
79 } |
|
80 |
|
81 |
|
82 /** |
|
83 * Gets ISymbolFile object to corresponding symbol file |
|
84 * @param moduleName Module name which is loaded |
|
85 * @param onlyForProjecTargets Create results for only project modules |
|
86 * @return Symbol file if found, otherwise null |
|
87 */ |
|
88 public ISymbolFile getSymbolFile( String moduleName, boolean onlyForProjecTargets ) |
|
89 { |
|
90 //thru project targets |
|
91 if( onlyForProjecTargets ) |
|
92 { |
|
93 Iterator<String> targetsIter = targets.iterator(); |
|
94 while( targetsIter.hasNext() ) |
|
95 { |
|
96 String oneTarget = targetsIter.next(); |
|
97 if( oneTarget.contains( moduleName ) ) |
|
98 { |
|
99 return getSymFile(moduleName); |
|
100 } |
|
101 } |
|
102 } |
|
103 else |
|
104 { |
|
105 return getSymFile(moduleName); |
|
106 } |
|
107 |
|
108 return null; |
|
109 } |
|
110 |
|
111 /** |
|
112 * Opens and return ISymbolFile for the given module |
|
113 * @param moduleName Module name |
|
114 * @return Opened symbol file |
|
115 */ |
|
116 private ISymbolFile getSymFile(String moduleName ) |
|
117 { |
|
118 if( allreayOpen.containsKey( moduleName ) ) |
|
119 { |
|
120 return allreayOpen.get( moduleName ); |
|
121 } |
|
122 |
|
123 //get symbol file name |
|
124 String symFile = getSymbolFileNameForTarget( moduleName ); |
|
125 if( symFile != null && manager != null ) |
|
126 { |
|
127 ISymbolFile symbolFile = manager.openSymbolFile( symFile ); |
|
128 allreayOpen.put(moduleName, symbolFile); |
|
129 return symbolFile; |
|
130 } |
|
131 |
|
132 return null; |
|
133 } |
|
134 |
|
135 |
|
136 /** |
|
137 * |
|
138 * @param targetName Target name |
|
139 * @return Target sym file name if found, otherwise null |
|
140 */ |
|
141 public String getSymbolFileNameForTarget( final String targetName ) |
|
142 { |
|
143 if( targetName == null || ("").equals( targetName) ) |
|
144 return null; |
|
145 |
|
146 buildTarget = getBuildTarget(); |
|
147 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo( project ); |
|
148 String platform = cpi.getDefaultConfiguration().getPlatformString(); |
|
149 //set symbol file location |
|
150 char backslash = '\\'; |
|
151 |
|
152 String epocRoot = getEpocroot(); |
|
153 if( epocRoot == null || ("").equals( epocRoot )) { |
|
154 return null; |
|
155 } |
|
156 StringBuffer symbolFileLocation = new StringBuffer(32); |
|
157 symbolFileLocation.append( epocRoot ); |
|
158 symbolFileLocation.append( "epoc32\\release\\" ); |
|
159 symbolFileLocation.append(platform); |
|
160 symbolFileLocation.append(backslash); |
|
161 symbolFileLocation.append( buildTarget ); |
|
162 symbolFileLocation.append(backslash); |
|
163 |
|
164 |
|
165 //build target is set to WINSCW we can use the target name |
|
166 if( (Constants.BUILD_TARGET_WINSCW).equalsIgnoreCase(platform) ) { |
|
167 symbolFileLocation.append(targetName); |
|
168 } |
|
169 //remove target name extension and add .sym |
|
170 else if( targetName.lastIndexOf('.') != -1 ) { |
|
171 String targetWithoutExt = targetName.substring(0, targetName.lastIndexOf('.')); |
|
172 symbolFileLocation.append( targetWithoutExt ); |
|
173 symbolFileLocation.append(".sym"); |
|
174 } |
|
175 |
|
176 //symbol file exists => return file location |
|
177 File symFile = new File( symbolFileLocation.toString() ); |
|
178 if( symFile.exists() ) |
|
179 { |
|
180 return symbolFileLocation.toString(); |
|
181 } |
|
182 //symbol file not found |
|
183 //try find target(with extension) + .sym |
|
184 StringBuffer symFileLocWithExt = new StringBuffer(32); |
|
185 symFileLocWithExt.append( epocRoot ); |
|
186 symFileLocWithExt.append( "epoc32\\release\\" ); |
|
187 symFileLocWithExt.append(platform); |
|
188 symFileLocWithExt.append(backslash); |
|
189 symFileLocWithExt.append( buildTarget ); |
|
190 symFileLocWithExt.append(backslash); |
|
191 symFileLocWithExt.append(targetName); |
|
192 symFileLocWithExt.append(".sym"); |
|
193 |
|
194 File symFileWithExt = new File( symFileLocWithExt.toString() ); |
|
195 if( symFileWithExt.exists() ) { |
|
196 return symFileLocWithExt.toString(); |
|
197 } |
|
198 return null; |
|
199 |
|
200 } |
|
201 |
|
202 /** |
|
203 * Returns build target |
|
204 * @return Active build target |
|
205 */ |
|
206 public String getBuildTarget() |
|
207 { |
|
208 //get build target |
|
209 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo( project ); |
|
210 EpocEngineHelper.getEpocRootForProject(project); |
|
211 String configName = cpi.getDefaultBuildConfigName(); |
|
212 buildTarget = "udeb"; |
|
213 if( configName.contains( "Release") ) |
|
214 { |
|
215 buildTarget = "urel"; |
|
216 } |
|
217 return buildTarget; |
|
218 } |
|
219 |
|
220 /** |
|
221 * Returns default epocroot location |
|
222 * @return Epocroot location |
|
223 */ |
|
224 public String getEpocroot() |
|
225 { |
|
226 if( project != null && project.isOpen() ) { |
|
227 IPath epocRootPath = EpocEngineHelper.getEpocRootForProject(project); |
|
228 if( epocRootPath != null ) { |
|
229 return epocRootPath.toOSString(); |
|
230 } |
|
231 } |
|
232 return null; |
|
233 } |
|
234 |
|
235 /** |
|
236 * Closes active ISymbolFiles |
|
237 */ |
|
238 public void dispose() |
|
239 { |
|
240 if( allreayOpen.isEmpty() ) { |
|
241 manager = null; |
|
242 return; |
|
243 } |
|
244 //thru open ISymbolFiles |
|
245 Set<String> keySet = allreayOpen.keySet(); |
|
246 for (String moduleName : keySet) { |
|
247 ISymbolFile symFile = allreayOpen.get( moduleName ); |
|
248 symFile.close(); |
|
249 symFile = null; |
|
250 allreayOpen.remove( moduleName ); |
|
251 } |
|
252 |
|
253 allreayOpen.clear(); |
|
254 manager = null; |
|
255 } |
|
256 |
|
257 /** |
|
258 * Gets current project targets info |
|
259 */ |
|
260 public void loadProjectTargetsInfo() |
|
261 { |
|
262 // Assumes buildConfig (ICarbideBuildConfiguration) is known |
|
263 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo( project ); |
|
264 ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration(); |
|
265 for (IPath mmpPath : EpocEngineHelper.getMMPFilesForBuildConfiguration(buildConfig)) { |
|
266 Object data = EpocEnginePlugin.runWithMMPData(mmpPath, new |
|
267 DefaultMMPViewConfiguration(buildConfig.getCarbideProject().getProject(), |
|
268 buildConfig, new AcceptedNodesViewFilter()), new MMPDataRunnableAdapter() |
|
269 { |
|
270 public Object run(IMMPData mmpData) { |
|
271 // The real return value, getting a single argument setting |
|
272 return mmpData.getSingleArgumentSettings().get(EMMPStatement.TARGET); |
|
273 } |
|
274 }); |
|
275 |
|
276 // Make sure to test for and cast to proper Object type! |
|
277 String mmpStatement = (String)data; // Now we should have the TARGETTYPE |
|
278 targets.add( mmpStatement ); |
|
279 } |
|
280 } |
|
281 |
|
282 /** |
|
283 * Reopen all cached symbol files if not already open |
|
284 */ |
|
285 public void reOpenCachedSymbolFiles() { |
|
286 if (manager == null) { |
|
287 //it's strange that we need to create another Object here so that DE releases the |
|
288 //targets |
|
289 manager = new SymbolReaderManager().getSymbolReaderManager(); |
|
290 } |
|
291 Set<String> keySet = allreayOpen.keySet(); |
|
292 for (String moduleName : keySet) { |
|
293 if (allreayOpen.get(moduleName) == null) { |
|
294 String file = getSymbolFileNameForTarget(moduleName); |
|
295 if (file != null) { |
|
296 ISymbolFile symFile = manager.openSymbolFile(file); |
|
297 allreayOpen.put(moduleName, symFile); |
|
298 } |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 /** |
|
304 * Close all cached symbol files |
|
305 */ |
|
306 public void closeCachedSymbolFiles() { |
|
307 Set<String> keySet = allreayOpen.keySet(); |
|
308 for (String moduleName : keySet) { |
|
309 ISymbolFile symFile = allreayOpen.get( moduleName ); |
|
310 if (symFile != null) { |
|
311 symFile.close(); |
|
312 symFile = null; |
|
313 } |
|
314 allreayOpen.put(moduleName, null); |
|
315 } |
|
316 manager = null; |
|
317 } |
|
318 } |