OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug |
29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
30 Debug = debug.Debug | 30 Debug = debug.Debug |
31 | 31 |
32 // Tests how debugger can step over not necessarily in the top frame. | 32 // Tests how debugger can step into/over not necessarily in the top frame. |
33 | 33 |
34 // Simple 3 functions, that protocol their execution state in global | 34 // Simple 3 functions, that protocol their execution state in global |
35 // variable state. | 35 // variable state. |
36 var state; | 36 var state; |
37 | 37 |
| 38 function e() { |
| 39 for (state[3] = 0; state[3] < 5; state[3]++) { |
| 40 void ("" + e + state[3]); |
| 41 } |
| 42 } |
38 function f() { | 43 function f() { |
39 var a = 1978; | 44 var a = 1978; |
40 for (state[2] = 0; state[2] < 5; state[2]++) { | 45 for (state[2] = 0; state[2] < 5; state[2]++) { |
41 void String(a); | 46 void String(a); |
42 } | 47 } |
43 } | 48 } |
44 function g() { | 49 function g() { |
45 for (state[1] = 0; state[1] < 5; state[1]++) { | 50 for (state[1] = 0; state[1] < 5; state[1]++) { |
46 f(); | 51 f() + e(); |
47 } | 52 } |
48 } | 53 } |
49 function h() { | 54 function h() { |
50 state = [-1, -1, -1]; | 55 state = [-1, -1, -1, -1]; |
51 for (state[0] = 0; state[0] < 5; state[0]++) { | 56 for (state[0] = 0; state[0] < 5; state[0]++) { |
52 g(); | 57 g(); |
53 } | 58 } |
54 } | 59 } |
55 | 60 |
56 function TestCase(frame_index, step_count, expected_final_state) { | 61 function TestCase(frame_index, step_count, expected_final_state, action) { |
57 print("Test case, parameters " + frame_index + "/" + step_count); | 62 action = action || Debug.StepAction.StepNext; |
| 63 print("Test case, parameters " + frame_index + "/" + step_count + |
| 64 ", action " + action); |
58 | 65 |
59 var listener_exception = null; | 66 var listener_exception = null; |
60 var state_snapshot; | 67 var state_snapshot; |
61 var listener_state; | 68 var listener_state; |
62 var bp; | 69 var bp; |
63 | 70 |
64 function listener(event, exec_state, event_data, data) { | 71 function listener(event, exec_state, event_data, data) { |
65 print("Here ("+event+"/"+listener_state+"): " + | 72 print("Here ("+event+"/"+listener_state+"): " + |
66 exec_state.frame(0).sourceLineText()); | 73 exec_state.frame(0).sourceLineText()); |
67 try { | 74 try { |
68 if (event == Debug.DebugEvent.Break) { | 75 if (event == Debug.DebugEvent.Break) { |
69 if (listener_state == 0) { | 76 if (listener_state == 0) { |
70 Debug.clearBreakPoint(bp); | 77 Debug.clearBreakPoint(bp); |
71 var context_frame; | 78 var context_frame; |
72 if (frame_index !== undefined) { | 79 if (frame_index !== undefined) { |
73 context_frame = exec_state.frame(frame_index); | 80 context_frame = exec_state.frame(frame_index); |
74 } | 81 } |
75 exec_state.prepareStep(Debug.StepAction.StepNext, | 82 exec_state.prepareStep(action, step_count, context_frame); |
76 step_count, context_frame); | |
77 listener_state = 1; | 83 listener_state = 1; |
78 } else if (listener_state == 1) { | 84 } else if (listener_state == 1) { |
79 state_snapshot = String(state); | 85 state_snapshot = String(state); |
80 print("State: " + state_snapshot); | 86 print("State: " + state_snapshot); |
81 Debug.setListener(null); | 87 Debug.setListener(null); |
82 listener_state = 2; | 88 listener_state = 2; |
83 } | 89 } |
84 } | 90 } |
85 } catch (e) { | 91 } catch (e) { |
86 listener_exception = e; | 92 listener_exception = e; |
87 } | 93 } |
88 } | 94 } |
89 | 95 |
90 | 96 |
91 // Add the debug event listener. | 97 // Add the debug event listener. |
92 listener_state = 0; | 98 listener_state = 0; |
93 Debug.setListener(listener); | 99 Debug.setListener(listener); |
94 bp = Debug.setBreakPoint(f, 1); | 100 bp = Debug.setBreakPoint(f, 1); |
95 | 101 |
96 h(); | 102 h(); |
97 Debug.setListener(null); | 103 Debug.setListener(null); |
98 if (listener_exception !== null) { | 104 if (listener_exception !== null) { |
99 print("Exception caught: " + listener_exception); | 105 print("Exception caught: " + listener_exception); |
100 assertUnreachable(); | 106 assertUnreachable(); |
101 } | 107 } |
102 | 108 |
103 assertEquals(expected_final_state, state_snapshot); | 109 assertEquals(expected_final_state, state_snapshot); |
104 } | 110 } |
105 | 111 |
| 112 function TestCase2(frame_index, step_count, expected_final_state) { |
| 113 return TestCase(frame_index, step_count, expected_final_state, |
| 114 Debug.StepAction.StepIn); |
| 115 } |
106 | 116 |
107 // Warm-up -- make sure all is compiled and ready for breakpoint. | 117 // Warm-up -- make sure all is compiled and ready for breakpoint. |
108 h(); | 118 h(); |
109 | 119 |
110 | 120 |
111 // Stepping in the default (top) frame. | 121 // Stepping over on the default (top) frame. |
112 TestCase(undefined, 0, "0,0,-1"); | 122 TestCase(undefined, 0, "0,0,-1,-1"); |
113 TestCase(undefined, 1, "0,0,-1"); | 123 TestCase(undefined, 1, "0,0,-1,-1"); |
114 TestCase(undefined, 2, "0,0,0"); | 124 TestCase(undefined, 2, "0,0,0,-1"); |
115 TestCase(undefined, 5, "0,0,1"); | 125 TestCase(undefined, 5, "0,0,1,-1"); |
116 TestCase(undefined, 8, "0,0,3"); | 126 TestCase(undefined, 8, "0,0,3,-1"); |
117 | 127 |
118 // Stepping in the frame #0 (should be exactly the same as above). | 128 // Stepping over on the frame #0 (should be exactly the same as above). |
119 TestCase(0, 0, "0,0,-1"); | 129 TestCase(0, 0, "0,0,-1,-1"); |
120 TestCase(0, 1, "0,0,-1"); | 130 TestCase(0, 1, "0,0,-1,-1"); |
121 TestCase(0, 2, "0,0,0"); | 131 TestCase(0, 2, "0,0,0,-1"); |
122 TestCase(0, 5, "0,0,1"); | 132 TestCase(0, 5, "0,0,1,-1"); |
123 TestCase(0, 8, "0,0,3"); | 133 TestCase(0, 8, "0,0,3,-1"); |
124 | 134 |
125 // Stepping in the frame #1. | 135 // Stepping over on the frame #1. |
126 TestCase(1, 0, "0,0,5"); | 136 TestCase(1, 0, "0,0,5,5"); |
127 TestCase(1, 3, "0,1,5"); | 137 TestCase(1, 3, "0,1,5,5"); |
128 TestCase(1, 8, "0,4,5"); | 138 TestCase(1, 8, "0,4,5,5"); |
129 | 139 |
130 // Stepping in the frame #2. | 140 // Stepping over on the frame #2. |
131 TestCase(2, 3, "1,5,5"); | 141 TestCase(2, 3, "1,5,5,5"); |
132 TestCase(2, 8, "4,5,5"); | 142 TestCase(2, 8, "4,5,5,5"); |
| 143 |
| 144 // Stepping into on the default (top) frame. |
| 145 TestCase2(undefined, 0, "0,0,-1,-1"); |
| 146 TestCase2(undefined, 1, "0,0,-1,-1"); |
| 147 TestCase2(undefined, 2, "0,0,0,-1"); |
| 148 TestCase2(undefined, 5, "0,0,1,-1"); |
| 149 TestCase2(undefined, 8, "0,0,3,-1"); |
| 150 |
| 151 // Stepping into on the frame #0 (should be exactly the same as above). |
| 152 TestCase2(0, 0, "0,0,-1,-1"); |
| 153 TestCase2(0, 1, "0,0,-1,-1"); |
| 154 TestCase2(0, 2, "0,0,0,-1"); |
| 155 TestCase2(0, 5, "0,0,1,-1"); |
| 156 TestCase2(0, 8, "0,0,3,-1"); |
| 157 |
| 158 // Stepping into on the frame #1. |
| 159 TestCase2(1, 0, "0,0,5,-1"); |
| 160 TestCase2(1, 3, "0,0,5,0"); |
| 161 TestCase2(1, 8, "0,0,5,2"); |
| 162 TestCase2(1, 9, "0,0,5,3"); |
| 163 |
| 164 // Stepping into on the frame #2. |
| 165 TestCase2(2, 0, "0,5,5,5"); |
| 166 TestCase2(2, 3, "1,5,5,5"); |
| 167 TestCase2(2, 4, "1,0,5,5"); |
| 168 TestCase2(2, 8, "1,0,0,5"); |
| 169 TestCase2(2, 9, "1,0,1,5"); |
OLD | NEW |