Search in sources :

Example 1 with Field

use of com.sun.jdi.Field in project che by eclipse.

the class JdiStackFrameImpl method getFields.

@Override
public JdiField[] getFields() throws DebuggerException {
    if (fields == null) {
        try {
            ObjectReference object = stackFrame.thisObject();
            if (object == null) {
                ReferenceType type = stackFrame.location().declaringType();
                List<Field> fs = stackFrame.location().declaringType().allFields();
                fields = new JdiField[fs.size()];
                int i = 0;
                for (Field f : fs) {
                    fields[i++] = new JdiFieldImpl(f, type);
                }
            } else {
                List<Field> fs = object.referenceType().allFields();
                fields = new JdiField[fs.size()];
                int i = 0;
                for (Field f : fs) {
                    fields[i++] = new JdiFieldImpl(f, object);
                }
            }
            Arrays.sort(fields);
        } catch (InvalidStackFrameException e) {
            throw new DebuggerException(e.getMessage(), e);
        }
    }
    return fields;
}
Also used : Field(com.sun.jdi.Field) ObjectReference(com.sun.jdi.ObjectReference) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException) ReferenceType(com.sun.jdi.ReferenceType)

Example 2 with Field

use of com.sun.jdi.Field in project che by eclipse.

the class Evaluator method getField.

public ExpressionValue getField(Value parent, String name) {
    if (!(parent instanceof ObjectReference)) {
        throw new ExpressionException("Value is not object. Cannot invoke method " + name);
    }
    ExpressionValue value = null;
    try {
        ObjectReference object = (ObjectReference) parent;
        Field field = object.referenceType().fieldByName(name);
        if (field != null) {
            value = new InstanceValue(object, field);
        }
    } catch (ClassNotPreparedException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
    LOG.debug("GET field {} {} ", name, value);
    return value;
}
Also used : Field(com.sun.jdi.Field) ObjectReference(com.sun.jdi.ObjectReference) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException)

Example 3 with Field

use of com.sun.jdi.Field in project jdk8u_jdk by JetBrains.

the class OomDebugTest method test2.

/*
     * Test case: Array reference as method parameter.
     */
// called via reflection
@SuppressWarnings("unused")
private void test2() throws Exception {
    System.out.println("DEBUG: ------------> Running test2");
    try {
        Field field = targetClass.fieldByName("byteArray");
        ArrayType arrType = (ArrayType) field.type();
        for (int i = 0; i < 15; i++) {
            ArrayReference byteArrayVal = arrType.newInstance(3000000);
            if (byteArrayVal.isCollected()) {
                System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
                continue;
            }
            invoke("testPrimitive", "([B)V", byteArrayVal);
        }
    } catch (VMOutOfMemoryException e) {
        defaultHandleOOMFailure(e);
    }
}
Also used : ArrayType(com.sun.jdi.ArrayType) Field(com.sun.jdi.Field) ArrayReference(com.sun.jdi.ArrayReference) VMOutOfMemoryException(com.sun.jdi.VMOutOfMemoryException)

Example 4 with Field

use of com.sun.jdi.Field in project jdk8u_jdk by JetBrains.

the class OomDebugTest method test1.

/*
     * Test case: Object reference as method parameter.
     */
// called via reflection
@SuppressWarnings("unused")
private void test1() throws Exception {
    System.out.println("DEBUG: ------------> Running test1");
    try {
        Field field = targetClass.fieldByName("fooCls");
        ClassType clsType = (ClassType) field.type();
        Method constructor = getConstructorForClass(clsType);
        for (int i = 0; i < 15; i++) {
            @SuppressWarnings({ "rawtypes", "unchecked" }) ObjectReference objRef = clsType.newInstance(mainThread, constructor, new ArrayList(0), ObjectReference.INVOKE_NONVIRTUAL);
            if (objRef.isCollected()) {
                System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
                continue;
            }
            invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
Also used : Field(com.sun.jdi.Field) ObjectReference(com.sun.jdi.ObjectReference) InvocationException(com.sun.jdi.InvocationException) ArrayList(java.util.ArrayList) Method(com.sun.jdi.Method) ClassType(com.sun.jdi.ClassType)

Example 5 with Field

use of com.sun.jdi.Field in project intellij-community by JetBrains.

the class ToggleFieldBreakpointAction method getPlace.

@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return null;
    }
    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
        final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
        if (psiElement instanceof PsiField) {
            return SourcePosition.createFromElement(psiElement);
        }
        return null;
    }
    final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
    if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
        final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
        final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
        if (debugProcess != null) {
            // if there is an active debug session
            final Ref<SourcePosition> positionRef = new Ref<>(null);
            debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {

                @Override
                public Priority getPriority() {
                    return Priority.HIGH;
                }

                @Override
                public void threadAction() {
                    ApplicationManager.getApplication().runReadAction(() -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)));
                }
            });
            final SourcePosition sourcePosition = positionRef.get();
            if (sourcePosition != null) {
                return sourcePosition;
            }
        }
    }
    if (DebuggerAction.isContextView(event)) {
        DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
        if (tree != null && tree.getSelectionPath() != null) {
            DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
            if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
                Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
                DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
                PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
                if (psiClass != null) {
                    psiClass = (PsiClass) psiClass.getNavigationElement();
                    final PsiField psiField = psiClass.findFieldByName(field.name(), true);
                    if (psiField != null) {
                        return SourcePosition.createFromElement(psiField);
                    }
                }
            }
        }
        return null;
    }
    Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor == null) {
        editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    }
    if (editor != null) {
        final Document document = editor.getDocument();
        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (file != null) {
            final VirtualFile virtualFile = file.getVirtualFile();
            FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
            if (StdFileTypes.JAVA == fileType || StdFileTypes.CLASS == fileType) {
                final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset());
                if (field != null) {
                    return SourcePosition.createFromElement(field);
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) Document(com.intellij.openapi.editor.Document) DebuggerTree(com.intellij.debugger.ui.impl.watch.DebuggerTree) FieldDescriptorImpl(com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl) Project(com.intellij.openapi.project.Project) Field(com.sun.jdi.Field) Ref(com.intellij.openapi.util.Ref) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) FileType(com.intellij.openapi.fileTypes.FileType) SourcePosition(com.intellij.debugger.SourcePosition) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) Editor(com.intellij.openapi.editor.Editor) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Field (com.sun.jdi.Field)6 ObjectReference (com.sun.jdi.ObjectReference)4 ArrayReference (com.sun.jdi.ArrayReference)2 ReferenceType (com.sun.jdi.ReferenceType)2 SourcePosition (com.intellij.debugger.SourcePosition)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 DebuggerTree (com.intellij.debugger.ui.impl.watch.DebuggerTree)1 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)1 FieldDescriptorImpl (com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 Ref (com.intellij.openapi.util.Ref)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayType (com.sun.jdi.ArrayType)1 ClassNotPreparedException (com.sun.jdi.ClassNotPreparedException)1