jdk/test/com/sun/jdi/PopAndStepTest.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 2 90ce3da70b43
child 20184 a2c4b7079eb6
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/* /nodynamiccopyright/ */  // DO NOT DELETE ANY LINES!!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
//    THIS TEST IS LINE NUMBER SENSITIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *  @bug 4530424
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *  @summary Hin says that doing a step over after a popframe acts like a resume.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  @author jjh
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  @library ..
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *  @run compile -g PopAndStepTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *  @run main PopAndStepTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
    /********** LINE NUMBER SENSITIVE! *****************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
class PopAndStepTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
    public void B() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
        System.out.println("debuggee: in B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
        System.out.println("debuggee: in B, back to A");   // add line breakpoint here line 26 !!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
    public void A() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
        System.out.println("debuggee: in A, about to call B");  // line 30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
        B();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
        System.out.println("debuggee: in A, back from B");      // line 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        throw new RuntimeException("debuggee: Got to line 33");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        System.out.println("debuggee: Howdy!");      // line 37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        PopAndStepTarg xxx = new PopAndStepTarg();   // line 39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        xxx.A();                                     // line 40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        System.out.println("debugee: Goodbye from PopAndStepTarg!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class PopAndStepTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    PopAndStepTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        new PopAndStepTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    StackFrame frameFor(String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Iterator it = mainThread.frames().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            StackFrame frame = (StackFrame)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            if (frame.location().method().name().equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                return frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        failure("FAIL: " + methodName + " not on stack");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    int getDebuggeeLineNum(int expectedLine) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        List allFrames = mainThread.frames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if ( allFrames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        Iterator it = allFrames.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        StackFrame frame = (StackFrame)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        Location loc = frame.location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int theLine = loc.lineNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (expectedLine != theLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            failure("FAIL: Should be at " + expectedLine + ", are at " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    theLine + ", method = " + loc.method().name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            println("Should be at, and am at: " + expectedLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return theLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void vmDied(VMDeathEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        println("Got VMDeathEvent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public void vmDisconnected(VMDisconnectEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        println("Got VMDisconnectEvent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        runOnce();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    void runOnce() throws Exception{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        BreakpointEvent bpe = startToMain("PopAndStepTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        getDebuggeeLineNum(37);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        println("Resuming to line 26");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        bpe = resumeTo("PopAndStepTarg", 26); getDebuggeeLineNum(26);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // The failure is this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        //   create step request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        //   enable step request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        //   pop frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        //   do the step
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        //   do another step - This step runs to completion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        EventRequestManager erm = eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        StepRequest srInto = erm.createStepRequest(mainThread, StepRequest.STEP_LINE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                                   StepRequest.STEP_INTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        srInto.addClassExclusionFilter("java.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        srInto.addClassExclusionFilter("sun.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        srInto.addClassExclusionFilter("com.sun.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        srInto.addCountFilter(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        srInto.enable(); // This fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        mainThread.popFrames(frameFor("A"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        //srInto.enable();   // if the enable is moved here, it passes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        println("Popped back to line 40 in main, the call to A()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        println("Stepping into line 30");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        waitForRequestedEvent(srInto);   // println
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        srInto.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        getDebuggeeLineNum(30);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // The failure occurs here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        println("Stepping over to line 31");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        stepOverLine(mainThread);   // println
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        getDebuggeeLineNum(31);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        println("Stepping over to line 32");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        stepOverLine(mainThread);        // call to B()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        getDebuggeeLineNum(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        vm().exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new Exception("PopAndStepTest failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        println("Passed:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}