J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 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 main 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("sun.*"); |
| 134 | srInto.addClassExclusionFilter("com.sun.*"); |
| 135 | srInto.addCountFilter(1); |
| 136 | srInto.enable(); // This fails |
| 137 | mainThread.popFrames(frameFor("A")); |
| 138 | //srInto.enable(); // if the enable is moved here, it passes |
| 139 | println("Popped back to line 40 in main, the call to A()"); |
| 140 | println("Stepping into line 30"); |
| 141 | waitForRequestedEvent(srInto); // println |
| 142 | srInto.disable(); |
| 143 | |
| 144 | getDebuggeeLineNum(30); |
| 145 | |
| 146 | // The failure occurs here. |
| 147 | println("Stepping over to line 31"); |
| 148 | stepOverLine(mainThread); // println |
| 149 | getDebuggeeLineNum(31); |
| 150 | |
| 151 | println("Stepping over to line 32"); |
| 152 | stepOverLine(mainThread); // call to B() |
| 153 | getDebuggeeLineNum(32); |
| 154 | |
| 155 | vm().exit(0); |
| 156 | |
| 157 | if (testFailed) { |
| 158 | throw new Exception("PopAndStepTest failed"); |
| 159 | } |
| 160 | println("Passed:"); |
| 161 | } |
| 162 | } |