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