Search in sources :

Example 11 with Breakpoint

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

the class JavaDebugger method addBreakpoint.

@Override
public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException {
    final String className = findFQN(breakpoint);
    final int lineNumber = breakpoint.getLocation().getLineNumber();
    List<ReferenceType> classes = vm.classesByName(className);
    // it may mean that class doesn't loaded by a target JVM yet
    if (classes.isEmpty()) {
        deferBreakpoint(breakpoint);
        throw new DebuggerException("Class not loaded");
    }
    ReferenceType clazz = classes.get(0);
    List<com.sun.jdi.Location> locations;
    try {
        locations = clazz.locationsOfLine(lineNumber);
    } catch (AbsentInformationException | ClassNotPreparedException e) {
        throw new DebuggerException(e.getMessage(), e);
    }
    if (locations.isEmpty()) {
        throw new DebuggerException("Line " + lineNumber + " not found in class " + className);
    }
    com.sun.jdi.Location location = locations.get(0);
    if (location.method() == null) {
        // Line is out of method.
        throw new DebuggerException("Invalid line " + lineNumber + " in class " + className);
    }
    // Ignore new breakpoint if already have breakpoint at the same location.
    EventRequestManager requestManager = getEventManager();
    for (BreakpointRequest breakpointRequest : requestManager.breakpointRequests()) {
        if (location.equals(breakpointRequest.location())) {
            LOG.debug("Breakpoint at {} already set", location);
            return;
        }
    }
    try {
        EventRequest breakPointRequest = requestManager.createBreakpointRequest(location);
        breakPointRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
        String expression = breakpoint.getCondition();
        if (!(expression == null || expression.isEmpty())) {
            ExpressionParser parser = ExpressionParser.newInstance(expression);
            breakPointRequest.putProperty("org.eclipse.che.ide.java.debug.condition.expression.parser", parser);
        }
        breakPointRequest.setEnabled(true);
    } catch (NativeMethodException | IllegalThreadStateException | InvalidRequestStateException e) {
        throw new DebuggerException(e.getMessage(), e);
    }
    debuggerCallback.onEvent(new BreakpointActivatedEventImpl(new BreakpointImpl(breakpoint.getLocation(), true, breakpoint.getCondition())));
    LOG.debug("Add breakpoint: {}", location);
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) AbsentInformationException(com.sun.jdi.AbsentInformationException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) BreakpointRequest(com.sun.jdi.request.BreakpointRequest) EventRequest(com.sun.jdi.request.EventRequest) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException) EventRequestManager(com.sun.jdi.request.EventRequestManager) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) ReferenceType(com.sun.jdi.ReferenceType) BreakpointActivatedEventImpl(org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl) ExpressionParser(org.eclipse.che.plugin.jdb.server.expression.ExpressionParser) InvalidRequestStateException(com.sun.jdi.request.InvalidRequestStateException) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 12 with Breakpoint

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

the class JavaDebugger method findFQN.

private String findFQN(Breakpoint breakpoint) throws DebuggerException {
    Location location = breakpoint.getLocation();
    final String parentFqn = location.getTarget();
    final String projectPath = location.getResourceProjectPath();
    int lineNumber = location.getLineNumber();
    return debuggerUtil.findFqnByPosition(projectPath, parentFqn, lineNumber);
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 13 with Breakpoint

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

the class JavaDebugger method deleteBreakpoint.

@Override
public void deleteBreakpoint(Location location) throws DebuggerException {
    final String className = location.getTarget();
    final int lineNumber = location.getLineNumber();
    EventRequestManager requestManager = getEventManager();
    List<BreakpointRequest> snapshot = new ArrayList<>(requestManager.breakpointRequests());
    for (BreakpointRequest breakpointRequest : snapshot) {
        com.sun.jdi.Location jdiLocation = breakpointRequest.location();
        if (jdiLocation.declaringType().name().equals(className) && jdiLocation.lineNumber() == lineNumber) {
            requestManager.deleteEventRequest(breakpointRequest);
            LOG.debug("Delete breakpoint: {}", location);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) BreakpointRequest(com.sun.jdi.request.BreakpointRequest) EventRequestManager(com.sun.jdi.request.EventRequestManager) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint)

Example 14 with Breakpoint

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

the class BreakPointComparator method compare.

@Override
public int compare(Breakpoint o1, Breakpoint o2) {
    String className1 = o1.getLocation().getTarget();
    String className2 = o2.getLocation().getTarget();
    if (className1 == null && className2 == null) {
        return 0;
    }
    if (className1 == null) {
        return 1;
    }
    if (className2 == null) {
        return -1;
    }
    int result = className1.compareTo(className2);
    if (result == 0) {
        result = o1.getLocation().getLineNumber() - o2.getLocation().getLineNumber();
    }
    return result;
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint)

Example 15 with Breakpoint

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

the class JavaDebuggerTest method testAddBreakpoint.

@Test(priority = 3)
public void testAddBreakpoint() throws Exception {
    int breakpointsCount = debugger.getAllBreakpoints().size();
    debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 18), false, null));
    DebuggerEvent debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof BreakpointActivatedEvent);
    Breakpoint breakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint();
    assertEquals(breakpoint.getLocation().getLineNumber(), 18);
    assertEquals(breakpoint.getLocation().getTarget(), "com.HelloWorld");
    assertTrue(breakpoint.isEnabled());
    assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount + 1);
}
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) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) 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