Exemplo n.º 1
0
  private boolean processBreakPointEvent(com.sun.jdi.event.BreakpointEvent event)
      throws DebuggerException {
    setCurrentThread(event.thread());
    boolean hitBreakpoint;
    ExpressionParser parser =
        (ExpressionParser)
            event
                .request()
                .getProperty("org.eclipse.che.ide.java.debug.condition.expression.parser");
    if (parser != null) {
      com.sun.jdi.Value result = evaluate(parser);
      hitBreakpoint =
          result instanceof com.sun.jdi.BooleanValue && ((com.sun.jdi.BooleanValue) result).value();
    } else {
      // If there is no expression.
      hitBreakpoint = true;
    }

    if (hitBreakpoint) {
      com.sun.jdi.Location jdiLocation = event.location();

      Location location =
          new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber());
      debuggerCallback.onEvent(new SuspendEventImpl(location));
    }

    // Left target JVM in suspended state if result of evaluation of expression is boolean value and
    // true
    // or if condition expression is not set.
    return !hitBreakpoint;
  }
Exemplo n.º 2
0
  protected void runTests() throws Exception {
    /*
     * Get to the top of main()
     * to determine targetClass and mainThread
     */
    BreakpointEvent bpe = startToMain("GetLocalVariables2Targ");
    targetClass = bpe.location().declaringType();
    mainThread = bpe.thread();
    EventRequestManager erm = vm().eventRequestManager();

    bpe = resumeTo("GetLocalVariables2Targ", "bar", "(I)Z");

    /*
     * Inspect the stack frame for main(), not bar()...
     */
    StackFrame frame = bpe.thread().frame(1);
    List localVars = frame.visibleVariables();
    System.out.println("    Visible variables at this point are: ");
    for (Iterator it = localVars.iterator(); it.hasNext(); ) {
      LocalVariable lv = (LocalVariable) it.next();
      System.out.print(lv.name());
      System.out.print(" typeName: ");
      System.out.print(lv.typeName());
      System.out.print(" signature: ");
      System.out.print(lv.type().signature());
      System.out.print(" primitive type: ");
      System.out.println(lv.type().name());

      if ("command".equals(lv.name())) {
        failure("Failure: LocalVariable \"command\" should not be visible at this point.");
        if (lv.isVisible(frame)) {
          System.out.println("Failure: \"command.isvisible(frame)\" returned true.");
        }
      }
    }

    /*
     * resume the target listening for events
     */
    listenUntilVMDisconnect();

    /*
     * deal with results of test
     * if anything has called failure("foo") testFailed will be true
     */
    if (!testFailed) {
      println("GetLocalVariables2Test: passed");
    } else {
      throw new Exception("GetLocalVariables2Test: failed");
    }
  }
Exemplo n.º 3
0
  protected void runTests() throws Exception {
    /*
     * Get to the top of main()
     * to determine targetClass and mainThread
     */

    BreakpointEvent bpe = startToMain("EarlyReturnTarg");
    targetClass = (ClassType) bpe.location().declaringType();
    mainThread = bpe.thread();

    /*
     * Ask for method exit events
     */
    MethodExitRequest exitRequest = eventRequestManager().createMethodExitRequest();

    for (int i = 0; i < excludes.length; ++i) {
      exitRequest.addClassExclusionFilter(excludes[i]);
    }
    int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
    // sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
    // sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
    exitRequest.setSuspendPolicy(sessionSuspendPolicy);
    exitRequest.enable();

    /*
     * Turn on the flag so debugee knows to check for early
     * return values instead of regular return values.
     */
    Field flagField = targetClass.fieldByName("debuggerWatching");
    targetClass.setValue(flagField, vm().mirrorOf(true));

    /*
     * We set and enable breakpoints on all of the interesting
     * methods called by doit().  In the breakpointReached()
     * handler we force an early return with a different return
     * value.
     *
     * The MethodExitEvent handler will keep score.
     */

    setBreakpoint("EarlyReturnTarg", "s_bytef", "(I)B");
    setBreakpoint("EarlyReturnTarg", "s_charf", "()C");
    setBreakpoint("EarlyReturnTarg", "s_doublef", "()D");
    setBreakpoint("EarlyReturnTarg", "s_floatf", "()F");
    setBreakpoint("EarlyReturnTarg", "s_intf", "()I");
    setBreakpoint("EarlyReturnTarg", "s_longf", "()J");
    setBreakpoint("EarlyReturnTarg", "s_shortf", "()S");
    setBreakpoint("EarlyReturnTarg", "s_booleanf", "()Z");

    setBreakpoint("EarlyReturnTarg", "s_stringf", "()Ljava/lang/String;");
    setBreakpoint("EarlyReturnTarg", "s_classf", "()Ljava/lang/Class;");
    setBreakpoint("EarlyReturnTarg", "s_classLoaderf", "()Ljava/lang/ClassLoader;");
    setBreakpoint("EarlyReturnTarg", "s_threadf", "()Ljava/lang/Thread;");
    setBreakpoint("EarlyReturnTarg", "s_threadGroupf", "()Ljava/lang/ThreadGroup;");
    setBreakpoint("EarlyReturnTarg", "s_intArrayf", "()[I");
    setBreakpoint("EarlyReturnTarg", "s_nullObjectf", "()Ljava/lang/Object;");
    setBreakpoint("EarlyReturnTarg", "s_objectf", "()Ljava/lang/Object;");
    setBreakpoint("EarlyReturnTarg", "s_voidf", "()V");

    setBreakpoint("EarlyReturnTarg", "i_bytef", "(I)B");
    setBreakpoint("EarlyReturnTarg", "i_charf", "()C");
    setBreakpoint("EarlyReturnTarg", "i_doublef", "()D");
    setBreakpoint("EarlyReturnTarg", "i_floatf", "()F");
    setBreakpoint("EarlyReturnTarg", "i_intf", "()I");
    setBreakpoint("EarlyReturnTarg", "i_longf", "()J");
    setBreakpoint("EarlyReturnTarg", "i_shortf", "()S");
    setBreakpoint("EarlyReturnTarg", "i_booleanf", "()Z");
    setBreakpoint("EarlyReturnTarg", "i_stringf", "()Ljava/lang/String;");
    setBreakpoint("EarlyReturnTarg", "i_intArrayf", "()[I");
    setBreakpoint("EarlyReturnTarg", "i_classf", "()Ljava/lang/Class;");
    setBreakpoint("EarlyReturnTarg", "i_classLoaderf", "()Ljava/lang/ClassLoader;");
    setBreakpoint("EarlyReturnTarg", "i_threadf", "()Ljava/lang/Thread;");
    setBreakpoint("EarlyReturnTarg", "i_threadGroupf", "()Ljava/lang/ThreadGroup;");
    setBreakpoint("EarlyReturnTarg", "i_nullObjectf", "()Ljava/lang/Object;");
    setBreakpoint("EarlyReturnTarg", "i_objectf", "()Ljava/lang/Object;");
    setBreakpoint("EarlyReturnTarg", "i_voidf", "()V");

    /* Here we go.  This adds 'this' as a listener so
     * that our handlers above will be called.
     */
    listenUntilVMDisconnect();

    if (earlyReturns != expectedEarlyReturns) {
      failure("failure: Expected " + expectedEarlyReturns + ", but got " + earlyReturns);
    }
    System.out.println("All done, " + earlyReturns + " passed");

    if (!testFailed) {
      System.out.println();
      System.out.println("EarlyReturnTest: passed");
    } else {
      System.out.println();
      System.out.println("EarlyReturnTest: failed");
      throw new Exception("EarlyReturnTest: failed");
    }
  }
Exemplo n.º 4
0
  public void breakpointReached(BreakpointEvent event) {
    String origMethodName = event.location().method().name();
    String methodName = origMethodName.substring(2);
    ThreadReference tr = event.thread();

    if (vm().canForceEarlyReturn()) {

      try {

        if ("bytef".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("ebyteValue");
          ByteValue theValue = (ByteValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
          /*
           * See what happens if we access the stack after the force
           * and before the resume.  Disabling this since spec says
           * the stack is undefined.  This type of code can be used to
           * pursue just what that means.
           *
           * StackFrame sf = tr.frame(0);
           * List<Value> ll = sf.getArgumentValues();
           * for (Value vv: ll) {
           *     System.out.println("vv = " + vv);
           * }
           */
        } else if ("charf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("echarValue");
          CharValue theValue = (CharValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("doublef".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("edoubleValue");
          DoubleValue theValue = (DoubleValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("floatf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("efloatValue");
          FloatValue theValue = (FloatValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("intf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("eintValue");
          IntegerValue theValue = (IntegerValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("longf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("elongValue");
          LongValue theValue = (LongValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("shortf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("eshortValue");
          ShortValue theValue = (ShortValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("booleanf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("ebooleanValue");
          BooleanValue theValue = (BooleanValue) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("stringf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("estringValue");
          StringReference theValue = (StringReference) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("classf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("eclassValue");
          ClassObjectReference theValue =
              (ClassObjectReference) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("classLoaderf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("eclassLoaderValue");
          ClassLoaderReference theValue =
              (ClassLoaderReference) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("threadf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("ethreadValue");
          ThreadReference theValue = (ThreadReference) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("threadGroupf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("ethreadGroupValue");
          ThreadGroupReference theValue =
              (ThreadGroupReference) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("intArrayf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("eintArrayValue");
          ArrayReference theValue = (ArrayReference) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("nullObjectf".equals(methodName)) {
          tr.forceEarlyReturn(null);
        } else if ("objectf".equals(methodName)) {
          Field theValueField = targetClass.fieldByName("eobjectValue");
          ObjectReference theValue = (ObjectReference) targetClass.getValue(theValueField);
          tr.forceEarlyReturn(theValue);
        } else if ("voidf".equals(methodName)) {
          VoidValue theValue = vm().mirrorOfVoid();
          tr.forceEarlyReturn(theValue);
        } else {
          failure("failure: Unknown methodName: " + origMethodName);
        }

      } catch (Exception ex) {
        failure("failure: " + ex.toString());
        ex.printStackTrace();
      }
    } else {
      System.out.println("Cannot force early return for method: " + origMethodName);
    }
  }