Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Overholt2011-02-28 14:50:42 -0500
committerAndrew Overholt2011-02-28 14:50:45 -0500
commita1289139b808537718337ec15eb0e28055f93ca2 (patch)
treeb71ba5d6077d204946111cfce745394816863bc6
parentbc592c2f83c27ad642b401965ad6bbdfa3595cb5 (diff)
parent0c607d02fab46c70af4c111065ae4c94603e5542 (diff)
downloadorg.eclipse.linuxtools-a1289139b808537718337ec15eb0e28055f93ca2.tar.gz
org.eclipse.linuxtools-a1289139b808537718337ec15eb0e28055f93ca2.tar.xz
org.eclipse.linuxtools-a1289139b808537718337ec15eb0e28055f93ca2.zip
Merge profiling 0.5.1
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.ui/ChangeLog18
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.ui/META-INF/MANIFEST.MF6
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.ui/src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java154
3 files changed, 177 insertions, 1 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.ui/ChangeLog b/profiling/org.eclipse.linuxtools.profiling.ui/ChangeLog
index 1492e166ce..d1163b8137 100644
--- a/profiling/org.eclipse.linuxtools.profiling.ui/ChangeLog
+++ b/profiling/org.eclipse.linuxtools.profiling.ui/ChangeLog
@@ -1,3 +1,21 @@
+2010-05-06 Roland Grunberg <rgrunber@redhat.com>
+
+ * src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java (findFunctionsInProject):
+ Use a stronger comparison when determining if two files have the same path.
+
+2010-04-08 Roland Grunberg <rgrunber@redhat.com>
+
+ * META-INF/MANIFEST.MF: Added imports needed for using CDT Indexer.
+ * src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java
+ (findCProjectWithAbsolutePath): New, for purpose of locating an ICProject.
+ (findFunctionsInProject): New, for purpose of finding data needed to link
+ to source code of a function call.
+
+2010-03-22 Roland Grunberg <rgrunber@redhat.com>
+
+ * src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java:
+ (openEditorAndSelect): Overload to take an offset and length.
+
2009-08-11 Elliott Baron <ebaron@redhat.com>
* META-INF/MANIFEST.MF: Bump version to 0.3.0.
diff --git a/profiling/org.eclipse.linuxtools.profiling.ui/META-INF/MANIFEST.MF b/profiling/org.eclipse.linuxtools.profiling.ui/META-INF/MANIFEST.MF
index 295f7edf1d..1fb4bdcdfe 100644
--- a/profiling/org.eclipse.linuxtools.profiling.ui/META-INF/MANIFEST.MF
+++ b/profiling/org.eclipse.linuxtools.profiling.ui/META-INF/MANIFEST.MF
@@ -12,7 +12,11 @@ Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.eclipse.linuxtools.internal.profiling.ui,
org.eclipse.linuxtools.profiling.ui
-Import-Package: org.eclipse.cdt.debug.core,
+Import-Package: org.eclipse.cdt.core,
+ org.eclipse.cdt.core.dom.ast,
+ org.eclipse.cdt.core.index,
+ org.eclipse.cdt.core.model,
+ org.eclipse.cdt.debug.core,
org.eclipse.core.filesystem,
org.eclipse.core.resources,
org.eclipse.debug.core.model,
diff --git a/profiling/org.eclipse.linuxtools.profiling.ui/src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java b/profiling/org.eclipse.linuxtools.profiling.ui/src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java
index 24defedc67..7e401dd61c 100644
--- a/profiling/org.eclipse.linuxtools.profiling.ui/src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java
+++ b/profiling/org.eclipse.linuxtools.profiling.ui/src/org/eclipse/linuxtools/profiling/ui/ProfileUIUtils.java
@@ -10,9 +10,28 @@
*******************************************************************************/
package org.eclipse.linuxtools.profiling.ui;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.index.IIndexFile;
+import org.eclipse.cdt.core.index.IIndexManager;
+import org.eclipse.cdt.core.index.IIndexName;
+import org.eclipse.cdt.core.index.IndexFilter;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICElementVisitor;
+import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.ui.DebugUITools;
@@ -104,4 +123,139 @@ public class ProfileUIUtils {
}
}
}
+
+ /**
+ * Open a file in the Editor at the specified offset, highlighting the given length
+ *
+ * @param path : Absolute path pointing to the file which will be opened.
+ * @param offset : Offset of the function to be highlighted.
+ * @param length : Length of the function to be highlighted.
+ * @throws PartInitException if the editor could not be initialized
+ */
+ public static void openEditorAndSelect(String path, int offset, int length) throws PartInitException {
+ Path p = new Path (path);
+
+ if (p.toFile().exists()) {
+ IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(p);
+
+ IEditorPart editor = IDE.openEditorOnFileStore(activePage, fileStore);
+ if (editor instanceof ITextEditor) {
+ ITextEditor text = (ITextEditor) editor;
+ text.selectAndReveal(offset, length);
+ }
+ }
+ }
+
+ /**
+ * Find an ICProject that contains the specified absolute path.
+ *
+ * @param absPath An absolute path (usually to some file/folder in a project)
+ * @return an ICProject corresponding to the project that contains the absolute path
+ * @throws CoreException
+ */
+ public static ICProject findCProjectWithAbsolutePath(final String absPath) throws CoreException{
+ final String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
+ final ArrayList<ICProject> ret = new ArrayList<ICProject>();
+
+ // visitor object to check for the matching path string
+ ICElementVisitor vis = new ICElementVisitor() {
+ public boolean visit(ICElement element) throws CoreException {
+ if (element.getElementType() == ICElement.C_CCONTAINER
+ || element.getElementType() == ICElement.C_PROJECT){
+ return true;
+ }else if (absPath.equals(workspaceLoc+element.getPath().toFile().getAbsolutePath())){
+ ret.add(element.getCProject());
+ }
+ return false;
+ }};
+
+ ICProject[] cProjects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects();
+ for (ICProject proj : cProjects){
+ // visit every project
+ proj.accept(vis);
+ }
+
+ // is it possible to find more than one matching project ?
+ return ret.size() == 0 ? null : ret.get(0);
+ }
+
+ /**
+ * Get a mapping between a file name, and the data relevant to locating
+ * the corresponding function name for a given project.
+ *
+ * @param project : C Project Type
+ * @param functionName : Name of a function
+ * @param numArgs : The number of arguments this function is expected to have.
+ * A value of -1 will ignore the number of arguments when searching.
+ * @param fileHint : The name of the file where we expect to find functionName.
+ * It is null if we do not want to use this option.
+ * @return a HashMap<String, int []> of String absolute paths of files and the
+ * function's corresponding node-offset and length.
+ */
+ public static HashMap<String,int[]> findFunctionsInProject(ICProject project, String functionName,
+ int numArgs, String fileHint) {
+ HashMap<String,int[]> files = new HashMap<String,int[]>() ;
+
+ IIndexManager manager = CCorePlugin.getIndexManager();
+ IIndex index = null;
+ try {
+ index = manager.getIndex(project);
+ index.acquireReadLock();
+ IBinding[] bindings = index.findBindings(functionName.toCharArray(), IndexFilter.ALL, null);
+ for (IBinding bind : bindings) {
+ if (bind instanceof IFunction
+ && (numArgs == -1 || ((IFunction)bind).getParameters().length == numArgs)) {
+ IFunction ifunction = (IFunction) bind;
+ IIndexName[] names = index.findNames(ifunction, IIndex.FIND_DEFINITIONS);
+ for (IIndexName iname : names) {
+ IIndexFile file = iname.getFile();
+ if (file != null) {
+ String loc = file.getLocation().getURI().getPath();
+ if (fileHint != null){
+ if (loc.equals(new File(fileHint).getCanonicalPath())){
+ //TODO: Consider changing data structure so that we can
+ // store multiple same-named functions (different args)
+ // from the same file.
+ files.put(loc, new int [] {iname.getNodeOffset(), iname.getNodeLength()});
+ }
+ }else{
+ files.put(loc, new int [] {iname.getNodeOffset(), iname.getNodeLength()});
+ }
+ }
+ }
+ }
+ }
+
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (DOMException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }finally{
+ index.releaseReadLock();
+ }
+ return files;
+ }
+
+ /**
+ * Helper function for findFunctionsInProject
+ * @param needResult True if the function should relax constraints in order
+ * to return some value. False if a failure to find the function(s) is acceptable.
+ */
+ public static HashMap<String,int[]> findFunctionsInProject(ICProject project, String functionName,
+ int numArgs, String fileHint, boolean needResult){
+ HashMap<String, int []> map = findFunctionsInProject(project, functionName, numArgs, fileHint);
+ if (needResult && map.size() == 0){
+ map = findFunctionsInProject(project, functionName, -1, fileHint);
+ if (map.size() == 0){
+ return findFunctionsInProject(project, functionName, -1, null);
+ }
+ }
+ return map;
+ }
+
}

Back to the top