diff options
author | Jeff Johnston | 2018-05-22 22:29:35 +0000 |
---|---|---|
committer | Jeff Johnston | 2018-05-29 19:20:00 +0000 |
commit | da57b8881279310261a67159992135d140ca8c20 (patch) | |
tree | e42d7bcaf8d126cde837d7ab4a9bd68df2616d9d /profiling | |
parent | 8bc138b9db3e727c9183a82828e6660a02a17092 (diff) | |
download | org.eclipse.linuxtools-da57b8881279310261a67159992135d140ca8c20.tar.gz org.eclipse.linuxtools-da57b8881279310261a67159992135d140ca8c20.tar.xz org.eclipse.linuxtools-da57b8881279310261a67159992135d140ca8c20.zip |
Bug 494296 - GCov plugin handling of linked resources
- modify STSymbolManager and add 3 new methods:
(1) findFileFromPath to find linked resource
(2) getProjectFromFile to resolve project from file
(3) findOneAndOnlyBinary to find binary which can be linked
- replace all occurences of getFileForLocation by
STSymbolManager.sharedInstance.findFileFromPath
Change-Id: I551452e969552e4b5cea7cc2fc5fc0ba46d0063f
Reviewed-on: https://git.eclipse.org/r/123109
Tested-by: CI Bot
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
Diffstat (limited to 'profiling')
4 files changed, 156 insertions, 5 deletions
diff --git a/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java b/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java index 452e3425d7..15c41a46f8 100644 --- a/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java +++ b/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java @@ -45,6 +45,7 @@ import org.eclipse.debug.core.sourcelookup.ISourceContainer; import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; +import org.eclipse.linuxtools.binutils.utils.STSymbolManager; import org.eclipse.linuxtools.internal.Activator; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; @@ -74,7 +75,8 @@ public final class STLink2SourceSupport { */ private static boolean openSourceFileAtLocation(IPath binaryLoc, IPath sourceLoc, int lineNumber) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFile binary = root.getFileForLocation(binaryLoc); + //FIXME EK-LINUXTOOLS: IFile binary = root.getFileForLocation(binaryLoc); + IFile binary = STSymbolManager.sharedInstance.findFileFromPath(binaryLoc); IProject project = null; if (binary != null) { project = binary.getProject(); @@ -257,7 +259,8 @@ public final class STLink2SourceSupport { private static IFile getFileForPathImpl(IPath path, IProject project) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (path.isAbsolute()) { - return root.getFileForLocation(path); + //FIXME EK-LINUXTOOLS: return root.getFileForLocation(path); + return STSymbolManager.sharedInstance.findFileFromPath(path); } if (project != null && project.exists()) { diff --git a/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java b/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java index 19d4e0c5c4..205287157a 100644 --- a/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java +++ b/profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java @@ -15,6 +15,7 @@ package org.eclipse.linuxtools.binutils.utils; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -36,9 +37,11 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.utils.Addr2line; import org.eclipse.cdt.utils.CPPFilt; +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.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -381,7 +384,8 @@ public class STSymbolManager { * @return a IBinaryObject */ private IBinaryObject getBinaryObject(IPath path, IBinaryParser defaultparser) { - IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + //FIXME EK-LINUXTOOLS: IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + IFile c = findFileFromPath(path); List<IBinaryParser> parsers; if (c != null) { IBinaryObject object = getAlreadyExistingBinaryObject(c); @@ -428,6 +432,148 @@ public class STSymbolManager { return ret; } + //FIXME EK-LINUXTOOLS: Search workspace for one binary + /** + * Searches workspace and tries to find one-and-only binary which could have + * created GCOV files. + * 1. Look in the project where .gcda or .gcna file are registered + * 2. Search workspace and list all binaries + * 3. If there is only one binary found then return it + * + * @param file + * @return Binary path or null + * @since 6.0 + */ + public IResource findOneAndOnlyBinary(IPath file) + { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource project; + IResource binary = null; + + project = STSymbolManager.sharedInstance.getProjectFromFile(file); + if (project != null && project.exists()) + { + ICProject cproject = (ICProject)CoreModel.getDefault().create(project); + if (cproject != null) + { + try + { + IBinary[] bs = cproject.getBinaryContainer().getBinaries(); + if (bs.length == 1) + { + binary = bs[0].getResource(); + } + } + catch (CModelException e) + { + String message = + "Error getting binaries for [" + cproject.toString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + CCorePlugin.log(message, e); + } + } + } + + if (binary == null) + { + /* + * Apparently we did not find one binary in the project + * where GCOV files are located. + * Search workspace in hopes that there will be only one binary there + */ + ArrayList<IResource> binaries = new ArrayList<>(); + IProject projects[] = root.getProjects(); + for (IProject prj : projects) + { + ICProject cproject = CoreModel.getDefault().create(prj); + if (cproject != null) + { + try + { + IBinary[] bs = cproject.getBinaryContainer().getBinaries(); + if (bs.length == 1) + { + /* + * Validate binary. Not tested + */ + IBinaryObject binObj = + STSymbolManager.sharedInstance.getBinaryObject(bs[0].getPath()); + if (binObj != null) + { + binaries.add(bs[0].getResource()); + } + } + } + catch (CModelException e) + { + String message = + "Error getting binaries for [" + cproject.toString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + CCorePlugin.log(message, e); + } + } + + } + + if (binaries.size() == 1) + { + binary = binaries.get(0); + } + } + + return (binary); + } + + //FIXME EK-LINUXTOOLS: New method to get location for linked binary resource + /** + * @param file + * @return + * @since 6.0 + */ + public IFile findFileFromPath(IPath file) + { + // can't use a null or empty path below + if (file == null || file.isEmpty()) { + return null; + } + + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + /* + * Find resource to which this GCOV file maps to in workspace + */ + IFile files[] = root.findFilesForLocationURI(URIUtil.toURI(file)); + if ((files.length == 0) || (files.length > 1)) + { + /* + * Nothing found or more than one GCOV output file + * Let user decide what to use as binary + */ + return (null); + } + return files[0]; + } + + //FIXME EK-LINUXTOOLS: IProject file resolution for linked resources + /** + * @param file + * @return + * @since 6.0 + */ + public IProject getProjectFromFile(IPath file) + { + IFile ifile = findFileFromPath(file); + if (ifile == null) + { + /* + * Nothing found or more than one GCOV output file + * Let upstream processing handle this exception + */ + return (null); + } + /* + * Find project this resource belongs to + */ + return (ifile.getProject()); + } + /** * Validate the binary file. In particular, verify that this binary file can be decoded. * @param o diff --git a/profiling/org.eclipse.linuxtools.dataviewers/META-INF/MANIFEST.MF b/profiling/org.eclipse.linuxtools.dataviewers/META-INF/MANIFEST.MF index 32d460c6a0..96ebfa0bb5 100644 --- a/profiling/org.eclipse.linuxtools.dataviewers/META-INF/MANIFEST.MF +++ b/profiling/org.eclipse.linuxtools.dataviewers/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-Vendor: %bundleProvider Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.ui, + org.eclipse.linuxtools.binutils, org.eclipse.ui.ide Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.linuxtools.dataviewers, diff --git a/profiling/org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersCSVExporter.java b/profiling/org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersCSVExporter.java index c3fb81c6f4..71da36403c 100644 --- a/profiling/org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersCSVExporter.java +++ b/profiling/org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersCSVExporter.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -35,6 +34,7 @@ import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.linuxtools.binutils.utils.STSymbolManager; import org.eclipse.linuxtools.dataviewers.STDataViewersActivator; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Item; @@ -374,7 +374,8 @@ public class STDataViewersCSVExporter { // end monitoring monitor.done(); - IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(getFilePath())); + //FIXME EK-LINUXTOOLS: IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(getFilePath())); + IFile c = STSymbolManager.sharedInstance.findFileFromPath(new Path(getFilePath())); if (c != null) { try { c.refreshLocal(1, new NullProgressMonitor()); |