1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 496818 - Cannot find executable if working directory is not default

Originally, to determine the program path, GDBBackend's constructor
would call:

   ICProject cproject = LaunchUtils.getCProject(lc);
   fProgramPath = LaunchUtils.verifyProgramPath(lc, cproject);
   
When we made the change in 192bfff688 we
didn't keep that logic and lost some functionality.

This commit re-instates the original logic.

Change-Id: Ifbee2273517c41ad6ebdc9980261ed36d651f130
This commit is contained in:
Marc Khouzam 2016-06-27 14:21:31 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 972aeb3d0b
commit 783787af25

View file

@ -70,6 +70,7 @@ import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.utils.CommandLineUtil;
import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@ -617,27 +618,7 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr
* @since 5.0
*/
public String[] getLaunchEnvironment() throws CoreException {
// Get the project
String projectName = getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
(String) null);
IProject project = null;
if (projectName == null) {
IResource[] resources = getLaunchConfiguration().getMappedResources();
if (resources != null && resources.length > 0 && resources[0] instanceof IProject) {
project = (IProject) resources[0];
}
} else {
projectName = projectName.trim();
if (projectName.length() == 0) {
return null;
}
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
if (project == null || !project.isAccessible()) {
// No project
return null;
}
IProject project = getProject();
HashMap<String, String> envMap = new HashMap<String, String>();
ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project, false);
@ -691,6 +672,30 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr
return strings.toArray(new String[strings.size()]);
}
private IProject getProject() throws CoreException {
String projectName = getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
(String) null);
IProject project = null;
if (projectName == null) {
IResource[] resources = getLaunchConfiguration().getMappedResources();
if (resources != null && resources.length > 0 && resources[0] instanceof IProject) {
project = (IProject) resources[0];
}
} else {
projectName = projectName.trim();
if (projectName.length() == 0) {
return null;
}
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
if (project == null || !project.isAccessible()) {
// No project
return null;
}
return project;
}
/**
* Get the location of the gdbinit file.
*
@ -797,12 +802,34 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr
* @since 5.0
*/
public String getProgramPath() throws CoreException {
String programPath = getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME);
if (programPath == null) {
programPath = getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME,
String programName = getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME);
if (programName == null) {
programName = getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME,
(String) null);
}
return programPath;
if (programName == null) {
return null;
}
programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName);
IPath programPath = new Path(programName);
if (programPath.isEmpty()) {
return null;
}
if (!programPath.isAbsolute()) {
IProject project = getProject();
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();
}
}
if (!programPath.toFile().exists()) {
return null;
}
return programPath.toOSString();
}
/**