debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/ExecutablesTab.java
changeset 1925 54d4f01c8389
parent 1603 40a2929cde0d
equal deleted inserted replaced
1924:c8f736b04bf4 1925:54d4f01c8389
   229 		} catch (CoreException e) {
   229 		} catch (CoreException e) {
   230 			LaunchPlugin.log(e);
   230 			LaunchPlugin.log(e);
   231 		}
   231 		}
   232 	}
   232 	}
   233 
   233 
   234 	public static String getExecutablesToTarget(ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
   234 	public static List<IPath> getExecutablesToTarget(ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
       
   235 		List<IPath> executables = new ArrayList<IPath>();
       
   236 		
   235 		int targetingRule = config.getAttribute(SettingsData.LCS_ExecutableTargetingRule, SettingsData.LCS_ExeTargetingRule_AllInSDK);
   237 		int targetingRule = config.getAttribute(SettingsData.LCS_ExecutableTargetingRule, SettingsData.LCS_ExeTargetingRule_AllInSDK);
   236 		String filesString = ""; //$NON-NLS-1$
   238 		String filesString = ""; //$NON-NLS-1$
   237 		if (targetingRule == SettingsData.LCS_ExeTargetingRule_ExeList) {
   239 		if (targetingRule == SettingsData.LCS_ExeTargetingRule_ExeList) {
   238 			filesString = config.getAttribute(PreferenceConstants.J_PN_ExecutablesToDebug, ""); //$NON-NLS-1$			
   240 			filesString = config.getAttribute(PreferenceConstants.J_PN_ExecutablesToDebug, ""); //$NON-NLS-1$			
   239 		} else {
   241 		} else {
   240 			List<ExeFileToDebug> exeFiles = ExecutablesTab.getExecutablesToTarget(targetingRule, config, monitor);
   242 			List<ExeFileToDebug> exeFiles = getExecutablesToTarget(targetingRule, config, monitor);
   241 			filesString = ExecutablesTab.getExeFilesAsString(exeFiles.toArray(new ExeFileToDebug[exeFiles.size()]));
   243 			filesString = getExeFilesAsString(exeFiles.toArray(new ExeFileToDebug[exeFiles.size()]));
   242 		}
   244 		}
   243 		return filesString;
   245 		
       
   246 		if (filesString.length() > 0) {
       
   247 			StringTokenizer tokenizer = new StringTokenizer(filesString, ","); //$NON-NLS-1$
       
   248 			while (tokenizer.hasMoreTokens()) {
       
   249 				String exePath = tokenizer.nextToken();
       
   250 				String enabled = tokenizer.nextToken();
       
   251 				try {
       
   252 					int enabledVal = Integer.parseInt(enabled);
       
   253 					if (enabledVal != 0) {
       
   254 						IPath path = new Path(exePath);
       
   255 						if (!executables.contains(path)) {
       
   256 							executables.add(path);
       
   257 						}
       
   258 					}
       
   259 				} catch (NumberFormatException e) {
       
   260 				}
       
   261 			}
       
   262 		}
       
   263 		
       
   264 		// add in the main executable for the launch config
       
   265 		IPath mainExePath = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""));
       
   266 		if (!executables.contains(mainExePath)) {
       
   267 			executables.add(mainExePath);
       
   268 		}
       
   269 		
       
   270 		return executables;
   244 	}
   271 	}
   245 
   272 
   246 	private static String getExeFilesAsString(ExeFileToDebug[] files) {
   273 	private static String getExeFilesAsString(ExeFileToDebug[] files) {
   247 		String filesString = ""; //$NON-NLS-1$
   274 		String filesString = ""; //$NON-NLS-1$
   248 		for (int i = 0; i < files.length; i++) {
   275 		for (int i = 0; i < files.length; i++) {
   267 					PreferenceConstants.J_PV_SymbolLoadingRule_All);
   294 					PreferenceConstants.J_PV_SymbolLoadingRule_All);
   268 		else
   295 		else
   269 			configuration.setAttribute(
   296 			configuration.setAttribute(
   270 					PreferenceConstants.J_PN_SymbolLoadingRule,
   297 					PreferenceConstants.J_PN_SymbolLoadingRule,
   271 					PreferenceConstants.J_PV_SymbolLoadingRule_Auto);
   298 					PreferenceConstants.J_PV_SymbolLoadingRule_Auto);
   272 		
       
   273 		// get the current program name because it needs to be set to some executable to target
       
   274 		String programName = null;
       
   275 		try {
       
   276 			programName = AbstractCLaunchDelegate.getProgramName(configuration);
       
   277 		} catch (CoreException e) {
       
   278 		}
       
   279 		
       
   280 		// only do this when the current program name is not empty.  if it is, we'll be changing it
       
   281 		// which causes the apply button to become enabled which is not expected behavior.  this will
       
   282 		// be called later if/when they do specify the main program, so we'll make sure then that it's
       
   283 		// actually being targeted.
       
   284 		if (programName != null && programName.length() > 0) {
       
   285 			boolean resetProgramName = true;
       
   286 			// check to see if the current program name is one of the executables to target
       
   287 			for (ExeFileToDebug exeFileToDebug : executablesToTarget) {
       
   288 				if (exeFileToDebug.getExePath().equalsIgnoreCase(programName)) {
       
   289 					resetProgramName = false;
       
   290 					break;
       
   291 				}
       
   292 			}
       
   293 			if (resetProgramName) {
       
   294 				// ensure one of the enabled files to target is set as the program name
       
   295 				for (ExeFileToDebug exeFileToDebug : executablesToTarget) {
       
   296 					if (exeFileToDebug.getEnabled()) {
       
   297 						configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, exeFileToDebug.getExePath());
       
   298 						break;
       
   299 					}
       
   300 				}
       
   301 			}
       
   302 		}
       
   303 	}
   299 	}
   304 
   300 
   305 	private static List<ExeFileToDebug> getExecutablesForTheProject(ILaunchConfiguration configuration) {
   301 	private static List<ExeFileToDebug> getExecutablesForTheProject(ILaunchConfiguration configuration) {
   306 		List<ExeFileToDebug> files = new ArrayList<ExeFileToDebug>();
   302 		List<ExeFileToDebug> files = new ArrayList<ExeFileToDebug>();
   307 		try {
   303 		try {
   326 			}
   322 			}
   327 		} catch (CoreException e1) { } catch (IOException e) { }
   323 		} catch (CoreException e1) { } catch (IOException e) { }
   328 		return files;
   324 		return files;
   329 	}
   325 	}
   330 
   326 
   331 	static public List<ExeFileToDebug> getExecutablesToTarget(int targetingRule, ILaunchConfiguration launchConfig, IProgressMonitor monitor) {
   327 	private static List<ExeFileToDebug> getExecutablesToTarget(int targetingRule, ILaunchConfiguration launchConfig, IProgressMonitor monitor) {
   332 		List<ExeFileToDebug> files = new ArrayList<ExeFileToDebug>();
   328 		List<ExeFileToDebug> files = new ArrayList<ExeFileToDebug>();
   333 
   329 
   334 		if (targetingRule == SettingsData.LCS_ExeTargetingRule_All) {
   330 		if (targetingRule == SettingsData.LCS_ExeTargetingRule_All) {
   335 			files = getExecutablesForTheProject(launchConfig);
   331 			files = getExecutablesForTheProject(launchConfig);
   336 		}
   332 		}