Search in sources :

Example 1 with EventRequest

use of com.sun.jdi.request.EventRequest 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 2 with EventRequest

use of com.sun.jdi.request.EventRequest in project jdk8u_jdk by JetBrains.

the class EventRequestSpecList method addEagerlyResolve.

boolean addEagerlyResolve(EventRequestSpec spec) {
    try {
        eventRequestSpecs.add(spec);
        EventRequest eventRequest = spec.resolveEagerly();
        if (eventRequest != null) {
            MessageOutput.println("Set", spec.toString());
        }
        return true;
    } catch (Exception exc) {
        MessageOutput.println("Unable to set", new Object[] { spec.toString(), spec.errorMessageFor(exc) });
        return false;
    }
}
Also used : EventRequest(com.sun.jdi.request.EventRequest)

Example 3 with EventRequest

use of com.sun.jdi.request.EventRequest in project jdk8u_jdk by JetBrains.

the class ModificationWatchpointSpec method resolveEventRequest.

/**
     * The 'refType' is known to match, return the EventRequest.
     */
@Override
EventRequest resolveEventRequest(ReferenceType refType) throws NoSuchFieldException {
    Field field = refType.fieldByName(fieldId);
    EventRequestManager em = refType.virtualMachine().eventRequestManager();
    EventRequest wp = em.createModificationWatchpointRequest(field);
    wp.setSuspendPolicy(suspendPolicy);
    wp.enable();
    return wp;
}
Also used : EventRequest(com.sun.jdi.request.EventRequest) EventRequestManager(com.sun.jdi.request.EventRequestManager)

Aggregations

EventRequest (com.sun.jdi.request.EventRequest)3 EventRequestManager (com.sun.jdi.request.EventRequestManager)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)1 ClassNotPreparedException (com.sun.jdi.ClassNotPreparedException)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 ReferenceType (com.sun.jdi.ReferenceType)1 BreakpointRequest (com.sun.jdi.request.BreakpointRequest)1 InvalidRequestStateException (com.sun.jdi.request.InvalidRequestStateException)1 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)1 Location (org.eclipse.che.api.debug.shared.model.Location)1 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)1 BreakpointActivatedEventImpl (org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1 DebuggerAbsentInformationException (org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)1 ExpressionParser (org.eclipse.che.plugin.jdb.server.expression.ExpressionParser)1