1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 572759: Allow debugging binaries with project relative path

In some situations, it makes sense to have a build structure parallel
with the source tree, and it this case, the build results may not be
part of the resources visible in the Eclipse workspace.
Current implementation allows absolute paths to the binary to debug.
While it works, it's a cumbersome way to handle the above situation.
By resolving the relative path outside of Eclipse scope allows to point
to files that are not part of the Eclipse workspace, allthough the path
is relative to a project in the workspace.

Contributed by STMicroelectronics

Change-Id: I284a5dad61e692dae4029e5f142d23d8cda98ed0
Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
This commit is contained in:
Torbjörn Svensson 2021-03-01 18:36:28 +01:00
parent 450e0cac52
commit 5654112209
6 changed files with 52 additions and 20 deletions

View file

@ -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,

View file

@ -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$

View file

@ -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

View file

@ -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);

View file

@ -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 <code>null</code> 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;

View file

@ -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.