Search in sources :

Example 1 with VariableImpl

use of org.eclipse.che.api.debug.shared.model.impl.VariableImpl in project che by eclipse.

the class GdbDebugger method dumpStackFrame.

/**
     * Dump frame.
     */
@Override
public StackFrameDump dumpStackFrame() throws DebuggerException {
    try {
        Map<String, String> locals = gdb.infoLocals().getVariables();
        locals.putAll(gdb.infoArgs().getVariables());
        List<Variable> variables = new ArrayList<>(locals.size());
        for (Map.Entry<String, String> e : locals.entrySet()) {
            String varName = e.getKey();
            String varValue = e.getValue();
            String varType;
            try {
                varType = gdb.ptype(varName).getType();
            } catch (GdbParseException pe) {
                LOG.warn(pe.getMessage(), pe);
                varType = "";
            }
            VariablePath variablePath = new VariablePathImpl(singletonList(varName));
            VariableImpl variable = new VariableImpl(varType, varName, varValue, true, variablePath, Collections.emptyList(), true);
            variables.add(variable);
        }
        return new StackFrameDumpImpl(Collections.emptyList(), variables);
    } catch (GdbTerminatedException e) {
        disconnect();
        throw e;
    } catch (IOException | GdbParseException | InterruptedException e) {
        throw new DebuggerException("Can't dump stack frame. " + e.getMessage(), e);
    }
}
Also used : Variable(org.eclipse.che.api.debug.shared.model.Variable) VariablePathImpl(org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StackFrameDumpImpl(org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl) VariablePath(org.eclipse.che.api.debug.shared.model.VariablePath) VariableImpl(org.eclipse.che.api.debug.shared.model.impl.VariableImpl) GdbTerminatedException(org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException) GdbParseException(org.eclipse.che.plugin.gdb.server.exception.GdbParseException) Map(java.util.Map)

Example 2 with VariableImpl

use of org.eclipse.che.api.debug.shared.model.impl.VariableImpl in project che by eclipse.

the class JavaDebuggerTest method testSetAndGetValue.

@Test(priority = 11)
public void testSetAndGetValue() throws Exception {
    assertEquals(debugger.getValue(new VariablePathImpl("test")).getValue(), "\"hello\"");
    assertEquals(debugger.getValue(new VariablePathImpl("msg")).getValue(), "\"Hello, debugger!\"");
    debugger.setValue(new VariableImpl("\"new hello\"", (new VariablePathImpl("test"))));
    assertEquals(debugger.getValue(new VariablePathImpl("test")).getValue(), "\"new hello\"");
    StackFrameDump stackFrameDump = debugger.dumpStackFrame();
    Set<String> vars = stackFrameDump.getVariables().stream().map(Variable::getName).collect(Collectors.toSet());
    assertTrue(vars.contains("args"));
    assertTrue(vars.contains("msg"));
    assertTrue(vars.contains("test"));
}
Also used : VariableImpl(org.eclipse.che.api.debug.shared.model.impl.VariableImpl) VariablePathImpl(org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl) StackFrameDump(org.eclipse.che.api.debug.shared.model.StackFrameDump) Test(org.testng.annotations.Test)

Example 3 with VariableImpl

use of org.eclipse.che.api.debug.shared.model.impl.VariableImpl in project che by eclipse.

the class ChangeValuePresenter method onChangeClicked.

/** {@inheritDoc} */
@Override
public void onChangeClicked() {
    Debugger debugger = debuggerManager.getActiveDebugger();
    if (debugger != null) {
        Variable newVariable = new VariableImpl(view.getValue(), variable.getVariablePath());
        debugger.setValue(newVariable);
    }
    view.close();
}
Also used : Debugger(org.eclipse.che.ide.debug.Debugger) VariableImpl(org.eclipse.che.api.debug.shared.model.impl.VariableImpl) Variable(org.eclipse.che.api.debug.shared.model.Variable)

Example 4 with VariableImpl

use of org.eclipse.che.api.debug.shared.model.impl.VariableImpl 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 5 with VariableImpl

use of org.eclipse.che.api.debug.shared.model.impl.VariableImpl in project che by eclipse.

the class GdbDebuggerTest method doSetAndGetValues.

private void doSetAndGetValues() throws DebuggerException {
    VariablePath variablePath = new VariablePathImpl("i");
    Variable variable = new VariableImpl("int", "i", "2", true, variablePath, Collections.emptyList(), false);
    SimpleValue value = gdbDebugger.getValue(variablePath);
    assertEquals(value.getValue(), "0");
    gdbDebugger.setValue(variable);
    value = gdbDebugger.getValue(variablePath);
    assertEquals(value.getValue(), "2");
    String expression = gdbDebugger.evaluate("i");
    assertEquals(expression, "2");
    expression = gdbDebugger.evaluate("10 + 10");
    assertEquals(expression, "20");
    StackFrameDump stackFrameDump = gdbDebugger.dumpStackFrame();
    assertTrue(stackFrameDump.getFields().isEmpty());
    assertEquals(stackFrameDump.getVariables().size(), 1);
    assertEquals(stackFrameDump.getVariables().get(0).getName(), "i");
    assertEquals(stackFrameDump.getVariables().get(0).getValue(), "2");
    assertEquals(stackFrameDump.getVariables().get(0).getType(), "int");
}
Also used : VariablePath(org.eclipse.che.api.debug.shared.model.VariablePath) VariableImpl(org.eclipse.che.api.debug.shared.model.impl.VariableImpl) Variable(org.eclipse.che.api.debug.shared.model.Variable) VariablePathImpl(org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl) StackFrameDump(org.eclipse.che.api.debug.shared.model.StackFrameDump) SimpleValue(org.eclipse.che.api.debug.shared.model.SimpleValue)

Aggregations

VariableImpl (org.eclipse.che.api.debug.shared.model.impl.VariableImpl)6 Variable (org.eclipse.che.api.debug.shared.model.Variable)5 VariablePathImpl (org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl)4 ArrayList (java.util.ArrayList)3 StackFrameDump (org.eclipse.che.api.debug.shared.model.StackFrameDump)3 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)2 VariablePath (org.eclipse.che.api.debug.shared.model.VariablePath)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 Map (java.util.Map)1 VariablePathDto (org.eclipse.che.api.debug.shared.dto.VariablePathDto)1 SimpleValue (org.eclipse.che.api.debug.shared.model.SimpleValue)1 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)1 FieldImpl (org.eclipse.che.api.debug.shared.model.impl.FieldImpl)1 SimpleValueImpl (org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl)1 StackFrameDumpImpl (org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1 Debugger (org.eclipse.che.ide.debug.Debugger)1 GdbParseException (org.eclipse.che.plugin.gdb.server.exception.GdbParseException)1 GdbTerminatedException (org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException)1