diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF b/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF index bc10f86d201..4e421bc64c9 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF @@ -12,7 +12,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.cdt.core, org.eclipse.cdt.debug.core, org.eclipse.core.variables, - org.eclipse.cdt.launch;bundle-version="9.3.0", + org.eclipse.cdt.launch;bundle-version="10.3.0", org.eclipse.cdt.gdb;bundle-version="7.0.0", org.eclipse.core.resources, org.eclipse.launchbar.core;bundle-version="2.0.0";visibility:=reexport, diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java index ecee91644c3..4ba7534fecf 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/LaunchUtils.java @@ -19,6 +19,7 @@ package org.eclipse.cdt.dsf.gdb.launching; import java.io.BufferedReader; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -52,7 +53,6 @@ import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.service.SessionType; import org.eclipse.cdt.utils.CommandLineUtil; import org.eclipse.cdt.utils.spawner.ProcessFactory; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -120,13 +120,12 @@ public class LaunchUtils { ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); } - if (!programPath.isAbsolute() && cproject != null) { - // Find the specified program within the specified project - IFile wsProgramPath = cproject.getProject().getFile(programPath); - programPath = wsProgramPath.getLocation(); + if (cproject != null) { + programPath = org.eclipse.cdt.launch.LaunchUtils.toAbsoluteProgramPath(cproject.getProject(), programPath); } - if (!programPath.toFile().exists()) { + File executable = programPath.toFile(); + if (!executable.exists() || !executable.isFile()) { abort(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$ new FileNotFoundException( LaunchMessages.getFormattedString("AbstractCLaunchDelegate.PROGRAM_PATH_not_found", //$NON-NLS-1$ diff --git a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF index c31055a9407..c6667667825 100644 --- a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF +++ b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.launch; singleton:=true -Bundle-Version: 10.2.200.qualifier +Bundle-Version: 10.3.0.qualifier Bundle-Activator: org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java index 721927ab270..8cc28c210dc 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java @@ -39,7 +39,6 @@ import org.eclipse.cdt.launch.internal.ui.LaunchMessages; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -692,13 +691,12 @@ public abstract class AbstractCLaunchDelegate2 extends LaunchConfigurationDelega ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); } - if (!programPath.isAbsolute() && cproject != null) { - // Find the specified program within the specified project - IFile wsProgramPath = cproject.getProject().getFile(programPath); - programPath = wsProgramPath.getLocation(); + if (cproject != null) { + programPath = LaunchUtils.toAbsoluteProgramPath(cproject.getProject(), programPath); } - if (!programPath.toFile().exists()) { + File executable = programPath.toFile(); + if (!executable.exists() || !executable.isFile()) { abort(LaunchMessages.AbstractCLaunchDelegate_Program_file_does_not_exist, new FileNotFoundException( NLS.bind(LaunchMessages.AbstractCLaunchDelegate_PROGRAM_PATH_not_found, programPath.toOSString())), ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java index e90b1be21cb..53afc404862 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java @@ -15,6 +15,7 @@ *******************************************************************************/ package org.eclipse.cdt.launch; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet; @@ -152,12 +153,11 @@ public class LaunchUtils { IProject project = getProject(configuration); ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project); if (cproject != null) { - // Find the specified program within the specified project - IFile wsProgramPath = cproject.getProject().getFile(programPath); - programPath = wsProgramPath.getLocation(); + programPath = toAbsoluteProgramPath(cproject.getProject(), programPath); } } - if (!programPath.toFile().exists()) { + File executable = programPath.toFile(); + if (!executable.exists() || !executable.isFile()) { throwException(Messages.LaunchUtils_program_file_does_not_exist, new FileNotFoundException( MessageFormat.format(Messages.LaunchUtils__0_not_found, programPath.toOSString())), @@ -167,6 +167,33 @@ public class LaunchUtils { return programPath.toOSString(); } + /** + * Return the program path, resolved as an absolute IPath. + * + * @param project Project to resolve relative paths to + * @param programPath The program path to resolve + * @return the program path + * @since 10.3 + */ + public static IPath toAbsoluteProgramPath(IProject project, IPath programPath) { + if (project == null || programPath == null || programPath.isAbsolute()) { + return programPath; + } + + // Find the specified program within the specified project + try { + IPath resolvedPath = project.getFile(programPath).getLocation(); + if (resolvedPath != null && resolvedPath.isAbsolute() && resolvedPath.toFile().exists()) { + return resolvedPath; + } + } catch (IllegalArgumentException e) { + } + + // Find the specified program relative to the specified project + IPath projectPath = project.getLocation(); + return projectPath.append(programPath).makeAbsolute(); + } + /** * Return project or null if project is not accessible or not specified. * @param configuration Launch configuration to obtain project from @@ -322,7 +349,8 @@ public class LaunchUtils { if (dirLocation == null) continue; for (IFile file : files) { - if (dirLocation.isPrefixOf(file.getLocation())) { + IPath location = file.getLocation(); + if (location != null && dirLocation.isPrefixOf(location)) { if (buildConfig != null && buildConfig != cfgDes) { // Matched more than one, so use the active configuration buildConfig = null; diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java index bc9e0bf01ed..44c90a15bdf 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.launch.LaunchUtils; import org.eclipse.cdt.launch.internal.ui.LaunchImages; import org.eclipse.cdt.launch.internal.ui.LaunchMessages; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; @@ -475,10 +476,16 @@ public class CMainTab2 extends CAbstractMainTab { setErrorMessage(LaunchMessages.CMainTab_Project_must_be_opened); return false; } - if (!project.getFile(programName).exists()) { + exePath = LaunchUtils.toAbsoluteProgramPath(project, exePath); + File executable = exePath.toFile(); + if (!executable.exists()) { setErrorMessage(LaunchMessages.CMainTab_Program_does_not_exist); return false; } + if (!executable.isFile()) { + setErrorMessage(LaunchMessages.CMainTab_Selection_must_be_file); + return false; + } } // Notice that we don't check if exePath points to a valid executable since such // check is too expensive to be done on the UI thread.