Search in sources :

Example 6 with Location

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

the class ZendDebugger method handleReady.

private void handleReady(ReadyNotification notification) {
    String remoteFilePath = notification.getFileName();
    if (breakpointAflId != null && remoteFilePath.equals(debugStartFile)) {
        debugConnection.sendRequest(new DeleteBreakpointRequest(breakpointAflId));
        breakpointAflId = null;
    }
    int lineNumber = notification.getLineNumber();
    Location dbgLocation = ZendDbgLocationHandler.createDBG(remoteFilePath, lineNumber);
    // Convert DBG location from engine to VFS location
    Location vfsLocation = debugLocationHandler.convertToVFS(dbgLocation);
    // Send suspend event
    debugCallback.onEvent(new SuspendEventImpl(vfsLocation));
}
Also used : SuspendEventImpl(org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl) DeleteBreakpointRequest(org.eclipse.che.plugin.zdb.server.connection.ZendDbgClientMessages.DeleteBreakpointRequest) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 7 with Location

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

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

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

the class JavaDebugger method processStepEvent.

private boolean processStepEvent(com.sun.jdi.event.StepEvent event) throws DebuggerException {
    setCurrentThread(event.thread());
    com.sun.jdi.Location jdiLocation = event.location();
    Location location = debuggerUtil.getLocation(jdiLocation);
    debuggerCallback.onEvent(new SuspendEventImpl(location));
    return false;
}
Also used : SuspendEventImpl(org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 10 with Location

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

the class JavaDebuggerTest method testStartDebugger.

@Test(priority = 2)
public void testStartDebugger() throws Exception {
    BreakpointImpl breakpoint = new BreakpointImpl(new LocationImpl("com.HelloWorld", 17), false, null);
    debugger.start(new StartActionImpl(singletonList(breakpoint)));
    DebuggerEvent debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof BreakpointActivatedEvent);
    debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof SuspendEvent);
    Location location = ((SuspendEvent) debuggerEvent).getLocation();
    assertEquals(location.getLineNumber(), 17);
    assertEquals(location.getTarget(), "com.HelloWorld");
}
Also used : BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) SuspendEvent(org.eclipse.che.api.debug.shared.model.event.SuspendEvent) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) BreakpointActivatedEvent(org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent) StartActionImpl(org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl) DebuggerEvent(org.eclipse.che.api.debug.shared.model.event.DebuggerEvent) Location(org.eclipse.che.api.debug.shared.model.Location) Test(org.testng.annotations.Test)

Aggregations

Location (org.eclipse.che.api.debug.shared.model.Location)26 LocationImpl (org.eclipse.che.api.debug.shared.model.impl.LocationImpl)11 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)9 Test (org.testng.annotations.Test)9 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)8 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)6 Matcher (java.util.regex.Matcher)4 BreakpointActivatedEventImpl (org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl)4 ArrayList (java.util.ArrayList)3 BreakpointActivatedEvent (org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent)3 DebuggerEvent (org.eclipse.che.api.debug.shared.model.event.DebuggerEvent)3 SuspendEventImpl (org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl)3 IOException (java.io.IOException)2 SuspendEvent (org.eclipse.che.api.debug.shared.model.event.SuspendEvent)2 GdbParseException (org.eclipse.che.plugin.gdb.server.exception.GdbParseException)2 GdbTerminatedException (org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException)2 ExpressionParser (org.eclipse.che.plugin.jdb.server.expression.ExpressionParser)2 NodeJsOutput (org.eclipse.che.plugin.nodejsdbg.server.NodeJsOutput)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1