예제 #1
0
  @Override
  public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException {
    final String className = breakpoint.getLocation().getTarget();
    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(breakpoint));
    LOG.debug("Add breakpoint: {}", location);
  }
예제 #2
0
 private EventRequest createMethodRequest(JDXDebugTarget target, Object classFilter, boolean entry)
     throws CoreException {
   EventRequest request = null;
   EventRequestManager manager = target.getEventRequestManager();
   if (manager == null) {
     target.requestFailed(
         JDXMessages.JDXMethodBreakpoint_Unable_to_create_breakpoint_request___VM_disconnected__1,
         null); //$NON-NLS-1$
   }
   try {
     if (entry) {
       if (classFilter instanceof ClassType
           && getMethodName() != null
           && getMethodSignature() != null) {
         ClassType clazz = (ClassType) classFilter;
         if (clazz.name().equals(getTypeName())) {
           Method method = clazz.concreteMethodByName(getMethodName(), getMethodSignature());
           if (method != null && !method.isNative()) {
             Location location = method.location();
             if (location != null && location.codeIndex() != -1) {
               request = manager.createBreakpointRequest(location);
             }
           }
         }
       }
       if (request == null) {
         request = manager.createMethodEntryRequest();
         if (classFilter instanceof String) {
           ((MethodEntryRequest) request).addClassFilter((String) classFilter);
         } else if (classFilter instanceof ReferenceType) {
           ((MethodEntryRequest) request).addClassFilter((ReferenceType) classFilter);
         }
       }
     } else {
       request = manager.createMethodExitRequest();
       if (classFilter instanceof String) {
         ((MethodExitRequest) request).addClassFilter((String) classFilter);
       } else if (classFilter instanceof ReferenceType) {
         ((MethodExitRequest) request).addClassFilter((ReferenceType) classFilter);
       }
     }
     configureRequest(request, target);
   } catch (VMDisconnectedException e) {
     if (!target.isAvailable()) {
       return null;
     }
     Plugin.log(e);
   } catch (RuntimeException e) {
     target.internalError(e);
   }
   return request;
 }