/** The 'refType' is known to match, return the EventRequest. */
 EventRequest resolveEventRequest(ReferenceType refType) throws NoSuchFieldException {
   Field field = refType.fieldByName(fieldId);
   EventRequestManager em = refType.virtualMachine().eventRequestManager();
   EventRequest wp = em.createAccessWatchpointRequest(field);
   wp.setSuspendPolicy(suspendPolicy);
   wp.enable();
   return wp;
 }
Exemplo n.º 2
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);
  }
  private EventRequest findRequest(DebugProcessImpl debugProcess, Class requestClass) {
    Set reqSet = debugProcess.getRequestsManager().findRequests(this);
    for (Iterator iterator = reqSet.iterator(); iterator.hasNext(); ) {
      EventRequest eventRequest = (EventRequest) iterator.next();
      if (eventRequest.getClass().equals(requestClass)) {
        return eventRequest;
      }
    }

    return null;
  }
 public void onEvent(Event event, EventRequest request) {
   if (event instanceof StepEvent) {
     request.disable();
     boeBotDebugger.stepRequest = null;
     boeBotDebugger.updateView();
   }
   if (event instanceof BreakpointEvent) {
     boeBotDebugger.updateView();
   }
 }
Exemplo n.º 5
0
 @Override
 protected void configureRequestHitCount(EventRequest request) throws CoreException {
   if (request instanceof BreakpointRequest) {
     super.configureRequestHitCount(request);
   } else {
     int hitCount = getHitCount();
     if (hitCount > 0) {
       request.putProperty(HIT_COUNT, new Integer(hitCount));
     }
   }
 }
Exemplo n.º 6
0
 @Override
 protected void updateEnabledState(EventRequest request, JDXDebugTarget target)
     throws CoreException {
   boolean enabled = isEnabled();
   if (request instanceof MethodEntryRequest || request instanceof BreakpointRequest) {
     enabled = enabled && isEntry();
   } else if (request instanceof MethodExitRequest) {
     enabled = enabled && isExit();
   }
   if (enabled != request.isEnabled()) {
     internalUpdateEnabledState(request, enabled, target);
   }
 }
Exemplo n.º 7
0
    EventDestination destination() {
      /*
       * We need to decide if this event is for
       * 1. an internal request
       * 2. a client request that is no longer available, ie
       *    it has been deleted, or disabled and re-enabled
       *    which gives it a new ID.
       * 3. a current client request that is disabled
       * 4. a current enabled client request.
       *
       * We will filter this set into a set
       * that contains only 1s for our internal queue
       * and a set that contains only 4s for our client queue.
       * If we get an EventSet that contains only 2 and 3
       * then we have to resume it if it is not SUSPEND_NONE
       * because no one else will.
       */
      if (requestID == 0) {
        /* An unsolicited event.  These have traditionally
         * been treated as client events.
         */
        return EventDestination.CLIENT_EVENT;
      }

      // Is this an event for a current client request?
      if (request == null) {
        // Nope.  Is it an event for an internal request?
        EventRequestManagerImpl ermi = this.vm.getInternalEventRequestManager();
        if (ermi.request(eventCmd, requestID) != null) {
          // Yep
          return EventDestination.INTERNAL_EVENT;
        }
        return EventDestination.UNKNOWN_EVENT;
      }

      // We found a client request
      if (request.isEnabled()) {
        return EventDestination.CLIENT_EVENT;
      }
      return EventDestination.UNKNOWN_EVENT;
    }