Search in sources :

Example 6 with Breakpoint

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

the class GdbInfoBreak method parse.

/**
     * Factory method.
     */
public static GdbInfoBreak parse(GdbOutput gdbOutput) throws GdbParseException {
    String output = gdbOutput.getOutput();
    List<Breakpoint> breakpoints = new ArrayList<>();
    for (String line : output.split("\n")) {
        Matcher matcher = GDB_INFO_B.matcher(line);
        if (matcher.find()) {
            String file = matcher.group(2);
            String lineNumber = matcher.group(3);
            Location location = new LocationImpl(file, Integer.parseInt(lineNumber));
            breakpoints.add(new BreakpointImpl(location));
        }
    }
    return new GdbInfoBreak(breakpoints);
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 7 with Breakpoint

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

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

Example 9 with Breakpoint

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

the class NodeJsDebuggerTest method testManageBreakpoints.

@Test
public void testManageBreakpoints() throws Exception {
    List<Breakpoint> breakpoints = debugger.getAllBreakpoints();
    assertEquals(breakpoints.size(), 1);
    debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("app.js", 2)));
    ArgumentCaptor<BreakpointActivatedEvent> breakpointActivated = ArgumentCaptor.forClass(BreakpointActivatedEvent.class);
    verify(callback).onEvent(breakpointActivated.capture());
    BreakpointActivatedEvent event = breakpointActivated.getValue();
    Breakpoint breakpoint = event.getBreakpoint();
    assertEquals(breakpoint.getLocation().getTarget(), "app.js");
    assertEquals(breakpoint.getLocation().getLineNumber(), 2);
    debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("app.js", 5)));
    breakpoints = debugger.getAllBreakpoints();
    assertEquals(breakpoints.size(), 3);
    debugger.deleteBreakpoint(new LocationImpl("app.js", 2));
    breakpoints = debugger.getAllBreakpoints();
    assertEquals(breakpoints.size(), 2);
    debugger.deleteAllBreakpoints();
    breakpoints = debugger.getAllBreakpoints();
    assertEquals(breakpoints.size(), 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) Test(org.testng.annotations.Test)

Example 10 with Breakpoint

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

the class JavaDebugger method deferBreakpoint.

private void deferBreakpoint(Breakpoint breakpoint) throws DebuggerException {
    final String className = breakpoint.getLocation().getTarget();
    List<Breakpoint> newList = new ArrayList<>();
    List<Breakpoint> list = deferredBreakpoints.putIfAbsent(className, newList);
    if (list == null) {
        list = newList;
    }
    list.add(breakpoint);
    // start listening for the load of the type
    if (!classPrepareRequests.containsKey(className)) {
        ClassPrepareRequest request = getEventManager().createClassPrepareRequest();
        // set class filter in order to reduce the amount of event traffic sent from the target VM to the debugger VM
        request.addClassFilter(className);
        request.enable();
        classPrepareRequests.put(className, request);
    }
    LOG.debug("Deferred breakpoint: {}", breakpoint.getLocation().toString());
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) ArrayList(java.util.ArrayList) ClassPrepareRequest(com.sun.jdi.request.ClassPrepareRequest)

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