Search in sources :

Example 1 with DebuggerAbsentInformationException

use of org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException in project che by eclipse.

the class JavaDebugger method dumpStackFrame.

@Override
public StackFrameDumpDto dumpStackFrame() throws DebuggerException {
    lock.lock();
    try {
        final JdiStackFrame currentFrame = getCurrentFrame();
        StackFrameDumpDto dump = newDto(StackFrameDumpDto.class);
        boolean existInformation = true;
        JdiLocalVariable[] variables = new JdiLocalVariable[0];
        try {
            variables = currentFrame.getLocalVariables();
        } catch (DebuggerAbsentInformationException e) {
            existInformation = false;
        }
        for (JdiField f : currentFrame.getFields()) {
            List<String> variablePath = asList(f.isStatic() ? "static" : "this", f.getName());
            dump.getFields().add(newDto(FieldDto.class).withIsFinal(f.isFinal()).withIsStatic(f.isStatic()).withIsTransient(f.isTransient()).withIsVolatile(f.isVolatile()).withName(f.getName()).withExistInformation(existInformation).withValue(f.getValue().getAsString()).withType(f.getTypeName()).withVariablePath(newDto(VariablePathDto.class).withPath(variablePath)).withPrimitive(f.isPrimitive()));
        }
        for (JdiLocalVariable var : variables) {
            dump.getVariables().add(newDto(VariableDto.class).withName(var.getName()).withExistInformation(existInformation).withValue(var.getValue().getAsString()).withType(var.getTypeName()).withVariablePath(newDto(VariablePathDto.class).withPath(singletonList(var.getName()))).withPrimitive(var.isPrimitive()));
        }
        return dump;
    } finally {
        lock.unlock();
    }
}
Also used : StackFrameDumpDto(org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto) VariableDto(org.eclipse.che.api.debug.shared.dto.VariableDto) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) FieldDto(org.eclipse.che.api.debug.shared.dto.FieldDto)

Example 2 with DebuggerAbsentInformationException

use of org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException in project che by eclipse.

the class JavaDebugger method getValue.

/**
     * Get value of variable with specified path. Each item in path is name of variable.
     * <p>
     * Path must be specified according to the following rules:
     * <ol>
     * <li>If need to get field of this object of current frame then first element in array always should be
     * 'this'.</li>
     * <li>If need to get static field in current frame then first element in array always should be 'static'.</li>
     * <li>If need to get local variable in current frame then first element should be the name of local variable.</li>
     * </ol>
     * </p>
     * Here is example. <br/>
     * Assume we have next hierarchy of classes and breakpoint set in line: <i>// breakpoint</i>:
     * <pre>
     *    class A {
     *       private String str;
     *       ...
     *    }
     *
     *    class B {
     *       private A a;
     *       ....
     *
     *       void method() {
     *          A var = new A();
     *          var.setStr(...);
     *          a = var;
     *          // breakpoint
     *       }
     *    }
     * </pre>
     * There are two ways to access variable <i>str</i> in class <i>A</i>:
     * <ol>
     * <li>Through field <i>a</i> in class <i>B</i>: ['this', 'a', 'str']</li>
     * <li>Through local variable <i>var</i> in method <i>B.method()</i>: ['var', 'str']</li>
     * </ol>
     *
     * @param variablePath
     *         path to variable
     * @return variable or <code>null</code> if variable not found
     * @throws DebuggerException
     *         when any other errors occur when try to access the variable
     */
@Override
public SimpleValue getValue(VariablePath variablePath) throws DebuggerException {
    List<String> path = variablePath.getPath();
    if (path.size() == 0) {
        throw new IllegalArgumentException("Path to value may not be empty. ");
    }
    JdiVariable variable;
    int offset;
    if ("this".equals(path.get(0)) || "static".equals(path.get(0))) {
        if (path.size() < 2) {
            throw new IllegalArgumentException("Name of field required. ");
        }
        variable = getCurrentFrame().getFieldByName(path.get(1));
        offset = 2;
    } else {
        try {
            variable = getCurrentFrame().getLocalVariableByName(path.get(0));
        } catch (DebuggerAbsentInformationException e) {
            return null;
        }
        offset = 1;
    }
    for (int i = offset; variable != null && i < path.size(); i++) {
        variable = variable.getValue().getVariableByName(path.get(i));
    }
    if (variable == null) {
        return null;
    }
    List<Variable> variables = new ArrayList<>();
    for (JdiVariable ch : variable.getValue().getVariables()) {
        VariablePathDto chPath = newDto(VariablePathDto.class).withPath(new ArrayList<>(path));
        chPath.getPath().add(ch.getName());
        if (ch instanceof JdiField) {
            JdiField f = (JdiField) ch;
            variables.add(new FieldImpl(f.getName(), true, f.getValue().getAsString(), f.getTypeName(), f.isPrimitive(), Collections.<Variable>emptyList(), chPath, f.isFinal(), f.isStatic(), f.isTransient(), f.isVolatile()));
        } else {
            // Array element.
            variables.add(new VariableImpl(ch.getTypeName(), ch.getName(), ch.getValue().getAsString(), ch.isPrimitive(), chPath, Collections.emptyList(), true));
        }
    }
    return new SimpleValueImpl(variables, variable.getValue().getAsString());
}
Also used : Variable(org.eclipse.che.api.debug.shared.model.Variable) VariablePathDto(org.eclipse.che.api.debug.shared.dto.VariablePathDto) SimpleValueImpl(org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl) ArrayList(java.util.ArrayList) FieldImpl(org.eclipse.che.api.debug.shared.model.impl.FieldImpl) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) VariableImpl(org.eclipse.che.api.debug.shared.model.impl.VariableImpl)

Example 3 with DebuggerAbsentInformationException

use of org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException in project che by eclipse.

the class JdiStackFrameImpl method getLocalVariables.

@Override
public JdiLocalVariable[] getLocalVariables() throws DebuggerException {
    if (localVariables == null) {
        try {
            List<LocalVariable> targetVariables = stackFrame.visibleVariables();
            localVariables = new JdiLocalVariable[targetVariables.size()];
            int i = 0;
            for (LocalVariable var : targetVariables) {
                localVariables[i++] = new JdiLocalVariableImpl(stackFrame, var);
            }
        } catch (AbsentInformationException e) {
            throw new DebuggerAbsentInformationException(e.getMessage(), e);
        } catch (InvalidStackFrameException | NativeMethodException e) {
            throw new DebuggerException(e.getMessage(), e);
        }
    }
    return localVariables;
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) AbsentInformationException(com.sun.jdi.AbsentInformationException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) LocalVariable(com.sun.jdi.LocalVariable) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)

Aggregations

DebuggerAbsentInformationException (org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)3 AbsentInformationException (com.sun.jdi.AbsentInformationException)1 InvalidStackFrameException (com.sun.jdi.InvalidStackFrameException)1 LocalVariable (com.sun.jdi.LocalVariable)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 ArrayList (java.util.ArrayList)1 FieldDto (org.eclipse.che.api.debug.shared.dto.FieldDto)1 StackFrameDumpDto (org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto)1 VariableDto (org.eclipse.che.api.debug.shared.dto.VariableDto)1 VariablePathDto (org.eclipse.che.api.debug.shared.dto.VariablePathDto)1 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)1 Variable (org.eclipse.che.api.debug.shared.model.Variable)1 FieldImpl (org.eclipse.che.api.debug.shared.model.impl.FieldImpl)1 SimpleValueImpl (org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl)1 VariableImpl (org.eclipse.che.api.debug.shared.model.impl.VariableImpl)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1