Search in sources :

Example 6 with ValgrindStackFrame

use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame 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 7 with ValgrindStackFrame

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

the class AbstractMemcheckTest method checkTestMessages.

/**
 * Check messages appear as expected for the specified test.
 *
 * @param messages IValgrindMessage messages
 * @param testName test name
 */
public void checkTestMessages(IValgrindMessage[] messages, String testName) {
    assertTrue(messages.length > 0);
    // $NON-NLS-1$
    String lostBytesMsg = "10 bytes in 1 blocks are definitely lost in loss record 1 of 1";
    // $NON-NLS-1$
    String invalidReadMsg = "Invalid read of size 1";
    // $NON-NLS-1$
    String invalidWriteMsg = "Invalid write of size 1";
    for (IValgrindMessage message : messages) {
        for (IValgrindMessage child : message.getChildren()) {
            if (child instanceof ValgrindStackFrame) {
                ValgrindStackFrame stackFrameMsg = (ValgrindStackFrame) child;
                // check expected error messages exist for basicTest (child process in multiProcTest)
                if (// $NON-NLS-1$ //$NON-NLS-2$
                ("testNumErrors".equals(testName) || "testExec".equals(testName)) && "test.c".equals(stackFrameMsg.getFile())) {
                    // $NON-NLS-1$
                    assertTrue(stackFrameMsg.getLine() >= 15);
                    switch(stackFrameMsg.getLine()) {
                        case 15:
                            assertTrue(message.getText().contains(lostBytesMsg));
                            break;
                        case 16:
                            assertTrue(message.getText().contains(invalidReadMsg));
                            break;
                        case 17:
                            assertTrue(message.getText().contains(invalidWriteMsg));
                            break;
                        default:
                            break;
                    }
                }
                // check expected error messages exist for parent process in multiProcTest
                if (// $NON-NLS-1$ //$NON-NLS-2$
                ("testNoExec".equals(testName) || "testExec".equals(testName)) && "parent.c".equals(stackFrameMsg.getFile())) {
                    // $NON-NLS-1$
                    assertEquals(8, stackFrameMsg.getLine());
                    assertTrue(child.getParent().getText().contains(lostBytesMsg));
                }
            }
        }
    }
}
Also used : IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)

Example 8 with ValgrindStackFrame

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

the class DoubleClickTest method doDoubleClick.

private void doDoubleClick() {
    ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
    CoreMessagesViewer viewer = view.getMessagesViewer();
    // get first leaf
    IValgrindMessage[] elements = (IValgrindMessage[]) viewer.getTreeViewer().getInput();
    IValgrindMessage element = elements[0];
    TreePath path = new TreePath(new Object[] { element });
    frame = null;
    while (element.getChildren().length > 0) {
        element = element.getChildren()[0];
        path = path.createChildPath(element);
        if (element instanceof ValgrindStackFrame) {
            frame = (ValgrindStackFrame) element;
        }
    }
    assertNotNull(frame);
    viewer.getTreeViewer().expandToLevel(frame, AbstractTreeViewer.ALL_LEVELS);
    TreeSelection selection = new TreeSelection(path);
    // do double click
    IDoubleClickListener listener = viewer.getDoubleClickListener();
    listener.doubleClick(new DoubleClickEvent(viewer.getTreeViewer(), selection));
}
Also used : ValgrindViewPart(org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CoreMessagesViewer(org.eclipse.linuxtools.internal.valgrind.ui.CoreMessagesViewer)

Example 9 with ValgrindStackFrame

use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame 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 10 with ValgrindStackFrame

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

the class WrongDeallocationResolution method getMessage.

/**
 * Returns the {@link IValgrindMessage} element from the Valgrind View that represents
 * a given Marker
 * @param marker the marker to which the ValgrindMessage relates
 * @return {@link IValgrindMessage} that represents the {@link IMarker}
 */
private IValgrindMessage getMessage(IMarker marker) {
    IValgrindMessage message = null;
    String file = marker.getResource().getName();
    int line = marker.getAttribute(IMarker.LINE_NUMBER, 0);
    // $NON-NLS-1$
    IValgrindMessage[] wrongDeallocMessages = getMessagesByText(Messages.getString("ValgrindMemcheckQuickFixes.Wrong_dealloc_message"));
    for (IValgrindMessage wrongDeallocMessage : wrongDeallocMessages) {
        ValgrindStackFrame stackBottom = getStackBottom(wrongDeallocMessage);
        int stackBottomLine = stackBottom.getLine();
        String stackBottomFile = stackBottom.getFile();
        if (stackBottomLine == line && file != null && stackBottomFile.endsWith(file)) {
            message = stackBottom;
        }
    }
    return message;
}
Also used : IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)

Aggregations

ValgrindStackFrame (org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)10 IValgrindMessage (org.eclipse.linuxtools.valgrind.core.IValgrindMessage)10 IMarker (org.eclipse.core.resources.IMarker)3 ValgrindError (org.eclipse.linuxtools.internal.valgrind.core.ValgrindError)3 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 TreePath (org.eclipse.jface.viewers.TreePath)2 TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 CoreMessagesViewer (org.eclipse.linuxtools.internal.valgrind.ui.CoreMessagesViewer)2 ValgrindViewPart (org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart)2 URI (java.net.URI)1 Stack (java.util.Stack)1 IASTNode (org.eclipse.cdt.core.dom.ast.IASTNode)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1