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 } 101 } 102 failure("FAIL: " + methodName + " not on stack"); 103 return null; 104 } 105 106 int getDebuggeeLineNum(int expectedLine) throws Exception { 107 List allFrames = mainThread.frames(); 108 if ( allFrames == null) { 109 return -1; 110 } 111 Iterator it = allFrames.iterator(); 112 StackFrame frame = (StackFrame)it.next(); 113 Location loc = frame.location(); 114 int theLine = loc.lineNumber(); 115 if (expectedLine != theLine) { 116 failure("FAIL: Should be at " + expectedLine + ", are at " + 117 theLine + ", method = " + loc.method().name()); 118 } else { 119 println("Should be at, and am at: " + expectedLine); 120 } 121 return theLine; 122 } 123 124 125 public void vmDied(VMDeathEvent event) { 126 println("Got VMDeathEvent"); 127 } 128 129 public void vmDisconnected(VMDisconnectEvent event) { 130 println("Got VMDisconnectEvent"); 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 }