Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Ryall2008-03-24 21:21:02 +0000
committerKen Ryall2008-03-24 21:21:02 +0000
commit3071e4834e349169773a86177381f2831e494b1d (patch)
treea0df77d9d498ed24d62d86c01f33c3a7f1a87475 /debug/org.eclipse.cdt.debug.core
parent2e3fbf6c23755e395ff5ba843f9e1b35279ab32e (diff)
downloadorg.eclipse.cdt-3071e4834e349169773a86177381f2831e494b1d.tar.gz
org.eclipse.cdt-3071e4834e349169773a86177381f2831e494b1d.tar.xz
org.eclipse.cdt-3071e4834e349169773a86177381f2831e494b1d.zip
Bug 182388, Executables view and supporting classes.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.core')
-rw-r--r--debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF4
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/Executable.java309
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesChangeEvent.java35
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesManager.java172
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableImporter.java19
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableProvider.java28
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeEvent.java19
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeListener.java20
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ISourceFileRemapping.java24
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableImporter.java210
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java166
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardSourceFileRemapping.java58
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java24
13 files changed, 1080 insertions, 8 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF
index 62f3ed6be9b..0b9c5f5322e 100644
--- a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF
+++ b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Export-Package: org.eclipse.cdt.debug.core,
org.eclipse.cdt.debug.core.cdi.event,
org.eclipse.cdt.debug.core.cdi.model,
org.eclipse.cdt.debug.core.cdi.model.type,
+ org.eclipse.cdt.debug.core.executables,
org.eclipse.cdt.debug.core.model,
org.eclipse.cdt.debug.core.sourcelookup,
org.eclipse.cdt.debug.internal.core,
@@ -21,6 +22,7 @@ Export-Package: org.eclipse.cdt.debug.core,
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)",
org.eclipse.cdt.core;bundle-version="[5.0.0,6.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)"
+ org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.filesystem;bundle-version="1.2.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/Executable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/Executable.java
new file mode 100644
index 00000000000..688d9101b30
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/Executable.java
@@ -0,0 +1,309 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.core.executables;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.IBinaryParser;
+import org.eclipse.cdt.core.ISymbolReader;
+import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.internal.core.model.BinaryParserConfig;
+import org.eclipse.cdt.internal.core.model.CModelManager;
+import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
+import org.eclipse.cdt.internal.core.model.TranslationUnit;
+import org.eclipse.core.filesystem.URIUtil;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+
+public class Executable extends PlatformObject {
+
+ private IPath path;
+ private IProject project;
+ private String name;
+ private IResource resource;
+ private Map<ITranslationUnit, String> remappedPaths;
+ private ArrayList<ITranslationUnit> sourceFiles;
+
+ public IPath getPath() {
+ return path;
+ }
+
+ public IProject getProject() {
+ return project;
+ }
+
+ public Executable(IPath path, IProject project, IResource resource) {
+ this.path = path;
+ this.project = project;
+ this.name = new File(path.toOSString()).getName();
+ this.resource = resource;
+ remappedPaths = new HashMap<ITranslationUnit, String>();
+ sourceFiles = new ArrayList<ITranslationUnit>();
+ }
+
+ public IResource getResource() {
+ return resource;
+ }
+
+ @Override
+ public String toString() {
+ return path.toString();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter.equals(IResource.class))
+ if (getResource() != null)
+ return getResource();
+ else
+ return this.getProject();
+ return super.getAdapter(adapter);
+ }
+
+ static public boolean isExecutableFile(IPath path) {
+ // ignore directories
+ if (path.toFile().isDirectory()) {
+ return false;
+ }
+ // Only if file has no extension, has an extension that is an integer
+ // or is a binary file content type
+ String ext = path.getFileExtension();
+ if (ext != null) {
+ // shared libraries often have a version number
+ boolean isNumber = true;
+ for (int i = 0; i < ext.length(); ++i)
+ if (!Character.isDigit(ext.charAt(i))) {
+ isNumber = false;
+ break;
+ }
+ if (!isNumber) {
+ boolean isBinary = false;
+ final IContentTypeManager ctm = Platform.getContentTypeManager();
+ final IContentType ctbin = ctm.getContentType(CCorePlugin.CONTENT_TYPE_BINARYFILE);
+ final IContentType[] cts = ctm.findContentTypesFor(path.toFile().getName());
+ for (int i = 0; !isBinary && i < cts.length; i++) {
+ isBinary = cts[i].isKindOf(ctbin);
+ }
+ if (!isBinary) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public IBinaryFile createBinaryFile() {
+ CModelManager factory = CModelManager.getDefault();
+
+ if (resource != null && resource instanceof IFile)
+ return factory.createBinaryFile((IFile) resource);
+
+ BinaryParserConfig[] parsers = factory.getBinaryParser(getProject());
+ if (parsers.length == 0) {
+ return null;
+ }
+
+ if (!isExecutableFile(path))
+ return null;
+
+ File f = new File(path.toOSString());
+ if (f.length() == 0) {
+ return null;
+ }
+
+ int hints = 0;
+
+ for (int i = 0; i < parsers.length; i++) {
+ IBinaryParser parser = null;
+ try {
+ parser = parsers[i].getBinaryParser();
+ if (parser.getHintBufferSize() > hints) {
+ hints = parser.getHintBufferSize();
+ }
+ } catch (CoreException e) {
+ }
+ }
+ byte[] bytes = new byte[hints];
+ if (hints > 0) {
+ InputStream is = null;
+ try {
+ is = new FileInputStream(path.toFile());
+ int count = 0;
+ // Make sure we read up to 'hints' bytes if we possibly can
+ while (count < hints) {
+ int bytesRead = is.read(bytes, count, hints - count);
+ if (bytesRead < 0)
+ break;
+ count += bytesRead;
+ }
+ if (count > 0 && count < bytes.length) {
+ byte[] array = new byte[count];
+ System.arraycopy(bytes, 0, array, 0, count);
+ bytes = array;
+ }
+ } catch (IOException e) {
+ return null;
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < parsers.length; i++) {
+ try {
+ IBinaryParser parser = parsers[i].getBinaryParser();
+ if (parser.isBinary(bytes, path)) {
+ IBinaryFile binFile = parser.getBinary(bytes, path);
+ if (binFile != null) {
+ return binFile;
+ }
+ }
+ } catch (IOException e) {
+ } catch (CoreException e) {
+ }
+ }
+ return null;
+ }
+
+ public ITranslationUnit[] getSourceFiles() {
+ // Try to get the list of source files used to build the binary from the
+ // symbol information.
+
+ remappedPaths.clear();
+
+ sourceFiles.clear();
+
+ CModelManager factory = CModelManager.getDefault();
+ IBinaryFile bin = createBinaryFile();
+
+ if (bin != null) {
+ ICProject cproject = factory.create(project);
+
+ ISymbolReader symbolreader = (ISymbolReader) bin.getAdapter(ISymbolReader.class);
+ if (symbolreader != null) {
+ String[] symReaderSources = symbolreader.getSourceFiles();
+ if (symReaderSources != null && symReaderSources.length > 0) {
+ for (int i = 0; i < symReaderSources.length; i++) {
+ String filename = symReaderSources[i];
+ String orgPath = filename;
+
+ filename = ExecutablesManager.getExecutablesManager().remapSourceFile(filename);
+
+ // Sometimes the path in the symbolics will have a
+ // different
+ // case than the actual file system path. Even if the
+ // file
+ // system is not case sensitive this will confuse the
+ // Path
+ // class.
+ // So make sure the path is canonical, otherwise
+ // breakpoints
+ // won't be resolved, etc..
+ // Also check for relative path names and attempt to
+ // resolve
+ // them relative to the executable.
+
+ try {
+ File file = new File(filename);
+ if (file.exists()) {
+ filename = file.getCanonicalPath();
+ } else if (filename.startsWith(".")) { //$NON-NLS-1$
+ file = new File(bin.getPath().removeLastSegments(1).toOSString(), filename);
+ filename = file.getCanonicalPath();
+ }
+ } catch (IOException e) { // Do nothing.
+ }
+
+ // See if this source file is already in the project.
+ // We check this to determine if we should create a
+ // TranslationUnit or ExternalTranslationUnit
+ IFile sourceFile = getProject().getFile(filename);
+ IPath path = new Path(filename);
+
+ IFile wkspFile = null;
+ if (sourceFile.exists())
+ wkspFile = sourceFile;
+ else {
+ IFile[] filesInWP = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
+
+ for (int j = 0; j < filesInWP.length; j++) {
+ if (filesInWP[j].isAccessible()) {
+ wkspFile = filesInWP[j];
+ break;
+ }
+ }
+ }
+
+ // Create a translation unit for this file and add it as
+ // a child of the binary
+ String id = CoreModel.getRegistedContentTypeId(sourceFile.getProject(), sourceFile.getName());
+
+ if (id != null) { // Don't add files we can't get an
+ // ID for.
+ TranslationUnit tu;
+ if (wkspFile != null)
+ tu = new TranslationUnit(cproject, wkspFile, id);
+ else
+ tu = new ExternalTranslationUnit(cproject, URIUtil.toURI(path), id);
+
+ sourceFiles.add(tu);
+
+ if (!orgPath.equals(filename)) {
+ remappedPaths.put(tu, orgPath);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ return sourceFiles.toArray(new TranslationUnit[sourceFiles.size()]);
+ }
+
+ public String getOriginalLocation(ITranslationUnit tu) {
+ String orgLocation = remappedPaths.get(tu);
+ if (orgLocation == null)
+ orgLocation = tu.getPath().toOSString();
+ return orgLocation;
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesChangeEvent.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesChangeEvent.java
new file mode 100644
index 00000000000..60bd74ce9d5
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesChangeEvent.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.debug.core.executables;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.PlatformObject;
+
+public class ExecutablesChangeEvent extends PlatformObject implements IExecutablesChangeEvent {
+
+ private Executable[] oldExecutables;
+ private Executable[] newExecutables;
+
+ public ExecutablesChangeEvent(ArrayList<Executable> oldList, ArrayList<Executable> newList) {
+ oldExecutables = oldList.toArray(new Executable[oldList.size()]);
+ newExecutables = newList.toArray(new Executable[newList.size()]);
+ }
+
+ public Executable[] getCurrentExecutables() {
+ return newExecutables;
+ }
+
+ public Executable[] getPreviousExecutables() {
+ return oldExecutables;
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesManager.java
new file mode 100644
index 00000000000..c50e3f5b14a
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ExecutablesManager.java
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.core.executables;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * The Executables Manager maintains a collection of executables built by all of
+ * the projects in the workspace. Executables are contributed by instances of
+ * IExecutablesProvider.
+ *
+ * @author Ken Ryall
+ *
+ */
+public class ExecutablesManager extends PlatformObject {
+
+ private ArrayList<Executable> executables = new ArrayList<Executable>();
+ private List<IExecutablesChangeListener> changeListeners = Collections.synchronizedList(new ArrayList<IExecutablesChangeListener>());
+ private List<ISourceFileRemapping> sourceFileRemappings = Collections.synchronizedList(new ArrayList<ISourceFileRemapping>());
+ private List<IExecutableProvider> executableProviders = Collections.synchronizedList(new ArrayList<IExecutableProvider>());
+ private List<IExecutableImporter> executableImporters = Collections.synchronizedList(new ArrayList<IExecutableImporter>());
+ private boolean refreshNeeded = true;
+
+ private Job refreshJob = new Job("Get Executables") {
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ refreshExecutables(monitor);
+ return Status.OK_STATUS;
+ }
+ };
+
+ private static ExecutablesManager executablesManager = null;
+
+ public static ExecutablesManager getExecutablesManager() {
+ if (executablesManager == null)
+ executablesManager = new ExecutablesManager();
+ return executablesManager;
+ }
+
+ public ExecutablesManager() {
+ addSourceFileRemapping(new StandardSourceFileRemapping());
+ addExecutableImporter(new StandardExecutableImporter());
+ addExecutablesProvider(new StandardExecutableProvider());
+ }
+
+ public void addExecutablesChangeListener(IExecutablesChangeListener listener) {
+ changeListeners.add(listener);
+ }
+
+ public void removeExecutablesChangeListener(IExecutablesChangeListener listener) {
+ changeListeners.remove(listener);
+ }
+
+ public void addSourceFileRemapping(ISourceFileRemapping remapping) {
+ sourceFileRemappings.add(remapping);
+ }
+
+ public void removeSourceFileRemapping(ISourceFileRemapping remapping) {
+ sourceFileRemappings.remove(remapping);
+ }
+
+ public void addExecutableImporter(IExecutableImporter importer) {
+ executableImporters.add(importer);
+ }
+
+ public void removeExecutableImporter(IExecutableImporter importer) {
+ executableImporters.remove(importer);
+ }
+
+ public void addExecutablesProvider(IExecutableProvider provider) {
+ executableProviders.add(provider);
+ }
+
+ public void removeExecutablesProvider(IExecutableProvider provider) {
+ executableProviders.remove(provider);
+ }
+
+ public IStatus refreshExecutables(IProgressMonitor monitor) {
+ ArrayList<Executable> oldList = executables;
+ executables = new ArrayList<Executable>();
+ synchronized (executableProviders) {
+ monitor.beginTask("Refresh Executables", executableProviders.size());
+ for (IExecutableProvider provider : executableProviders) {
+ executables.addAll(provider.getExecutables(new SubProgressMonitor(monitor, 1)));
+ }
+ monitor.done();
+ }
+ refreshNeeded = false;
+
+ synchronized (changeListeners) {
+ for (IExecutablesChangeListener listener : changeListeners) {
+ listener.executablesChanged(new ExecutablesChangeEvent(oldList, executables) {
+ });
+ }
+ }
+ return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
+ }
+
+ public Executable[] getExecutables() {
+ if (refreshNeeded) {
+ try {
+ refreshJob.schedule();
+ refreshJob.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ return executables.toArray(new Executable[executables.size()]);
+ }
+
+ public String remapSourceFile(String filePath) {
+ synchronized (sourceFileRemappings) {
+ for (ISourceFileRemapping remapping : sourceFileRemappings) {
+ String remappedPath = remapping.remapSourceFile(filePath);
+ if (!remappedPath.equals(filePath))
+ return remappedPath;
+ }
+ }
+ return filePath;
+ }
+
+ public void importExecutables(String[] fileNames, IProgressMonitor monitor) {
+ synchronized (executableImporters) {
+ monitor.beginTask("Import Executables", executableImporters.size());
+ for (IExecutableImporter importer : executableImporters) {
+ importer.importExecutables(fileNames, new SubProgressMonitor(monitor, 1));
+ }
+ monitor.done();
+ }
+ }
+
+ public ISourceFileRemapping[] getSourceFileRemappings() {
+ return sourceFileRemappings.toArray(new ISourceFileRemapping[sourceFileRemappings.size()]);
+ }
+
+ public IExecutableProvider[] getExecutableProviders() {
+ return executableProviders.toArray(new IExecutableProvider[executableProviders.size()]);
+ }
+
+ public IExecutableImporter[] getExecutableImporters() {
+ return executableImporters.toArray(new IExecutableImporter[executableImporters.size()]);
+ }
+
+ public void scheduleRefresh(IExecutableProvider provider, long delay) {
+ refreshNeeded = true;
+ refreshJob.schedule(delay);
+ }
+
+ public boolean refreshNeeded() {
+ return refreshNeeded;
+ }
+
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableImporter.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableImporter.java
new file mode 100644
index 00000000000..8fe0ef324ce
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableImporter.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.debug.core.executables;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public interface IExecutableImporter {
+
+ public abstract void importExecutables(String[] fileNames, IProgressMonitor monitor);
+
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableProvider.java
new file mode 100644
index 00000000000..6c4ede78d09
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutableProvider.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.debug.core.executables;
+
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * IExecutablesProvider supplies a list of executables to the Executables
+ * Manager.
+ *
+ * @author Ken Ryall
+ *
+ */
+public interface IExecutableProvider {
+
+ Collection<Executable> getExecutables(IProgressMonitor monitor);
+
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeEvent.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeEvent.java
new file mode 100644
index 00000000000..3c559eadae4
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeEvent.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.core.executables;
+
+public interface IExecutablesChangeEvent {
+
+ public Executable[] getCurrentExecutables();
+
+ public Executable[] getPreviousExecutables();
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeListener.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeListener.java
new file mode 100644
index 00000000000..bfa0677655f
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IExecutablesChangeListener.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.core.executables;
+
+import java.util.EventListener;
+
+public interface IExecutablesChangeListener extends EventListener {
+
+ public void executablesChanged(IExecutablesChangeEvent event);
+
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ISourceFileRemapping.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ISourceFileRemapping.java
new file mode 100644
index 00000000000..85948e3b61a
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/ISourceFileRemapping.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.debug.core.executables;
+
+/**
+ * ISourceFileRemapping is used by the Executables Manager when finding missing
+ * source files.
+ *
+ * @author Ken Ryall
+ *
+ */
+public interface ISourceFileRemapping {
+
+ String remapSourceFile(String filePath);
+
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableImporter.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableImporter.java
new file mode 100644
index 00000000000..3d9a20729d0
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableImporter.java
@@ -0,0 +1,210 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.debug.core.executables;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.IBinaryParser;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.debug.core.CDebugCorePlugin;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+
+public class StandardExecutableImporter implements IExecutableImporter {
+
+ public static final String DEBUG_PROJECT_ID = "org.eclipse.cdt.debug"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.executables.IExecutableImporter#importExecutables(java.lang.String[],
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void importExecutables(String[] fileNames, IProgressMonitor monitor) {
+ monitor.beginTask("Import Executables", fileNames.length);
+
+ IProject exeProject = null;
+ boolean checkProject = false;
+ // Weed out existing ones
+ for (String path : fileNames) {
+
+ try {
+ path = new File(path).getCanonicalPath();
+ } catch (IOException e1) {
+ }
+ if (!executableExists(path)) {
+ if (!checkProject) {
+ // See if the default project exists
+ String defaultProjectName = "Executables";
+ ICProject cProject = CoreModel.getDefault().getCModel().getCProject(defaultProjectName);
+ if (cProject.exists()) {
+ exeProject = cProject.getProject();
+ } else {
+ final String[] ignoreList = { ".project", //$NON-NLS-1$
+ ".cdtproject", //$NON-NLS-1$
+ ".cproject", //$NON-NLS-1$
+ ".cdtbuild", //$NON-NLS-1$
+ ".settings", //$NON-NLS-1$
+ };
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProject newProjectHandle = workspace.getRoot().getProject(defaultProjectName);
+
+ IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
+ description.setLocation(null);
+ IFileStore store;
+ try {
+ store = EFS.getStore(workspace.getRoot().getLocationURI());
+ store = store.getChild(newProjectHandle.getName());
+ for (String deleteName : ignoreList) {
+ IFileStore projFile = store.getChild(deleteName);
+ projFile.delete(EFS.NONE, monitor);
+ }
+ exeProject = CCorePlugin.getDefault().createCProject(description, newProjectHandle, null, DEBUG_PROJECT_ID);
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ checkProject = true;
+ }
+
+ importExecutable(exeProject, path);
+ }
+ monitor.worked(1);
+ }
+ monitor.done();
+ }
+
+ private boolean executableExists(String path) {
+ Executable[] executables = ExecutablesManager.getExecutablesManager().getExecutables();
+ for (Executable executable : executables) {
+ if (executable.getPath().toOSString().equals(path))
+ return true;
+ }
+ return false;
+ }
+
+ private void importExecutable(IProject exeProject, String path) {
+
+ IPath location = Path.fromOSString(path);
+ String executableName = location.toFile().getName();
+ IFile exeFile = exeProject.getProject().getFile(executableName);
+ if (!exeFile.exists() && validateBinaryParsers(exeProject, new File(path))) {
+ try {
+ exeFile.createLink(location, 0, null);
+ } catch (Exception e) {
+ }
+ }
+
+ }
+
+ private boolean isExtensionVisible(IExtension ext) {
+ IConfigurationElement[] elements = ext.getConfigurationElements();
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement[] children = elements[i].getChildren("filter"); //$NON-NLS-1$
+ for (int j = 0; j < children.length; j++) {
+ String name = children[j].getAttribute("name"); //$NON-NLS-1$
+ if (name != null && name.equals("visibility")) { //$NON-NLS-1$
+ String value = children[j].getAttribute("value"); //$NON-NLS-1$
+ if (value != null && value.equals("private")) { //$NON-NLS-1$
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ return false; // invalid extension definition (must have at least
+ // cextension elements)
+ }
+
+ private IBinaryParser instantiateBinaryParser(IExtension ext) {
+ IBinaryParser parser = null;
+ IConfigurationElement[] elements = ext.getConfigurationElements();
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement[] children = elements[i].getChildren("run"); //$NON-NLS-1$
+ for (int j = 0; j < children.length; j++) {
+ try {
+ parser = (IBinaryParser) children[j].createExecutableExtension("class");
+ } catch (CoreException e) {
+ CDebugCorePlugin.log(e);
+ }
+ }
+ }
+ return parser;
+ }
+
+ private boolean validateBinaryParsers(IProject exeProject, File file) {
+ IExtension[] binaryParserExtensions;
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.BINARY_PARSER_SIMPLE_ID);
+ if (point != null) {
+ IExtension[] exts = point.getExtensions();
+ ArrayList<IExtension> extensionsInUse = new ArrayList<IExtension>();
+ for (int i = 0; i < exts.length; i++) {
+ if (isExtensionVisible(exts[i])) {
+ extensionsInUse.add(exts[i]);
+ }
+ }
+ binaryParserExtensions = extensionsInUse.toArray(new IExtension[extensionsInUse.size()]);
+
+ for (int i = 0; i < binaryParserExtensions.length; i++) {
+ IBinaryParser parser = instantiateBinaryParser(binaryParserExtensions[i]);
+ if (isBinary(file, parser)) {
+ String parserID = binaryParserExtensions[i].getUniqueIdentifier();
+ // Make sure the project has this parser
+ ICProjectDescription pd = CCorePlugin.getDefault().getProjectDescription(exeProject);
+ try {
+ pd.getDefaultSettingConfiguration().create(CCorePlugin.BINARY_PARSER_UNIQ_ID, parserID);
+ CCorePlugin.getDefault().setProjectDescription(exeProject, pd, true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ }
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private boolean isBinary(File file, IBinaryParser parser) {
+ if (parser != null) {
+ try {
+ IBinaryParser.IBinaryFile bin = parser.getBinary(new Path(file.getAbsolutePath()));
+ return bin != null && (bin.getType() == IBinaryParser.IBinaryFile.EXECUTABLE || bin.getType() == IBinaryParser.IBinaryFile.SHARED);
+ } catch (IOException e) {
+ return false;
+ }
+ } else
+ return false;
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java
new file mode 100644
index 00000000000..cdb81086350
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.core.executables;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
+import org.eclipse.cdt.internal.core.model.CModelManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class StandardExecutableProvider implements IResourceChangeListener, ICProjectDescriptionListener, IExecutableProvider {
+
+ private ArrayList<Executable> executables = new ArrayList<Executable>();
+
+ public StandardExecutableProvider() {
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
+ CoreModel.getDefault().getProjectDescriptionManager().addCProjectDescriptionListener(this,
+ CProjectDescriptionEvent.DATA_APPLIED | CProjectDescriptionEvent.LOADDED);
+ }
+
+ public void resourceChanged(IResourceChangeEvent event) {
+
+ // refresh when projects are opened or closed. note that deleted
+ // projects are handled later
+ // in this method. new projects are handled in handleEvent.
+ // resource changed events always start at the workspace root, so
+ // projects
+ // are the next level down
+ IResourceDelta[] projects = event.getDelta().getAffectedChildren();
+ for (IResourceDelta projectDelta : projects) {
+ if ((projectDelta.getFlags() & IResourceDelta.OPEN) != 0) {
+ if (projectDelta.getKind() == IResourceDelta.CHANGED) {
+ // project was opened or closed
+ ExecutablesManager.getExecutablesManager().scheduleRefresh(this, 0);
+ return;
+ }
+ }
+ }
+
+ try {
+ final StandardExecutableProvider provider = this;
+ event.getDelta().accept(new IResourceDeltaVisitor() {
+
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) {
+ IResource deltaResource = delta.getResource();
+ if (deltaResource != null) {
+ boolean refresh = false;
+ if (delta.getKind() == IResourceDelta.REMOVED && deltaResource instanceof IProject) {
+ // project deleted
+ refresh = true;
+ } else {
+ // see if a binary has been added/removed
+ IPath resourcePath = delta.getResource().getLocation();
+ if (resourcePath != null && Executable.isExecutableFile(resourcePath)) {
+ refresh = true;
+ }
+ }
+ if (refresh) {
+ ExecutablesManager.getExecutablesManager().scheduleRefresh(provider, 0);
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ });
+ } catch (CoreException e) {
+ }
+ }
+
+ public void handleEvent(CProjectDescriptionEvent event) {
+ // this handles the cases where the active build configuration changes,
+ // and when new
+ // projects are created.
+ boolean refresh = false;
+
+ int eventType = event.getEventType();
+
+ if (eventType == CProjectDescriptionEvent.DATA_APPLIED) {
+ // see if the active build config has changed
+ ICProjectDescription newDesc = event.getNewCProjectDescription();
+ ICProjectDescription oldDesc = event.getOldCProjectDescription();
+ if (oldDesc != null && newDesc != null) {
+ String newConfigName = newDesc.getActiveConfiguration().getName();
+ String oldConfigName = oldDesc.getActiveConfiguration().getName();
+ refresh = (!newConfigName.equals(oldConfigName));
+ } else if (newDesc != null && oldDesc == null) {
+ // project just created
+ refresh = true;
+ }
+ }
+
+ if (refresh) {
+ ExecutablesManager.getExecutablesManager().scheduleRefresh(this, 0);
+ }
+ }
+
+ public Collection<Executable> getExecutables(IProgressMonitor monitor) {
+ executables.clear();
+
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProject[] projects = root.getProjects();
+
+ monitor.beginTask("Checking C/C++ Projects", projects.length);
+
+ for (IProject project : projects) {
+
+ if (monitor.isCanceled())
+ break;
+
+ try {
+ if (CoreModel.hasCNature(project)) {
+ CModelManager manager = CModelManager.getDefault();
+ ICProject cproject = manager.create(project);
+ try {
+ IBinary[] binaries = cproject.getBinaryContainer().getBinaries();
+ for (IBinary binary : binaries) {
+ if (binary.isExecutable() || binary.isSharedLib()) {
+ IPath exePath = binary.getResource().getLocation();
+ if (exePath == null)
+ exePath = binary.getPath();
+ Executable exe = new Executable(exePath, project, binary.getResource());
+ executables.add(exe);
+ }
+ }
+ } catch (CModelException e) {
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ monitor.worked(1);
+ }
+ monitor.done();
+
+ return executables;
+ }
+
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardSourceFileRemapping.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardSourceFileRemapping.java
new file mode 100644
index 00000000000..001dd717dde
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardSourceFileRemapping.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia 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
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.core.executables;
+
+import org.eclipse.cdt.debug.core.CDebugCorePlugin;
+import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
+import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
+
+public class StandardSourceFileRemapping implements ISourceFileRemapping {
+
+ public String remapSourceFile(String filePath) {
+
+ try {
+ Object[] foundElements = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().findSourceElements(filePath);
+
+ if (foundElements.length == 0) {
+ Object foundElement = null;
+ ILaunchManager launchMgr = DebugPlugin.getDefault().getLaunchManager();
+ ILaunch[] launches = launchMgr.getLaunches();
+ for (ILaunch launch : launches) {
+ ISourceLocator locator = launch.getSourceLocator();
+ if (locator instanceof ICSourceLocator || locator instanceof CSourceLookupDirector) {
+ if (locator instanceof ICSourceLocator)
+ foundElement = ((ICSourceLocator) locator).findSourceElement(filePath);
+ else
+ foundElement = ((CSourceLookupDirector) locator).getSourceElement(filePath);
+ }
+ }
+ if (foundElement != null)
+ foundElements = new Object[] { foundElement };
+ }
+
+ if (foundElements.length == 1 && foundElements[0] instanceof LocalFileStorage) {
+ LocalFileStorage newLocation = (LocalFileStorage) foundElements[0];
+ filePath = newLocation.getFullPath().toOSString();
+ }
+
+ } catch (CoreException e) {
+ }
+ return filePath;
+ }
+
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java
index 4e99c16951f..38dead7aa3a 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java
@@ -24,7 +24,9 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
@@ -48,14 +50,22 @@ public class AbsolutePathSourceContainer extends AbstractSourceContainer {
return wfiles;
// The file is not already in the workspace so try to create an external translation unit for it.
- String projectName = getDirector().getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
- if (projectName != "") {
- ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName);
- if (project != null)
+ ISourceLookupDirector director = getDirector();
+ if (director != null)
+ {
+ ILaunchConfiguration launch = director.getLaunchConfiguration();
+ if (launch != null)
{
- IPath path = Path.fromOSString(file.getCanonicalPath());
- String id = CoreModel.getRegistedContentTypeId(project.getProject(), path.lastSegment());
- return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, file.toURI(), id) };
+ String projectName = getDirector().getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
+ if (projectName != "") {
+ ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName);
+ if (project != null)
+ {
+ IPath path = Path.fromOSString(file.getCanonicalPath());
+ String id = CoreModel.getRegistedContentTypeId(project.getProject(), path.lastSegment());
+ return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, file.toURI(), id) };
+ }
+ }
}
}
} catch (IOException e) { // ignore if getCanonicalPath throws

Back to the top