Search in sources :

Example 1 with VariablePathImpl

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

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

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

the class ZendDbgVariable method makeComplete.

@Override
public void makeComplete() {
    if (!isComplete) {
        // Evaluate wrapped expression to fetch all child variables
        zendDbgExpression.evaluate();
        variables = new ArrayList<>();
        int childId = 0;
        for (IDbgExpression child : zendDbgExpression.getChildren()) {
            List<String> childPath = new ArrayList<>(variablePath.getPath());
            childPath.add(String.valueOf(childId++));
            variables.add(new ZendDbgVariable(new VariablePathImpl(childPath), child));
        }
        isComplete = true;
    }
}
Also used : VariablePathImpl(org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl) IDbgExpression(org.eclipse.che.plugin.zdb.server.expressions.IDbgExpression) ArrayList(java.util.ArrayList)

Example 4 with VariablePathImpl

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

the class ZendDbgSessionTest method testGetValue.

@Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" })
public void testGetValue() throws Exception {
    List<Breakpoint> breakpoints = new ArrayList<>();
    Breakpoint bp1 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgClassesFile, 16));
    breakpoints.add(bp1);
    triggerSession(dbgHelloFile, getDbgSettings(false, false), breakpoints);
    awaitBreakpointActivated(bp1);
    awaitSuspend(dbgClassesFile, 16);
    debugger.dumpStackFrame();
    VariablePath variablePath = new VariablePathImpl("0");
    SimpleValue simpleValue = debugger.getValue(variablePath);
    assertEquals(simpleValue.getVariables().size(), 3);
    List<String> path = Arrays.asList("0", "0");
    variablePath = new VariablePathImpl(path);
    simpleValue = debugger.getValue(variablePath);
    assertEquals(simpleValue.getValue(), "\"A\"");
    path = Arrays.asList("0", "1");
    variablePath = new VariablePathImpl(path);
    simpleValue = debugger.getValue(variablePath);
    assertEquals(simpleValue.getValue(), "123");
    path = Arrays.asList("0", "2");
    variablePath = new VariablePathImpl(path);
    simpleValue = debugger.getValue(variablePath);
    assertEquals(simpleValue.getValue(), "array [3]");
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) VariablePath(org.eclipse.che.api.debug.shared.model.VariablePath) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) VariablePathImpl(org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl) ArrayList(java.util.ArrayList) SimpleValue(org.eclipse.che.api.debug.shared.model.SimpleValue) Test(org.testng.annotations.Test)

Example 5 with VariablePathImpl

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

VariablePathImpl (org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl)8 ArrayList (java.util.ArrayList)6 VariablePath (org.eclipse.che.api.debug.shared.model.VariablePath)4 VariableImpl (org.eclipse.che.api.debug.shared.model.impl.VariableImpl)4 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)3 StackFrameDump (org.eclipse.che.api.debug.shared.model.StackFrameDump)3 Variable (org.eclipse.che.api.debug.shared.model.Variable)3 Test (org.testng.annotations.Test)3 SimpleValue (org.eclipse.che.api.debug.shared.model.SimpleValue)2 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)2 IDbgExpression (org.eclipse.che.plugin.zdb.server.expressions.IDbgExpression)2 IOException (java.io.IOException)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 StackFrameDumpImpl (org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1 GdbParseException (org.eclipse.che.plugin.gdb.server.exception.GdbParseException)1 GdbTerminatedException (org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException)1