Search in sources :

Example 21 with Breakpoint

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

the class ZendDbgSessionTest method testBreaking.

@Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" })
public void testBreaking() throws Exception {
    List<Breakpoint> breakpoints = new ArrayList<>();
    Breakpoint bp1 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgHelloFile, 4));
    Breakpoint bp2 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgClassesFile, 10));
    breakpoints.add(bp1);
    breakpoints.add(bp2);
    triggerSession(dbgHelloFile, getDbgSettings(false, false), breakpoints);
    awaitBreakpointActivated(bp1);
    awaitBreakpointActivated(bp2);
    awaitSuspend(dbgHelloFile, 4);
    debugger.resume(new ResumeActionImpl());
    awaitSuspend(dbgClassesFile, 10);
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) ArrayList(java.util.ArrayList) ResumeActionImpl(org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl) Test(org.testng.annotations.Test)

Example 22 with Breakpoint

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

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

the class JavaDebugger method processClassPrepareEvent.

private boolean processClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent event) throws DebuggerException {
    setCurrentThread(event.thread());
    final String className = event.referenceType().name();
    // add deferred breakpoints
    List<Breakpoint> breakpointsToAdd = deferredBreakpoints.get(className);
    if (breakpointsToAdd != null) {
        for (Breakpoint b : breakpointsToAdd) {
            addBreakpoint(b);
        }
        deferredBreakpoints.remove(className);
        // All deferred breakpoints for className have been already added,
        // so no need to listen for an appropriate ClassPrepareRequests any more.
        ClassPrepareRequest request = classPrepareRequests.remove(className);
        if (request != null) {
            getEventManager().deleteEventRequest(request);
        }
    }
    return true;
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) ClassPrepareRequest(com.sun.jdi.request.ClassPrepareRequest)

Example 24 with Breakpoint

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

the class JavaDebugger method getAllBreakpoints.

@Override
public List<Breakpoint> getAllBreakpoints() throws DebuggerException {
    List<BreakpointRequest> breakpointRequests;
    try {
        breakpointRequests = getEventManager().breakpointRequests();
    } catch (DebuggerException e) {
        Throwable cause = e.getCause();
        if (cause instanceof VMCannotBeModifiedException) {
            // If target VM in read-only state then list of break point always empty.
            return Collections.emptyList();
        }
        throw e;
    }
    List<Breakpoint> breakPoints = new ArrayList<>(breakpointRequests.size());
    for (BreakpointRequest breakpointRequest : breakpointRequests) {
        com.sun.jdi.Location location = breakpointRequest.location();
        // Breakpoint always enabled at the moment. Managing states of breakpoint is not supported for now.
        breakPoints.add(newDto(BreakpointDto.class).withEnabled(true).withLocation(newDto(LocationDto.class).withTarget(location.declaringType().name()).withLineNumber(location.lineNumber())));
    }
    Collections.sort(breakPoints, BREAKPOINT_COMPARATOR);
    return breakPoints;
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) BreakpointRequest(com.sun.jdi.request.BreakpointRequest) ArrayList(java.util.ArrayList) VMCannotBeModifiedException(com.sun.jdi.VMCannotBeModifiedException) BreakpointDto(org.eclipse.che.api.debug.shared.dto.BreakpointDto)

Example 25 with Breakpoint

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

the class JavaDebuggerTest method testGetAllBreakpoints.

@Test(priority = 8)
public void testGetAllBreakpoints() throws Exception {
    assertFalse(debugger.getAllBreakpoints().isEmpty());
    debugger.deleteAllBreakpoints();
    assertTrue(debugger.getAllBreakpoints().isEmpty());
    debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 18), false, null));
    DebuggerEvent debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof BreakpointActivatedEvent);
    assertEquals(debugger.getAllBreakpoints().size(), 1);
    Breakpoint breakpoint = debugger.getAllBreakpoints().get(0);
    assertEquals(breakpoint.getLocation().getLineNumber(), 18);
    assertEquals(breakpoint.getLocation().getTarget(), "com.HelloWorld");
    assertTrue(breakpoint.isEnabled());
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) BreakpointActivatedEvent(org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent) DebuggerEvent(org.eclipse.che.api.debug.shared.model.event.DebuggerEvent) Test(org.testng.annotations.Test)

Aggregations

Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)32 Test (org.testng.annotations.Test)14 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)13 ArrayList (java.util.ArrayList)11 Location (org.eclipse.che.api.debug.shared.model.Location)7 LocationImpl (org.eclipse.che.api.debug.shared.model.impl.LocationImpl)7 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)5 BreakpointActivatedEvent (org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent)4 BreakpointRequest (com.sun.jdi.request.BreakpointRequest)3 DebuggerEvent (org.eclipse.che.api.debug.shared.model.event.DebuggerEvent)3 GdbContinue (org.eclipse.che.plugin.gdb.server.parser.GdbContinue)3 ClassPrepareRequest (com.sun.jdi.request.ClassPrepareRequest)2 EventRequestManager (com.sun.jdi.request.EventRequestManager)2 IOException (java.io.IOException)2 StackFrameDump (org.eclipse.che.api.debug.shared.model.StackFrameDump)2 Variable (org.eclipse.che.api.debug.shared.model.Variable)2 VariableImpl (org.eclipse.che.api.debug.shared.model.impl.VariableImpl)2 VariablePathImpl (org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl)2 ResumeActionImpl (org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl)2 BreakpointActivatedEventImpl (org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl)2