Search in sources :

Example 1 with Variable

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

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

the class DebuggerTest method testGetValue.

@Test
public void testGetValue() throws Exception {
    final VariableDto variableDto = mock(VariableDto.class);
    final Variable variable = mock(Variable.class);
    final Promise<SimpleValueDto> promiseValue = mock(Promise.class);
    doReturn(variableDto).when(dtoFactory).createDto(VariableDto.class);
    doReturn(mock(VariablePathDto.class)).when(dtoFactory).createDto(VariablePathDto.class);
    doReturn(mock(VariablePathDto.class)).when(variable).getVariablePath();
    doReturn(Collections.emptyList()).when(variable).getVariables();
    doReturn(promiseValue).when(service).getValue(SESSION_ID, variableDto);
    doReturn(promiseValue).when(promiseValue).then((Function<SimpleValueDto, Object>) any());
    doReturn(promiseValue).when(promiseValue).catchError((Operation<PromiseError>) any());
    Promise<SimpleValue> result = debugger.getValue(variable);
    assertEquals(promiseValue, result);
}
Also used : Variable(org.eclipse.che.api.debug.shared.model.Variable) VariablePathDto(org.eclipse.che.api.debug.shared.dto.VariablePathDto) PromiseError(org.eclipse.che.api.promises.client.PromiseError) VariableDto(org.eclipse.che.api.debug.shared.dto.VariableDto) SimpleValueDto(org.eclipse.che.api.debug.shared.dto.SimpleValueDto) SimpleValue(org.eclipse.che.api.debug.shared.model.SimpleValue) BaseTest(org.eclipse.che.plugin.debugger.ide.BaseTest) Test(org.junit.Test)

Example 3 with Variable

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

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

the class DebuggerTest method testChangeVariableValue.

@Test
public void testChangeVariableValue() throws Exception {
    final List<String> path = mock(List.class);
    final String newValue = "new-value";
    VariablePath variablePath = mock(VariablePathDto.class);
    doReturn(path).when(variablePath).getPath();
    VariableDto variableDto = mock(VariableDto.class);
    doReturn(variableDto).when(dtoFactory).createDto(VariableDto.class);
    Variable variable = mock(Variable.class);
    doReturn(mock(VariablePathDto.class)).when(dtoFactory).createDto(VariablePathDto.class);
    doReturn(variablePath).when(variable).getVariablePath();
    doReturn(newValue).when(variable).getValue();
    doReturn(Collections.emptyList()).when(variable).getVariables();
    doReturn(promiseVoid).when(service).setValue(SESSION_ID, variableDto);
    doReturn(promiseVoid).when(promiseVoid).then((Operation<Void>) any());
    debugger.setValue(variable);
    verify(promiseVoid).then(operationVoidCaptor.capture());
    operationVoidCaptor.getValue().apply(null);
    verify(observer).onValueChanged(path, newValue);
    verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture());
    operationPromiseErrorCaptor.getValue().apply(promiseError);
    verify(promiseError).getMessage();
}
Also used : VariablePath(org.eclipse.che.api.debug.shared.model.VariablePath) Variable(org.eclipse.che.api.debug.shared.model.Variable) VariablePathDto(org.eclipse.che.api.debug.shared.dto.VariablePathDto) VariableDto(org.eclipse.che.api.debug.shared.dto.VariableDto) Matchers.anyString(org.mockito.Matchers.anyString) BaseTest(org.eclipse.che.plugin.debugger.ide.BaseTest) Test(org.junit.Test)

Example 5 with Variable

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

Variable (org.eclipse.che.api.debug.shared.model.Variable)8 VariableImpl (org.eclipse.che.api.debug.shared.model.impl.VariableImpl)5 ArrayList (java.util.ArrayList)3 VariablePathDto (org.eclipse.che.api.debug.shared.dto.VariablePathDto)3 VariablePath (org.eclipse.che.api.debug.shared.model.VariablePath)3 VariablePathImpl (org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl)3 VariableDto (org.eclipse.che.api.debug.shared.dto.VariableDto)2 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)2 SimpleValue (org.eclipse.che.api.debug.shared.model.SimpleValue)2 StackFrameDump (org.eclipse.che.api.debug.shared.model.StackFrameDump)2 BaseTest (org.eclipse.che.plugin.debugger.ide.BaseTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Map (java.util.Map)1 SimpleValueDto (org.eclipse.che.api.debug.shared.dto.SimpleValueDto)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