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 "";
}
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;
}
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()) }"));
}
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;
}
}
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;
}
Aggregations