Search in sources :

Example 1 with ReferenceType

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

use of com.sun.jdi.ReferenceType 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 3 with ReferenceType

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

the class Evaluator method invokeMethod.

public ExpressionValue invokeMethod(Value value, String name, List<Value> arguments) {
    if (!(value instanceof ObjectReference)) {
        throw new ExpressionException("Value is not object. Cannot invoke method " + name);
    }
    ObjectReference object = (ObjectReference) value;
    ReferenceType type = object.referenceType();
    List<Method> methods = type.methodsByName(name);
    Method method = findMethod(methods, arguments);
    if (method == null) {
        throw new ExpressionException("No method with name " + name + " matched to specified arguments for " + type.name());
    }
    try {
        return new ReadOnlyValue(object.invokeMethod(thread, method, arguments, 0));
    } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | InvocationException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
}
Also used : ClassNotLoadedException(com.sun.jdi.ClassNotLoadedException) ObjectReference(com.sun.jdi.ObjectReference) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) InvocationException(com.sun.jdi.InvocationException) Method(com.sun.jdi.Method) ReferenceType(com.sun.jdi.ReferenceType) InvalidTypeException(com.sun.jdi.InvalidTypeException)

Example 4 with ReferenceType

use of com.sun.jdi.ReferenceType in project kotlin by JetBrains.

the class DebuggerSteppingHelper method getCurrentClassName.

// copied from DebugProcessImpl.getActiveFilters
@Nullable
private static String getCurrentClassName(ThreadReferenceProxyImpl thread) {
    try {
        if (thread != null && thread.frameCount() > 0) {
            StackFrameProxyImpl stackFrame = thread.frame(0);
            if (stackFrame != null) {
                Location location = stackFrame.location();
                ReferenceType referenceType = location == null ? null : location.declaringType();
                if (referenceType != null) {
                    return referenceType.name();
                }
            }
        }
    } catch (EvaluateException ignored) {
    }
    return null;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ReferenceType(com.sun.jdi.ReferenceType) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ReferenceType

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

the class SpringLoadedPositionManager method getAllClasses.

@NotNull
@Override
public List<ReferenceType> getAllClasses(@NotNull final SourcePosition classPosition) throws NoDataException {
    int line;
    String className;
    AccessToken accessToken = ReadAction.start();
    try {
        className = findEnclosingName(classPosition);
        if (className == null)
            throw NoDataException.INSTANCE;
        line = classPosition.getLine();
    } finally {
        accessToken.finish();
    }
    List<ReferenceType> referenceTypes = myDebugProcess.getVirtualMachineProxy().classesByName(className);
    if (referenceTypes.isEmpty())
        throw NoDataException.INSTANCE;
    Set<ReferenceType> res = new HashSet<>();
    for (ReferenceType referenceType : referenceTypes) {
        findNested(res, referenceType, line);
    }
    if (res.isEmpty()) {
        throw NoDataException.INSTANCE;
    }
    return new ArrayList<>(res);
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) ReferenceType(com.sun.jdi.ReferenceType) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ReferenceType (com.sun.jdi.ReferenceType)42 Nullable (org.jetbrains.annotations.Nullable)9 Project (com.intellij.openapi.project.Project)8 Location (com.sun.jdi.Location)5 Method (com.sun.jdi.Method)5 ObjectReference (com.sun.jdi.ObjectReference)5 AbsentInformationException (com.sun.jdi.AbsentInformationException)4 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)3 ClassesTable (com.intellij.debugger.memory.ui.ClassesTable)3 InstancesWindow (com.intellij.debugger.memory.ui.InstancesWindow)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 XDebugSession (com.intellij.xdebugger.XDebugSession)3 BreakpointRequest (com.sun.jdi.request.BreakpointRequest)3 SourcePosition (com.intellij.debugger.SourcePosition)2 DebugProcess (com.intellij.debugger.engine.DebugProcess)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 InstancesTracker (com.intellij.debugger.memory.component.InstancesTracker)2 InstancesProvider (com.intellij.debugger.memory.utils.InstancesProvider)2 ClassPrepareRequestor (com.intellij.debugger.requests.ClassPrepareRequestor)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2