< prev index next >

test/com/sun/jdi/PopAndStepTest.java

Print this page
rev 16940 : 8177507: line number sensitive tests for jdi should be unified
Reviewed-by: duke
   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             }


  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 }
   1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 //    THIS TEST IS LINE NUMBER SENSITIVE
  25 
  26 /**
  27  * @test
  28  * @bug 4530424
  29  * @summary Hin says that doing a step over after a popframe acts like a resume.

  30  * @author jjh
  31  *
  32  * @library ..
  33  *
  34  * @run build TestScaffold VMConnection TargetListener TargetAdapter
  35  * @run compile -g PopAndStepTest.java
  36  * @run driver PopAndStepTest
  37  */
  38 import com.sun.jdi.*;
  39 import com.sun.jdi.event.*;
  40 import com.sun.jdi.request.*;
  41 
  42 import java.util.*;
  43 


  44 class PopAndStepTarg {
  45     public void B() {
  46         System.out.println("debuggee: in B");             // B_LINE_1
  47         System.out.println("debuggee: in B, back to A");  // B_LINE_2
  48     }
  49 
  50     public void A() {
  51         System.out.println("debuggee: in A, about to call B");  // A_LINE_1
  52         B();                                                    // A_LINE_2
  53         System.out.println("debuggee: in A, back from B");      // A_LINE_3
  54         throw new RuntimeException("debuggee: Got to line A_LINE_4:" + PopAndStepTest.A_LINE_4); // A_LINE_4
  55     }
  56 
  57     public static void main(String[] args) {
  58         System.out.println("debuggee: Howdy!");      // MAIN_LINE_1
  59         PopAndStepTarg xxx = new PopAndStepTarg();   // MAIN_LINE_2
  60         xxx.A();                                     // MAIN_LINE_3
  61         System.out.println("debugee: Goodbye from PopAndStepTarg!");
  62     }
  63 }
  64 
  65 
  66     /********** test program **********/
  67 
  68 public class PopAndStepTest extends TestScaffold {
  69     static final int B_LINE_1 = 46;
  70     static final int B_LINE_2 = B_LINE_1 + 1;
  71 
  72     static final int A_LINE_1 = 51;
  73     static final int A_LINE_2 = A_LINE_1 + 1;
  74     static final int A_LINE_3 = A_LINE_1 + 2;
  75     static final int A_LINE_4 = A_LINE_1 + 3;
  76 
  77     static final int MAIN_LINE_1 = 58;
  78     static final int MAIN_LINE_2 = MAIN_LINE_1 + 1;
  79     static final int MAIN_LINE_3 = MAIN_LINE_1 + 2;
  80 
  81     ReferenceType targetClass;
  82     ThreadReference mainThread;
  83 
  84     PopAndStepTest (String args[]) {
  85         super(args);
  86     }
  87 
  88     public static void main(String[] args)      throws Exception {
  89         new PopAndStepTest(args).startTests();
  90     }
  91 
  92 
  93     StackFrame frameFor(String methodName) throws Exception {
  94         Iterator it = mainThread.frames().iterator();
  95 
  96         while (it.hasNext()) {
  97             StackFrame frame = (StackFrame)it.next();
  98             if (frame.location().method().name().equals(methodName)) {
  99                 return frame;
 100             }


 131     }
 132 
 133     /********** test core **********/
 134 
 135     protected void runTests() throws Exception {
 136         /*
 137          * Get to the top of main()
 138          * to determine targetClass and mainThread
 139          */
 140         runOnce();
 141     }
 142 
 143     void runOnce() throws Exception{
 144         /*
 145          * Get to the top of main()
 146          * to determine targetClass and mainThread
 147          */
 148         BreakpointEvent bpe = startToMain("PopAndStepTarg");
 149         targetClass = bpe.location().declaringType();
 150         mainThread = bpe.thread();
 151         getDebuggeeLineNum(MAIN_LINE_1);
 152 
 153         println("Resuming to line B_LINE_2 : " + B_LINE_2);
 154         bpe = resumeTo("PopAndStepTarg", B_LINE_2); getDebuggeeLineNum(B_LINE_2);
 155 
 156         // The failure is this:
 157         //   create step request
 158         //   enable step request
 159         //   pop frame
 160         //   do the step
 161         //   do another step - This step runs to completion
 162         EventRequestManager erm = eventRequestManager();
 163         StepRequest srInto = erm.createStepRequest(mainThread, StepRequest.STEP_LINE,
 164                                                    StepRequest.STEP_INTO);
 165         srInto.addClassExclusionFilter("java.*");
 166         srInto.addClassExclusionFilter("javax.*");
 167         srInto.addClassExclusionFilter("sun.*");
 168         srInto.addClassExclusionFilter("com.sun.*");
 169         srInto.addClassExclusionFilter("com.oracle.*");
 170         srInto.addClassExclusionFilter("oracle.*");
 171         srInto.addClassExclusionFilter("jdk.internal.*");
 172         srInto.addCountFilter(1);
 173         srInto.enable(); // This fails
 174         mainThread.popFrames(frameFor("A"));
 175         //srInto.enable();   // if the enable is moved here, it passes
 176         println("Popped back to line MAIN_LINE_3(" + MAIN_LINE_3 + ") in main, the call to A()");
 177         println("Stepping into line A_LINE_1:" + A_LINE_1);
 178         waitForRequestedEvent(srInto);  // println
 179         srInto.disable();
 180 
 181         getDebuggeeLineNum(A_LINE_1);
 182 
 183         // The failure occurs here.
 184         println("Stepping over to line A_LINE_2:" + A_LINE_2);
 185         stepOverLine(mainThread);       // println
 186         getDebuggeeLineNum(A_LINE_2);
 187 
 188         println("Stepping over to line A_LINE_3:" + A_LINE_3);
 189         stepOverLine(mainThread);       // call to B()
 190         getDebuggeeLineNum(A_LINE_3);
 191 
 192         vm().exit(0);
 193 
 194         if (testFailed) {
 195             throw new Exception("PopAndStepTest failed");
 196         }
 197         println("Passed:");
 198     }
 199 }
< prev index next >