Search in sources :

Example 1 with BreakpointRequest

use of com.sun.jdi.request.BreakpointRequest 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 BreakpointRequest

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

use of com.sun.jdi.request.BreakpointRequest in project otertool by wuntee.

the class Testing method addBreakpointToMethod.

public static void addBreakpointToMethod(Method m, EventRequestManager mgr) {
    System.out.println("Breakpoint: " + m.toString());
    try {
        Location location = m.location();
        BreakpointRequest bpr = mgr.createBreakpointRequest(location);
        bpr.enable();
    } catch (com.sun.jdi.NativeMethodException e) {
        System.out.println("Error: Cant add breakpoint to native method (" + m.toString() + ")");
    }
}
Also used : BreakpointRequest(com.sun.jdi.request.BreakpointRequest) Location(com.sun.jdi.Location)

Example 4 with BreakpointRequest

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

the class ThreadReferenceImpl method isAtBreakpoint.

public boolean isAtBreakpoint() {
    /*
         * TO DO: This fails to take filters into account.
         */
    try {
        StackFrame frame = frame(0);
        Location location = frame.location();
        List<BreakpointRequest> requests = vm.eventRequestManager().breakpointRequests();
        Iterator<BreakpointRequest> iter = requests.iterator();
        while (iter.hasNext()) {
            BreakpointRequest request = iter.next();
            if (location.equals(request.location())) {
                return true;
            }
        }
        return false;
    } catch (IndexOutOfBoundsException iobe) {
        // no frames on stack => not at breakpoint
        return false;
    } catch (IncompatibleThreadStateException itse) {
        // Per the javadoc, not suspended => return false
        return false;
    }
}
Also used : BreakpointRequest(com.sun.jdi.request.BreakpointRequest)

Example 5 with BreakpointRequest

use of com.sun.jdi.request.BreakpointRequest in project che by eclipse.

the class JavaDebugger method getAllBreakpoints.

@Override
public List<Breakpoint> getAllBreakpoints() throws DebuggerException {
    List<BreakpointRequest> breakpointRequests;
    try {
        breakpointRequests = getEventManager().breakpointRequests();
    } catch (DebuggerException e) {
        Throwable cause = e.getCause();
        if (cause instanceof VMCannotBeModifiedException) {
            // If target VM in read-only state then list of break point always empty.
            return Collections.emptyList();
        }
        throw e;
    }
    List<Breakpoint> breakPoints = new ArrayList<>(breakpointRequests.size());
    for (BreakpointRequest breakpointRequest : breakpointRequests) {
        com.sun.jdi.Location location = breakpointRequest.location();
        // Breakpoint always enabled at the moment. Managing states of breakpoint is not supported for now.
        breakPoints.add(newDto(BreakpointDto.class).withEnabled(true).withLocation(newDto(LocationDto.class).withTarget(location.declaringType().name()).withLineNumber(location.lineNumber())));
    }
    Collections.sort(breakPoints, BREAKPOINT_COMPARATOR);
    return breakPoints;
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) BreakpointRequest(com.sun.jdi.request.BreakpointRequest) ArrayList(java.util.ArrayList) VMCannotBeModifiedException(com.sun.jdi.VMCannotBeModifiedException) BreakpointDto(org.eclipse.che.api.debug.shared.dto.BreakpointDto)

Aggregations

BreakpointRequest (com.sun.jdi.request.BreakpointRequest)8 EventRequestManager (com.sun.jdi.request.EventRequestManager)4 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)3 Location (com.sun.jdi.Location)2 Method (com.sun.jdi.Method)2 ReferenceType (com.sun.jdi.ReferenceType)2 ArrayList (java.util.ArrayList)2 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)1 ClassNotPreparedException (com.sun.jdi.ClassNotPreparedException)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 VMCannotBeModifiedException (com.sun.jdi.VMCannotBeModifiedException)1 EventRequest (com.sun.jdi.request.EventRequest)1 InvalidRequestStateException (com.sun.jdi.request.InvalidRequestStateException)1 BreakpointDto (org.eclipse.che.api.debug.shared.dto.BreakpointDto)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 DebuggerAbsentInformationException (org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)1 ExpressionParser (org.eclipse.che.plugin.jdb.server.expression.ExpressionParser)1