refactored getting list of executables to target from the executables tab - fixed bug #11880.
--- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/NokiaAbstractLaunchDelegate.java Mon Aug 30 20:19:48 2010 -0500
+++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/NokiaAbstractLaunchDelegate.java Mon Aug 30 21:48:01 2010 -0500
@@ -23,7 +23,6 @@
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
-import java.util.StringTokenizer;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary;
@@ -36,10 +35,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.jobs.IJobManager;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -209,49 +205,19 @@
*/
protected IPath[] getOtherExecutables(ICProject project, IPath exePath,
ILaunchConfiguration config, IProgressMonitor monitor) throws CModelException {
- ArrayList<IPath> targetedBinaries = new ArrayList<IPath>();
- targetedBinaries.addAll(getBldInfExecutables(project, exePath, config, monitor));
- return (IPath[]) targetedBinaries.toArray(new IPath[targetedBinaries
- .size()]);
- }
-
- /**
- * Returns list of executables that are built as part of the bld inf file.
- * Excludes the exe specified in the launch configuration.
- * @param monitor
- *
- * @return
- */
- protected List<IPath> getBldInfExecutables(ICProject project,
- IPath mainExePath, ILaunchConfiguration config, IProgressMonitor monitor) {
- // Target imported executables in the project
- ArrayList<IPath> infExecutables = new ArrayList<IPath>();
-
+ List<IPath> targetedBinaries = new ArrayList<IPath>();
+
try {
-
- String executablesToTarget = ExecutablesTab.getExecutablesToTarget(config, monitor);
+ targetedBinaries.addAll(ExecutablesTab.getExecutablesToTarget(config, monitor));
- if (executablesToTarget.length() > 0) {
- StringTokenizer tokenizer = new StringTokenizer(executablesToTarget,
- ","); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens()) {
- String exe = tokenizer.nextToken();
- String enabled = tokenizer.nextToken();
-
- Path exePath = new Path(exe);
- if (enabled.compareTo("0") == 0 //$NON-NLS-1$
- || exePath.lastSegment().equalsIgnoreCase(
- mainExePath.lastSegment())) {
- continue;
- }
- infExecutables.add(exePath);
- }
+ // remove the main exe if it exists
+ if (targetedBinaries.contains(exePath)) {
+ targetedBinaries.remove(exePath);
}
- } catch (CoreException ce) {
- return infExecutables;
+ } catch (CoreException e) {
}
- return infExecutables;
+ return (IPath[]) targetedBinaries.toArray(new IPath[targetedBinaries.size()]);
}
/**
--- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/ExecutablesTab.java Mon Aug 30 20:19:48 2010 -0500
+++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/ExecutablesTab.java Mon Aug 30 21:48:01 2010 -0500
@@ -231,16 +231,43 @@
}
}
- public static String getExecutablesToTarget(ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
+ public static List<IPath> getExecutablesToTarget(ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
+ List<IPath> executables = new ArrayList<IPath>();
+
int targetingRule = config.getAttribute(SettingsData.LCS_ExecutableTargetingRule, SettingsData.LCS_ExeTargetingRule_AllInSDK);
String filesString = ""; //$NON-NLS-1$
if (targetingRule == SettingsData.LCS_ExeTargetingRule_ExeList) {
filesString = config.getAttribute(PreferenceConstants.J_PN_ExecutablesToDebug, ""); //$NON-NLS-1$
} else {
- List<ExeFileToDebug> exeFiles = ExecutablesTab.getExecutablesToTarget(targetingRule, config, monitor);
- filesString = ExecutablesTab.getExeFilesAsString(exeFiles.toArray(new ExeFileToDebug[exeFiles.size()]));
+ List<ExeFileToDebug> exeFiles = getExecutablesToTarget(targetingRule, config, monitor);
+ filesString = getExeFilesAsString(exeFiles.toArray(new ExeFileToDebug[exeFiles.size()]));
}
- return filesString;
+
+ if (filesString.length() > 0) {
+ StringTokenizer tokenizer = new StringTokenizer(filesString, ","); //$NON-NLS-1$
+ while (tokenizer.hasMoreTokens()) {
+ String exePath = tokenizer.nextToken();
+ String enabled = tokenizer.nextToken();
+ try {
+ int enabledVal = Integer.parseInt(enabled);
+ if (enabledVal != 0) {
+ IPath path = new Path(exePath);
+ if (!executables.contains(path)) {
+ executables.add(path);
+ }
+ }
+ } catch (NumberFormatException e) {
+ }
+ }
+ }
+
+ // add in the main executable for the launch config
+ IPath mainExePath = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""));
+ if (!executables.contains(mainExePath)) {
+ executables.add(mainExePath);
+ }
+
+ return executables;
}
private static String getExeFilesAsString(ExeFileToDebug[] files) {
@@ -269,37 +296,6 @@
configuration.setAttribute(
PreferenceConstants.J_PN_SymbolLoadingRule,
PreferenceConstants.J_PV_SymbolLoadingRule_Auto);
-
- // get the current program name because it needs to be set to some executable to target
- String programName = null;
- try {
- programName = AbstractCLaunchDelegate.getProgramName(configuration);
- } catch (CoreException e) {
- }
-
- // only do this when the current program name is not empty. if it is, we'll be changing it
- // which causes the apply button to become enabled which is not expected behavior. this will
- // be called later if/when they do specify the main program, so we'll make sure then that it's
- // actually being targeted.
- if (programName != null && programName.length() > 0) {
- boolean resetProgramName = true;
- // check to see if the current program name is one of the executables to target
- for (ExeFileToDebug exeFileToDebug : executablesToTarget) {
- if (exeFileToDebug.getExePath().equalsIgnoreCase(programName)) {
- resetProgramName = false;
- break;
- }
- }
- if (resetProgramName) {
- // ensure one of the enabled files to target is set as the program name
- for (ExeFileToDebug exeFileToDebug : executablesToTarget) {
- if (exeFileToDebug.getEnabled()) {
- configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, exeFileToDebug.getExePath());
- break;
- }
- }
- }
- }
}
private static List<ExeFileToDebug> getExecutablesForTheProject(ILaunchConfiguration configuration) {
@@ -328,7 +324,7 @@
return files;
}
- static public List<ExeFileToDebug> getExecutablesToTarget(int targetingRule, ILaunchConfiguration launchConfig, IProgressMonitor monitor) {
+ private static List<ExeFileToDebug> getExecutablesToTarget(int targetingRule, ILaunchConfiguration launchConfig, IProgressMonitor monitor) {
List<ExeFileToDebug> files = new ArrayList<ExeFileToDebug>();
if (targetingRule == SettingsData.LCS_ExeTargetingRule_All) {
--- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java Mon Aug 30 20:19:48 2010 -0500
+++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java Mon Aug 30 21:48:01 2010 -0500
@@ -16,13 +16,12 @@
*/
package com.nokia.cdt.internal.debug.launch.ui;
-import java.util.StringTokenizer;
-
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -180,23 +179,14 @@
// main target if its in the list of target executables
if (isRemoteTextValid(remoteText.getText()) == null) {
try {
- Path processToLaunch = new Path(remoteText.getText());
- Path mainExePath = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""));
+ IPath processToLaunch = new Path(remoteText.getText());
+ IPath mainExePath = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""));
if (!processToLaunch.lastSegment().equalsIgnoreCase(mainExePath.lastSegment())) {
// passing null as the monitor should be ok as its not really being used.
- String executablesToTarget = ExecutablesTab.getExecutablesToTarget(config, null);
- if (executablesToTarget != null && executablesToTarget.length() > 0) {
- StringTokenizer tokenizer = new StringTokenizer(executablesToTarget, ","); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens()) {
- String exe = tokenizer.nextToken();
- String enabled = tokenizer.nextToken();
-
- Path exePath = new Path(exe);
- if (enabled.compareTo("1") == 0 //$NON-NLS-1$
- && exePath.lastSegment().equalsIgnoreCase(processToLaunch.lastSegment())) {
- config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, exePath.toOSString());
- break;
- }
+ for (IPath exe : ExecutablesTab.getExecutablesToTarget(config, null)) {
+ if (exe.lastSegment().equalsIgnoreCase(processToLaunch.lastSegment())) {
+ config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, exe.toOSString());
+ break;
}
}
}