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