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