Search in sources :

Example 6 with BreakpointImpl

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

Example 7 with BreakpointImpl

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

Example 8 with BreakpointImpl

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

the class JavaDebuggerTest method testSteps.

@Test(priority = 9)
public void testSteps() throws Exception {
    debugger.deleteAllBreakpoints();
    debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 20), false, null));
    assertTrue(events.take() instanceof BreakpointActivatedEvent);
    debugger.resume(new ResumeActionImpl());
    DebuggerEvent debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof SuspendEvent);
    Location location = ((SuspendEvent) debuggerEvent).getLocation();
    assertEquals(location.getTarget(), "com.HelloWorld");
    assertEquals(location.getLineNumber(), 20);
    assertEquals(location.getExternalResourceId(), -1);
    assertEquals(location.getResourceProjectPath(), "/test");
    assertEquals(location.getResourcePath(), "/test/src/com/HelloWorld.java");
    debugger.stepInto(new StepIntoActionImpl());
    debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof SuspendEvent);
    location = ((SuspendEvent) debuggerEvent).getLocation();
    assertEquals(location.getTarget(), "com.HelloWorld");
    assertEquals(location.getLineNumber(), 28);
    debugger.stepOut(new StepOutActionImpl());
    debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof SuspendEvent);
    location = ((SuspendEvent) debuggerEvent).getLocation();
    assertEquals(location.getTarget(), "com.HelloWorld");
    assertEquals(location.getLineNumber(), 20);
    debugger.stepOver(new StepOverActionImpl());
    debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof SuspendEvent);
    location = ((SuspendEvent) debuggerEvent).getLocation();
    assertEquals(location.getTarget(), "com.HelloWorld");
    assertEquals(location.getLineNumber(), 21);
    debugger.stepOver(new StepOverActionImpl());
    debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof SuspendEvent);
    location = ((SuspendEvent) debuggerEvent).getLocation();
    assertEquals(location.getTarget(), "com.HelloWorld");
    assertEquals(location.getLineNumber(), 23);
    debugger.stepOver(new StepOverActionImpl());
    debuggerEvent = events.take();
    assertTrue(debuggerEvent instanceof SuspendEvent);
    location = ((SuspendEvent) debuggerEvent).getLocation();
    assertEquals(location.getTarget(), "com.HelloWorld");
    assertEquals(location.getLineNumber(), 24);
}
Also used : BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) StepIntoActionImpl(org.eclipse.che.api.debug.shared.model.impl.action.StepIntoActionImpl) StepOverActionImpl(org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl) 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) ResumeActionImpl(org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl) StepOutActionImpl(org.eclipse.che.api.debug.shared.model.impl.action.StepOutActionImpl) DebuggerEvent(org.eclipse.che.api.debug.shared.model.event.DebuggerEvent) Location(org.eclipse.che.api.debug.shared.model.Location) Test(org.testng.annotations.Test)

Example 9 with BreakpointImpl

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

the class NodeJsDebugCommandsLibrary method getBreakpoints.

/**
     * Execute {@code breakpoints} command.
     * @see NodeJsBackTraceParser
     */
public List<Breakpoint> getBreakpoints() throws NodeJsDebuggerException {
    NodeJsDebugCommand<Breakpoints> breakpointsCommand = createCommand("breakpoints", NodeJsBreakpointsParser.INSTANCE);
    List<Breakpoint> breakpoints = doExecute(breakpointsCommand).getAll();
    NodeJsDebugCommand<Scripts> scriptsCommand = createCommand("scripts", NodeJsScriptsParser.INSTANCE);
    Map<Integer, String> scripts = doExecute(scriptsCommand).getAll();
    for (int i = 0; i < breakpoints.size(); i++) {
        Breakpoint breakpoint = breakpoints.get(i);
        Location location = breakpoint.getLocation();
        String newTarget;
        String[] target = location.getTarget().split(":");
        if (target.length != 2) {
            LOG.error(format("Illegal breakpoint location format %s", target[0]));
            continue;
        }
        if (target[0].equals("scriptId")) {
            newTarget = scripts.get((int) Double.parseDouble(target[1]));
        } else {
            newTarget = target[1];
        }
        Location newLocation = new LocationImpl(newTarget, location.getLineNumber());
        Breakpoint newBreakpoint = new BreakpointImpl(newLocation, breakpoint.isEnabled(), breakpoint.getCondition());
        breakpoints.set(i, newBreakpoint);
    }
    return breakpoints;
}
Also used : Breakpoints(org.eclipse.che.plugin.nodejsdbg.server.parser.NodeJsBreakpointsParser.Breakpoints) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) Scripts(org.eclipse.che.plugin.nodejsdbg.server.parser.NodeJsScriptsParser.Scripts) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 10 with BreakpointImpl

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

the class NodeJsBreakpointsParser method parse.

@Override
public Breakpoints parse(NodeJsOutput nodeJsOutput) throws NodeJsDebuggerParseException {
    final List<Breakpoint> breakpoints = new ArrayList<>();
    JsonObject json = new JsonParser().parse(nodeJsOutput.getOutput()).getAsJsonObject();
    if (json.has("breakpoints")) {
        Iterator<JsonElement> iter = json.getAsJsonArray("breakpoints").iterator();
        while (iter.hasNext()) {
            JsonObject item = iter.next().getAsJsonObject();
            try {
                final String condition = item.has("condition") && !item.get("condition").isJsonNull() ? item.get("condition").getAsString() : null;
                final boolean isEnabled = item.has("active") && !item.get("active").isJsonNull() && item.get("active").getAsBoolean();
                final int lineNumber = item.get("line").getAsInt();
                final String target;
                String targetType = item.get("type").getAsString();
                switch(targetType) {
                    case "scriptId":
                        target = String.valueOf(item.get("script_id").getAsInt());
                        break;
                    case "scriptRegExp":
                        target = item.get("script_regexp").getAsString();
                        break;
                    default:
                        throw new IllegalArgumentException("Unsupported 'type' value: " + targetType);
                }
                Location location = new LocationImpl(targetType + ":" + target, lineNumber + 1);
                Breakpoint breakpoint = new BreakpointImpl(location, isEnabled, condition);
                breakpoints.add(breakpoint);
            } catch (Exception e) {
                LOG.error("Failed to parse breakpoint: " + item.toString(), e);
            }
        }
    }
    return new Breakpoints(breakpoints);
}
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) JsonObject(com.google.gson.JsonObject) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) NodeJsDebuggerParseException(org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException) JsonElement(com.google.gson.JsonElement) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) JsonParser(com.google.gson.JsonParser) Location(org.eclipse.che.api.debug.shared.model.Location)

Aggregations

BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)17 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)13 LocationImpl (org.eclipse.che.api.debug.shared.model.impl.LocationImpl)11 Test (org.testng.annotations.Test)10 Location (org.eclipse.che.api.debug.shared.model.Location)9 ArrayList (java.util.ArrayList)7 BreakpointActivatedEvent (org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent)6 DebuggerEvent (org.eclipse.che.api.debug.shared.model.event.DebuggerEvent)5 Matcher (java.util.regex.Matcher)3 ResumeActionImpl (org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl)3 StackFrameDump (org.eclipse.che.api.debug.shared.model.StackFrameDump)2 SuspendEvent (org.eclipse.che.api.debug.shared.model.event.SuspendEvent)2 VariablePathImpl (org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 AbsentInformationException (com.sun.jdi.AbsentInformationException)1 ClassNotPreparedException (com.sun.jdi.ClassNotPreparedException)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 ReferenceType (com.sun.jdi.ReferenceType)1