Search in sources :

Example 1 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class OpenGCAction method getDefaultBinary.

private String getDefaultBinary(IPath file) {
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
    if (c != null) {
        IProject project = c.getProject();
        if (project != null && project.exists()) {
            IContainer folder = c.getParent();
            // $NON-NLS-1$
            IFile infoFile = folder.getFile(new Path("AnalysisInfo.txt"));
            try {
                String defaultBinaryFromUserPref = getDefaultBinaryFromUserPref(project, infoFile);
                if (defaultBinaryFromUserPref != null) {
                    return defaultBinaryFromUserPref;
                }
            } catch (IOException | CoreException ex) {
            // do nothing here.
            }
            ICProject cproject = CoreModel.getDefault().create(project);
            if (cproject != null) {
                try {
                    IBinary[] b = cproject.getBinaryContainer().getBinaries();
                    if (b != null && b.length > 0 && b[0] != null) {
                        IResource r = b[0].getResource();
                        return r.getLocation().toOSString();
                    }
                } catch (CModelException e) {
                }
            }
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) IOException(java.io.IOException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 2 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class GcovAnnotationModel method findSourceCoverageForElement.

private SourceFile findSourceCoverageForElement(ICElement element) {
    List<SourceFile> sources = new ArrayList<>();
    ICProject cProject = element.getCProject();
    IResource elementResource = element.getResource();
    IPath target = GcovAnnotationModelTracker.getInstance().getBinaryPath(cProject.getProject());
    if (target == null) {
        // We cannot find a target for this element, using it's project.
        // This can be caused by linking in a file to the project which may
        // not have a project or may point to another unseen project if the file originated
        // there.
        IProject[] trackedProjects = GcovAnnotationModelTracker.getInstance().getTrackedProjects();
        for (IProject proj : trackedProjects) {
            // element is linked in.
            try {
                FindLinkedResourceVisitor visitor = new FindLinkedResourceVisitor(element);
                proj.accept(visitor, IResource.DEPTH_INFINITE);
                // If we find a match, make note of the target and the real C project.
                if (visitor.foundElement()) {
                    target = GcovAnnotationModelTracker.getInstance().getBinaryPath(proj);
                    cProject = CoreModel.getDefault().getCModel().getCProject(proj.getName());
                    elementResource = visitor.getResource();
                    break;
                }
            } catch (CoreException e) {
            }
        }
        if (target == null) {
            return null;
        }
    }
    try {
        IBinary[] binaries = cProject.getBinaryContainer().getBinaries();
        for (IBinary b : binaries) {
            if (b.getResource().getLocation().equals(target)) {
                CovManager covManager = new CovManager(b.getResource().getLocation().toOSString());
                covManager.processCovFiles(covManager.getGCDALocations(), null);
                sources.addAll(covManager.getAllSrcs());
            }
        }
    } catch (IOException | CoreException | InterruptedException e) {
    }
    if (elementResource != null) {
        IPath elementLocation = elementResource.getLocation();
        if (elementLocation != null) {
            for (SourceFile sf : sources) {
                IPath sfPath = new Path(sf.getName());
                IFile file = STLink2SourceSupport.getFileForPath(sfPath, cProject.getProject());
                if (file != null && elementLocation.equals(file.getLocation())) {
                    return sf;
                }
                // the sources.  Fixes Bug 447554
                if (!sfPath.isAbsolute()) {
                    sfPath = target.removeLastSegments(1).append(sf.getName());
                    if (elementLocation.equals(sfPath.makeAbsolute()) && sfPath.toFile().exists())
                        return sf;
                }
            }
        }
    }
    URI elementURI = element.getLocationURI();
    if (elementURI != null) {
        IPath binFolder = target.removeLastSegments(1);
        for (SourceFile sf : sources) {
            String sfPath = Paths.get(binFolder.toOSString()).resolve(sf.getName()).normalize().toString();
            if (sfPath.equals(elementURI.getPath())) {
                return sf;
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IBinary(org.eclipse.cdt.core.model.IBinary) IOException(java.io.IOException) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) CovManager(org.eclipse.linuxtools.internal.gcov.parser.CovManager) CoreException(org.eclipse.core.runtime.CoreException) SourceFile(org.eclipse.linuxtools.internal.gcov.parser.SourceFile) IResource(org.eclipse.core.resources.IResource)

Example 3 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class LaunchShortcutsTest method testLaunchCallGraph.

@Test
public void testLaunchCallGraph() throws CModelException {
    SystemTapUIErrorMessages.setActive(false);
    LaunchStapGraph launch = new LaunchStapGraph();
    launch.setTestMode(true);
    IBinary bin = proj.getBinaryContainer().getBinaries()[0];
    launch.launch(bin, "profile");
    String script = launch.getScript();
    assert (script.contains("probe process(@1).function(\"calledOnce\").call{    callFunction(probefunc())    }    probe process(@1).function(\"calledOnce\").return{        returnFunction(probefunc())    }"));
    assert (script.contains("probe process(@1).function(\"calledTwice\").call{    callFunction(probefunc())    }    probe process(@1).function(\"calledTwice\").return{        returnFunction(probefunc())    }"));
    assert (script.contains("probe process(@1).function(\"main\").call{    callFunction(probefunc())    }    probe process(@1).function(\"main\").return{        returnFunction(probefunc())    }"));
}
Also used : LaunchStapGraph(org.eclipse.linuxtools.internal.callgraph.launch.LaunchStapGraph) IBinary(org.eclipse.cdt.core.model.IBinary) Test(org.junit.Test)

Example 4 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class SystemTapOptionsTab method getBinary.

private IBinary getBinary(ILaunchConfiguration config) {
    try {
        ICProject project = CDebugUtils.verifyCProject(config);
        IBinary[] binaries = project.getBinaryContainer().getBinaries();
        if (binaries != null && binaries.length > 0) {
            if (binaries.length == 1 && binaries[0] != null) {
                return binaries[0];
            } else
                return chooseBinary(binaries);
        }
        return null;
    } catch (CoreException e) {
        return null;
    }
}
Also used : ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IBinary(org.eclipse.cdt.core.model.IBinary)

Example 5 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class SystemTapOptionsTab method chooseBinary.

private IBinary chooseBinary(IBinary[] binaries) {
    ILabelProvider programLabelProvider = new CElementLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IBinary) {
                IBinary bin = (IBinary) element;
                StringBuffer name = new StringBuffer();
                name.append(bin.getPath().lastSegment());
                return name.toString();
            }
            return super.getText(element);
        }
    };
    ILabelProvider qualifierLabelProvider = new CElementLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IBinary) {
                IBinary bin = (IBinary) element;
                StringBuffer name = new StringBuffer();
                // $NON-NLS-1$ //$NON-NLS-2$
                name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be"));
                // $NON-NLS-1$
                name.append(" - ");
                name.append(bin.getPath().toString());
                return name.toString();
            }
            return super.getText(element);
        }
    };
    TwoPaneElementSelector dialog = new TwoPaneElementSelector(getActiveWorkbenchShell(), programLabelProvider, qualifierLabelProvider);
    dialog.setElements(binaries);
    // $NON-NLS-1$
    dialog.setTitle(Messages.getString("SystemtTapOptionsTab.Callgraph"));
    // $NON-NLS-1$
    dialog.setMessage(Messages.getString("SystemtTapOptionsTab.Choose_a_local_application"));
    // $NON-NLS-1$
    dialog.setUpperListLabel(Messages.getString("SystemtTapOptionsTab.Binaries"));
    // $NON-NLS-1$
    dialog.setLowerListLabel(Messages.getString("SystemtTapOptionsTab.Qualifier"));
    dialog.setMultipleSelection(false);
    if (dialog.open() == Window.OK) {
        return (IBinary) dialog.getFirstResult();
    }
    return null;
}
Also used : CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IBinary(org.eclipse.cdt.core.model.IBinary) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector)

Aggregations

IBinary (org.eclipse.cdt.core.model.IBinary)12 ICProject (org.eclipse.cdt.core.model.ICProject)7 CoreException (org.eclipse.core.runtime.CoreException)5 CElementLabelProvider (org.eclipse.cdt.ui.CElementLabelProvider)4 IProject (org.eclipse.core.resources.IProject)4 IResource (org.eclipse.core.resources.IResource)4 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)4 TwoPaneElementSelector (org.eclipse.ui.dialogs.TwoPaneElementSelector)4 CModelException (org.eclipse.cdt.core.model.CModelException)3 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ICElement (org.eclipse.cdt.core.model.ICElement)2 Path (org.eclipse.core.runtime.Path)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 Collections (java.util.Collections)1 List (java.util.List)1 CoreModel (org.eclipse.cdt.core.model.CoreModel)1