Search in sources :

Example 1 with ValgrindError

use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindError in project linuxtools by eclipse.

the class LinkedResourceMarkerTest method findMarker.

private void findMarker(ArrayList<IMarker> markers, IValgrindMessage error) throws Exception, CoreException {
    ValgrindStackFrame frame = null;
    IValgrindMessage[] children = error.getChildren();
    for (int i = 0; i < children.length; i++) {
        if (frame == null && children[i] instanceof ValgrindStackFrame && isWorkspaceFrame((ValgrindStackFrame) children[i])) {
            frame = (ValgrindStackFrame) children[i];
        } else if (children[i] instanceof ValgrindError) {
            findMarker(markers, children[i]);
        }
    }
    int ix = -1;
    for (int i = 0; i < markers.size(); i++) {
        IMarker marker = markers.get(i);
        if (marker.getAttribute(IMarker.MESSAGE).equals(error.getText()) && marker.getResource().getName().equals(frame.getFile()) && marker.getAttribute(IMarker.LINE_NUMBER).equals(frame.getLine())) {
            ix = i;
        }
    }
    assertFalse(ix < 0);
    markers.remove(ix);
}
Also used : ValgrindError(org.eclipse.linuxtools.internal.valgrind.core.ValgrindError) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IMarker(org.eclipse.core.resources.IMarker)

Example 2 with ValgrindError

use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindError in project linuxtools by eclipse.

the class ValgrindLaunchConfigurationDelegate method createMarkers.

private void createMarkers(IValgrindMessage[] messages) throws CoreException {
    // find the topmost stack frame within the workspace to annotate with marker
    // traverse nested errors as well
    Stack<IValgrindMessage> messageStack = new Stack<>();
    messageStack.addAll(Arrays.asList(messages));
    while (!messageStack.isEmpty()) {
        IValgrindMessage message = messageStack.pop();
        IMarker marker = null;
        IValgrindMessage[] children = message.getChildren();
        for (int i = 0; i < children.length; i++) {
            // if we've found our marker we don't care about any further frames in this stack
            if (children[i] instanceof ValgrindStackFrame && marker == null) {
                ValgrindStackFrame frame = (ValgrindStackFrame) children[i];
                if (frame.getLine() > 0) {
                    ISourceLocator locator = frame.getSourceLocator();
                    ISourceLookupResult result = DebugUITools.lookupSource(frame.getFile(), locator);
                    Object sourceElement = result.getSourceElement();
                    if (sourceElement != null) {
                        // Resolve IResource in case we get a LocalFileStorage object
                        if (sourceElement instanceof LocalFileStorage) {
                            IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
                            URI fileURI = URIUtil.toURI(filePath);
                            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                            IFile[] files = root.findFilesForLocationURI(fileURI);
                            if (files.length > 0) {
                                // Take the first match
                                sourceElement = files[0];
                            }
                        }
                        if (sourceElement instanceof IResource) {
                            IResource resource = (IResource) sourceElement;
                            marker = resource.createMarker(ValgrindLaunchPlugin.MARKER_TYPE);
                            marker.setAttribute(IMarker.MESSAGE, message.getText());
                            marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                            marker.setAttribute(IMarker.LINE_NUMBER, frame.getLine());
                        }
                    }
                }
            } else if (children[i] instanceof ValgrindError) {
                // nested error
                messageStack.push(children[i]);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) IPath(org.eclipse.core.runtime.IPath) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) URI(java.net.URI) Stack(java.util.Stack) ValgrindError(org.eclipse.linuxtools.internal.valgrind.core.ValgrindError) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ISourceLookupResult(org.eclipse.debug.ui.sourcelookup.ISourceLookupResult) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IMarker(org.eclipse.core.resources.IMarker) ISourceLocator(org.eclipse.debug.core.model.ISourceLocator) IResource(org.eclipse.core.resources.IResource)

Example 3 with ValgrindError

use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindError in project linuxtools by eclipse.

the class MarkerTest method findMarker.

private void findMarker(ArrayList<IMarker> markers, IValgrindMessage error) throws Exception, CoreException {
    ValgrindStackFrame frame = null;
    IValgrindMessage[] children = error.getChildren();
    for (int i = 0; i < children.length; i++) {
        if (frame == null && children[i] instanceof ValgrindStackFrame && isWorkspaceFrame((ValgrindStackFrame) children[i])) {
            frame = (ValgrindStackFrame) children[i];
        } else if (children[i] instanceof ValgrindError) {
            findMarker(markers, children[i]);
        }
    }
    int ix = -1;
    for (int i = 0; i < markers.size(); i++) {
        IMarker marker = markers.get(i);
        if (marker.getAttribute(IMarker.MESSAGE).equals(error.getText()) && marker.getResource().getName().equals(frame.getFile()) && marker.getAttribute(IMarker.LINE_NUMBER).equals(frame.getLine())) {
            ix = i;
        }
    }
    assertFalse(ix < 0);
    markers.remove(ix);
}
Also used : ValgrindError(org.eclipse.linuxtools.internal.valgrind.core.ValgrindError) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IMarker(org.eclipse.core.resources.IMarker)

Example 4 with ValgrindError

use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindError in project linuxtools by eclipse.

the class WrongDeallocationResolution method getNestedStack.

/**
 * Returns the nested stack from a given ValgrindMessage in the Valgrind View
 * @param message The message from which the stack will be acquired
 * @return {@link ValgrindError} object containing the nested stack
 */
private ValgrindError getNestedStack(IValgrindMessage message) {
    ValgrindError nestedError = null;
    IValgrindMessage[] children = message.getChildren();
    for (IValgrindMessage child : children) {
        if (child instanceof ValgrindError) {
            nestedError = (ValgrindError) child;
        }
    }
    return nestedError;
}
Also used : ValgrindError(org.eclipse.linuxtools.internal.valgrind.core.ValgrindError) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage)

Aggregations

ValgrindError (org.eclipse.linuxtools.internal.valgrind.core.ValgrindError)4 IValgrindMessage (org.eclipse.linuxtools.valgrind.core.IValgrindMessage)4 IMarker (org.eclipse.core.resources.IMarker)3 ValgrindStackFrame (org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)3 URI (java.net.URI)1 Stack (java.util.Stack)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IPath (org.eclipse.core.runtime.IPath)1 ISourceLocator (org.eclipse.debug.core.model.ISourceLocator)1 LocalFileStorage (org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage)1 ISourceLookupResult (org.eclipse.debug.ui.sourcelookup.ISourceLookupResult)1