Search in sources :

Example 6 with IValgrindMessage

use of org.eclipse.linuxtools.valgrind.core.IValgrindMessage in project linuxtools by eclipse.

the class MultiProcessTest method testExec.

@Test
public void testExec() throws Exception {
    ILaunchConfigurationWorkingCopy config = createConfiguration(proj.getProject()).getWorkingCopy();
    config.setAttribute(LaunchConfigurationConstants.ATTR_GENERAL_TRACECHILD, true);
    config.doSave();
    // $NON-NLS-1$
    doLaunch(config, "testExec");
    IValgrindMessage[] messages = ValgrindUIPlugin.getDefault().getView().getMessages();
    assertEquals(4, messages.length);
    // $NON-NLS-1$
    checkTestMessages(messages, "testExec");
}
Also used : IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Test(org.junit.Test)

Example 7 with IValgrindMessage

use of org.eclipse.linuxtools.valgrind.core.IValgrindMessage in project linuxtools by eclipse.

the class SignalTest method testSegfaultHandle.

@Test
public void testSegfaultHandle() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testSegfault");
    ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
    IValgrindMessage[] messages = view.getMessages();
    assertTrue(messages.length > 0);
    // $NON-NLS-1$
    assertTrue(messages[0].getText().contains("SIGSEGV"));
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ValgrindViewPart(org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) Test(org.junit.Test)

Example 8 with IValgrindMessage

use of org.eclipse.linuxtools.valgrind.core.IValgrindMessage in project linuxtools by eclipse.

the class WrongDeallocationResolution method getAllocFunction.

/**
 * Returns the allocation function that relates to the given marker
 * @param marker {@link IMarker} object that points to where the wrong de-allocation function is
 * @return {@link String} object containing the allocation function
 * @throws BadLocationException
 */
private String getAllocFunction(IMarker marker, IDocument document) throws BadLocationException {
    IValgrindMessage allocMessage = 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)) {
            allocMessage = getStackBottom(getNestedStack(wrongDeallocMessage));
        }
    }
    if (allocMessage instanceof ValgrindStackFrame) {
        int allocLine = ((ValgrindStackFrame) allocMessage).getLine() - 1;
        int allocOffset = document.getLineOffset(allocLine);
        int allocLength = document.getLineLength(allocLine);
        return document.get(allocOffset, allocLength);
    }
    return null;
}
Also used : IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)

Example 9 with IValgrindMessage

use of org.eclipse.linuxtools.valgrind.core.IValgrindMessage in project linuxtools by eclipse.

the class WrongDeallocationResolution method apply.

@Override
public void apply(IMarker marker, IDocument document) {
    try {
        IASTNode astNode = getIASTNode(marker, document);
        if (astNode != null) {
            int nodeLength = astNode.getFileLocation().getNodeLength();
            int nodeOffset = astNode.getFileLocation().getNodeOffset();
            String content = document.get(nodeOffset, nodeLength);
            if (content.contains(DELETE)) {
                String allocFunction = getAllocFunction(marker, document);
                if (allocFunction.contains(NEW)) {
                    // $NON-NLS-1$
                    content = document.get(nodeOffset, nodeLength).replace(DELETE, DELETE + "[]");
                    document.replace(nodeOffset, nodeLength, content);
                } else {
                    addParentheses(astNode, document);
                    if (content.contains("[")) {
                        // $NON-NLS-1$
                        removeBrackets(astNode, document);
                    }
                    content = document.get(nodeOffset, nodeLength).replace(DELETE, FREE);
                    document.replace(nodeOffset, nodeLength, content);
                }
            } else if (content.contains(FREE)) {
                if (getAllocFunction(marker, document).contains("[")) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$
                    content = content.concat("[]");
                }
                content = content.replace(FREE, DELETE);
                document.replace(nodeOffset, nodeLength, content);
            }
            IValgrindMessage message = getMessage(marker);
            removeMessage(message.getParent());
            ValgrindStackFrame nestedStackFrame = getStackBottom(getNestedStack(message.getParent()));
            int nestedLine = nestedStackFrame.getLine();
            String nestedFile = nestedStackFrame.getFile();
            removeMarker(nestedFile, nestedLine, marker.getType());
            marker.delete();
        }
    } catch (BadLocationException | CoreException e) {
        Status status = new Status(IStatus.ERROR, ValgrindUIPlugin.PLUGIN_ID, null, e);
        // $NON-NLS-1$
        String title = Messages.getString("ValgrindMemcheckQuickFixes.Valgrind_error_title");
        // $NON-NLS-1$
        String message = Messages.getString("ValgrindMemcheckQuickFixes.Error_applying_quickfix");
        showErrorMessage(title, message, status);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) CoreException(org.eclipse.core.runtime.CoreException) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 10 with IValgrindMessage

use of org.eclipse.linuxtools.valgrind.core.IValgrindMessage in project linuxtools by eclipse.

the class WrongDeallocationResolution method getStackBottom.

/**
 * Return the last nested element from a given {@link IValgrindMessage}, or null if there are
 * no nested messages.
 * @param message
 * @return The {@link ValgrindStackFrame} in the bottom of the nested stack
 */
private ValgrindStackFrame getStackBottom(IValgrindMessage message) {
    ValgrindStackFrame stackBottom = null;
    IValgrindMessage[] children = message.getChildren();
    for (IValgrindMessage child : children) {
        if (child instanceof ValgrindStackFrame) {
            stackBottom = (ValgrindStackFrame) child;
        }
    }
    return stackBottom;
}
Also used : IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)

Aggregations

IValgrindMessage (org.eclipse.linuxtools.valgrind.core.IValgrindMessage)24 ValgrindStackFrame (org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)10 ValgrindViewPart (org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart)10 Test (org.junit.Test)9 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 ArrayList (java.util.ArrayList)5 IMarker (org.eclipse.core.resources.IMarker)5 TreePath (org.eclipse.jface.viewers.TreePath)4 TreeSelection (org.eclipse.jface.viewers.TreeSelection)4 ValgrindError (org.eclipse.linuxtools.internal.valgrind.core.ValgrindError)4 IFile (org.eclipse.core.resources.IFile)3 CoreException (org.eclipse.core.runtime.CoreException)3 IPath (org.eclipse.core.runtime.IPath)3 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Status (org.eclipse.core.runtime.Status)2