Search in sources :

Example 1 with ClassNotPreparedException

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

the class JavaDebugger method addBreakpoint.

@Override
public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException {
    final String className = findFQN(breakpoint);
    final int lineNumber = breakpoint.getLocation().getLineNumber();
    List<ReferenceType> classes = vm.classesByName(className);
    // it may mean that class doesn't loaded by a target JVM yet
    if (classes.isEmpty()) {
        deferBreakpoint(breakpoint);
        throw new DebuggerException("Class not loaded");
    }
    ReferenceType clazz = classes.get(0);
    List<com.sun.jdi.Location> locations;
    try {
        locations = clazz.locationsOfLine(lineNumber);
    } catch (AbsentInformationException | ClassNotPreparedException e) {
        throw new DebuggerException(e.getMessage(), e);
    }
    if (locations.isEmpty()) {
        throw new DebuggerException("Line " + lineNumber + " not found in class " + className);
    }
    com.sun.jdi.Location location = locations.get(0);
    if (location.method() == null) {
        // Line is out of method.
        throw new DebuggerException("Invalid line " + lineNumber + " in class " + className);
    }
    // Ignore new breakpoint if already have breakpoint at the same location.
    EventRequestManager requestManager = getEventManager();
    for (BreakpointRequest breakpointRequest : requestManager.breakpointRequests()) {
        if (location.equals(breakpointRequest.location())) {
            LOG.debug("Breakpoint at {} already set", location);
            return;
        }
    }
    try {
        EventRequest breakPointRequest = requestManager.createBreakpointRequest(location);
        breakPointRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
        String expression = breakpoint.getCondition();
        if (!(expression == null || expression.isEmpty())) {
            ExpressionParser parser = ExpressionParser.newInstance(expression);
            breakPointRequest.putProperty("org.eclipse.che.ide.java.debug.condition.expression.parser", parser);
        }
        breakPointRequest.setEnabled(true);
    } catch (NativeMethodException | IllegalThreadStateException | InvalidRequestStateException e) {
        throw new DebuggerException(e.getMessage(), e);
    }
    debuggerCallback.onEvent(new BreakpointActivatedEventImpl(new BreakpointImpl(breakpoint.getLocation(), true, breakpoint.getCondition())));
    LOG.debug("Add breakpoint: {}", location);
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) AbsentInformationException(com.sun.jdi.AbsentInformationException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) BreakpointRequest(com.sun.jdi.request.BreakpointRequest) EventRequest(com.sun.jdi.request.EventRequest) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException) EventRequestManager(com.sun.jdi.request.EventRequestManager) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) ReferenceType(com.sun.jdi.ReferenceType) BreakpointActivatedEventImpl(org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl) ExpressionParser(org.eclipse.che.plugin.jdb.server.expression.ExpressionParser) InvalidRequestStateException(com.sun.jdi.request.InvalidRequestStateException) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 2 with ClassNotPreparedException

use of com.sun.jdi.ClassNotPreparedException 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 ClassNotPreparedException

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

the class DefaultSourcePositionProvider method getSourcePositionForField.

@Nullable
private static SourcePosition getSourcePositionForField(@NotNull FieldDescriptor descriptor, @NotNull Project project, @NotNull DebuggerContextImpl context, boolean nearest) {
    final ReferenceType type = descriptor.getField().declaringType();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final String fieldName = descriptor.getField().name();
    if (fieldName.startsWith(FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
        // this field actually mirrors a local variable in the outer class
        String varName = fieldName.substring(fieldName.lastIndexOf('$') + 1);
        PsiElement element = PositionUtil.getContextElement(context);
        if (element == null) {
            return null;
        }
        PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
        if (aClass == null) {
            return null;
        }
        PsiElement navigationElement = aClass.getNavigationElement();
        if (!(navigationElement instanceof PsiClass)) {
            return null;
        }
        aClass = (PsiClass) navigationElement;
        PsiVariable psiVariable = facade.getResolveHelper().resolveReferencedVariable(varName, aClass);
        if (psiVariable == null) {
            return null;
        }
        if (nearest) {
            return DebuggerContextUtil.findNearest(context, psiVariable, aClass.getContainingFile());
        }
        return SourcePosition.createFromElement(psiVariable);
    } else {
        final DebuggerSession session = context.getDebuggerSession();
        final GlobalSearchScope scope = session != null ? session.getSearchScope() : GlobalSearchScope.allScope(project);
        PsiClass aClass = facade.findClass(type.name().replace('$', '.'), scope);
        if (aClass == null) {
            // trying to search, assuming declaring class is an anonymous class
            final DebugProcessImpl debugProcess = context.getDebugProcess();
            if (debugProcess != null) {
                try {
                    final List<Location> locations = type.allLineLocations();
                    if (!locations.isEmpty()) {
                        // important: use the last location to be sure the position will be within the anonymous class
                        final Location lastLocation = locations.get(locations.size() - 1);
                        final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation);
                        aClass = JVMNameUtil.getClassAt(position);
                    }
                } catch (AbsentInformationException | ClassNotPreparedException ignored) {
                }
            }
        }
        if (aClass != null) {
            PsiField field = aClass.findFieldByName(fieldName, false);
            if (field == null)
                return null;
            if (nearest) {
                return DebuggerContextUtil.findNearest(context, field.getNavigationElement(), aClass.getContainingFile());
            }
            return SourcePosition.createFromElement(field);
        }
        return null;
    }
}
Also used : AbsentInformationException(com.sun.jdi.AbsentInformationException) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException) ReferenceType(com.sun.jdi.ReferenceType) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SourcePosition(com.intellij.debugger.SourcePosition) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ClassNotPreparedException (com.sun.jdi.ClassNotPreparedException)3 AbsentInformationException (com.sun.jdi.AbsentInformationException)2 ReferenceType (com.sun.jdi.ReferenceType)2 SourcePosition (com.intellij.debugger.SourcePosition)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 Field (com.sun.jdi.Field)1 Location (com.sun.jdi.Location)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 ObjectReference (com.sun.jdi.ObjectReference)1 BreakpointRequest (com.sun.jdi.request.BreakpointRequest)1 EventRequest (com.sun.jdi.request.EventRequest)1 EventRequestManager (com.sun.jdi.request.EventRequestManager)1 InvalidRequestStateException (com.sun.jdi.request.InvalidRequestStateException)1 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)1 Location (org.eclipse.che.api.debug.shared.model.Location)1 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)1 BreakpointActivatedEventImpl (org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1 DebuggerAbsentInformationException (org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)1