Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'debug/org.eclipse.cdt.debug.core/src')
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java14
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLaunchDescriptorType.java35
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java109
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java126
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildProjectLaunchDescriptor.java48
5 files changed, 330 insertions, 2 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java
index 177b245c5d1..78fd598077d 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java
@@ -46,6 +46,7 @@ import org.eclipse.debug.core.ILaunchDelegate;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* The plugin class for C/C++ debug core.
@@ -239,6 +240,15 @@ public class CDebugCorePlugin extends Plugin {
super.stop(context);
}
+ /**
+ * @since 8.1
+ */
+ public static <T> T getService(Class<T> service) {
+ BundleContext context = plugin.getBundle().getBundleContext();
+ ServiceReference<T> ref = context.getServiceReference(service);
+ return ref != null ? context.getService(ref) : null;
+ }
+
private void createCommandAdapterFactory() {
IAdapterManager manager= Platform.getAdapterManager();
CCommandAdapterFactory actionFactory = new CCommandAdapterFactory();
@@ -319,7 +329,7 @@ public class CDebugCorePlugin extends Plugin {
// Set the default launch delegates as early as possible, and do it only once (Bug 312997)
ILaunchManager launchMgr = DebugPlugin.getDefault().getLaunchManager();
- HashSet<String> debugSet = new HashSet<String>();
+ HashSet<String> debugSet = new HashSet<>();
debugSet.add(ILaunchManager.DEBUG_MODE);
ILaunchConfigurationType localCfg = launchMgr.getLaunchConfigurationType(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP);
@@ -378,7 +388,7 @@ public class CDebugCorePlugin extends Plugin {
} catch (CoreException e) {
}
- HashSet<String> runSet = new HashSet<String>();
+ HashSet<String> runSet = new HashSet<>();
runSet.add(ILaunchManager.RUN_MODE);
try {
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLaunchDescriptorType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLaunchDescriptorType.java
new file mode 100644
index 00000000000..661a6e3c896
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLaunchDescriptorType.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.debug.internal.core.launch;
+
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.launchbar.core.ILaunchDescriptor;
+import org.eclipse.launchbar.core.ILaunchDescriptorType;
+import org.eclipse.launchbar.core.internal.Activator;
+
+/**
+ * The launch descriptor type for launch objects built with the Core Build System.
+ */
+public class CoreBuildLaunchDescriptorType implements ILaunchDescriptorType {
+
+ @Override
+ public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
+ if (launchObject instanceof IProject) {
+ // Make sure it's a new style build
+ IProject project = (IProject) launchObject;
+ if (Activator.getService(ICBuildConfigurationManager.class).supports(project)) {
+ return new CoreBuildProjectLaunchDescriptor(this, project);
+ }
+ }
+ // TODO IBinary
+ return null;
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java
new file mode 100644
index 00000000000..609bfa3e342
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.debug.internal.core.launch;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.launchbar.core.AbstractLaunchConfigProvider;
+import org.eclipse.launchbar.core.ILaunchDescriptor;
+import org.eclipse.launchbar.core.target.ILaunchTarget;
+import org.eclipse.launchbar.core.target.ILaunchTargetManager;
+
+public class CoreBuildLocalLaunchConfigProvider extends AbstractLaunchConfigProvider {
+
+ private static final String TYPE_ID = "org.eclipse.cdt.debug.core.localLaunchConfigurationType"; //$NON-NLS-1$
+
+ private Map<IProject, ILaunchConfiguration> configs = new HashMap<>();
+
+ @Override
+ public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
+ return ILaunchTargetManager.localLaunchTargetTypeId.equals(target.getTypeId());
+ }
+
+ @Override
+ public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target)
+ throws CoreException {
+ return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(TYPE_ID);
+ }
+
+ @Override
+ public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
+ throws CoreException {
+ ILaunchConfiguration config = null;
+ IProject project = descriptor.getAdapter(IProject.class);
+ if (project != null) {
+ config = configs.get(project);
+ if (config == null) {
+ config = createLaunchConfiguration(descriptor, target);
+ // launch config added will get called below to add it to the
+ // configs map
+ }
+ }
+ return config;
+ }
+
+ @Override
+ protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target,
+ ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
+ super.populateLaunchConfiguration(descriptor, target, workingCopy);
+
+ // Set the project and the connection
+ IProject project = descriptor.getAdapter(IProject.class);
+ workingCopy.setMappedResources(new IResource[] { project });
+ }
+
+ @Override
+ public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
+ if (ownsLaunchConfiguration(configuration)) {
+ IProject project = configuration.getMappedResources()[0].getProject();
+ configs.put(project, configuration);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
+ for (Entry<IProject, ILaunchConfiguration> entry : configs.entrySet()) {
+ if (configuration.equals(entry.getValue())) {
+ configs.remove(entry.getKey());
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
+ // TODO not sure I care
+ return false;
+ }
+
+ @Override
+ public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
+ IProject project = descriptor.getAdapter(IProject.class);
+ if (project != null) {
+ configs.remove(project);
+ }
+ }
+
+ @Override
+ public void launchTargetRemoved(ILaunchTarget target) throws CoreException {
+ // nothing to do since the Local connection can't be removed
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java
new file mode 100644
index 00000000000..e26692aa13a
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.debug.internal.core.launch;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.core.build.ICBuildConfiguration;
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.IToolChainManager;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.debug.core.CDebugCorePlugin;
+import org.eclipse.cdt.utils.Platform;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.launchbar.core.target.ILaunchTarget;
+import org.eclipse.launchbar.core.target.launch.ITargetedLaunch;
+import org.eclipse.launchbar.core.target.launch.LaunchConfigurationTargetedDelegate;
+
+public class CoreBuildLocalRunLaunchDelegate extends LaunchConfigurationTargetedDelegate {
+
+ public static final String TYPE_ID = "org.eclipse.cdt.cmake.core.launchConfigurationType"; //$NON-NLS-1$
+
+ private ICBuildConfigurationManager configManager = CDebugCorePlugin.getService(ICBuildConfigurationManager.class);
+ private IToolChainManager tcManager = CDebugCorePlugin.getService(IToolChainManager.class);
+
+ private IProject getProject(ILaunchConfiguration configuration) throws CoreException {
+ return configuration.getMappedResources()[0].getProject();
+ }
+
+ @Override
+ public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, ILaunchTarget target,
+ IProgressMonitor monitor) throws CoreException {
+ // Set active build config based on toolchain for target
+ Map<String, String> properties = new HashMap<>();
+ properties.put(IToolChain.ATTR_OS, Platform.getOS());
+ properties.put(IToolChain.ATTR_ARCH, Platform.getOSArch());
+ // TODO should really use real architecture of platform, not what Eclipse is using.
+ // Also on 64-bit platforms, try 32-bit if toolchains not found
+ Collection<IToolChain> tcs = tcManager.getToolChainsMatching(properties);
+ if (!tcs.isEmpty()) {
+ IToolChain toolChain = tcs.iterator().next();
+
+ IProject project = getProject(configuration);
+ ICBuildConfiguration config = configManager.getBuildConfiguration(project, toolChain, "run", monitor); //$NON-NLS-1$
+
+ if (config != null) {
+ IProjectDescription desc = project.getDescription();
+ desc.setActiveBuildConfig(config.getBuildConfiguration().getName());
+ project.setDescription(desc, monitor);
+ }
+ }
+
+ // proceed with the build
+ return superBuildForLaunch(configuration, mode, monitor);
+ }
+
+ @Override
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
+ throws CoreException {
+ IProject project = getProject(configuration);
+ ILaunchTarget target = ((ITargetedLaunch) launch).getLaunchTarget();
+
+ ICBuildConfiguration buildConfig = getBuildConfiguration(project, mode, target, monitor);
+ IBinary[] binaries = buildConfig.getBuildOutput();
+ IBinary exeFile = null;
+ for (IBinary binary : binaries) {
+ if (binary.isExecutable()) {
+ exeFile = binary;
+ break;
+ }
+ }
+ if (exeFile == null) {
+ throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.PLUGIN_ID, "No binaries"));
+ }
+
+ try {
+ ProcessBuilder builder = new ProcessBuilder(Paths.get(exeFile.getLocationURI()).toString());
+ buildConfig.setBuildEnvironment(builder.environment());
+ Process process = builder.start();
+ DebugPlugin.newProcess(launch, process, exeFile.getPath().lastSegment());
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.PLUGIN_ID, "Error launching", e));
+ }
+ }
+
+ @Override
+ protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
+ // 1. Extract project from configuration
+ // TODO dependencies too.
+ IProject project = getProject(configuration);
+ return new IProject[] { project };
+ }
+
+ private ICBuildConfiguration getBuildConfiguration(IProject project, String mode, ILaunchTarget target,
+ IProgressMonitor monitor) throws CoreException {
+ // Set active build config based on toolchain for target
+ Map<String, String> properties = new HashMap<>();
+ properties.put(IToolChain.ATTR_OS, Platform.getOS());
+ properties.put(IToolChain.ATTR_ARCH, Platform.getOSArch());
+ Collection<IToolChain> tcs = tcManager.getToolChainsMatching(properties);
+ if (!tcs.isEmpty()) {
+ IToolChain toolChain = tcs.iterator().next();
+ return configManager.getBuildConfiguration(project, toolChain, "run", monitor); //$NON-NLS-1$
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildProjectLaunchDescriptor.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildProjectLaunchDescriptor.java
new file mode 100644
index 00000000000..bfb4a223d96
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildProjectLaunchDescriptor.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.debug.internal.core.launch;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.launchbar.core.ILaunchDescriptor;
+import org.eclipse.launchbar.core.ILaunchDescriptorType;
+
+/**
+ * A launch descriptor representing a project built with the new Core Build system.
+ */
+public class CoreBuildProjectLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
+
+ private final IProject project;
+ private final CoreBuildLaunchDescriptorType type;
+
+ public CoreBuildProjectLaunchDescriptor(CoreBuildLaunchDescriptorType type, IProject project) {
+ this.type = type;
+ this.project = project;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getAdapter(Class<T> adapter) {
+ if (IProject.class.equals(adapter)) {
+ return (T) project;
+ } else {
+ return super.getAdapter(adapter);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return project.getName();
+ }
+
+ @Override
+ public ILaunchDescriptorType getType() {
+ return type;
+ }
+
+}

Back to the top