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 into/over not necessarily in the top frame. | 32 // Tests how debugger can step 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 } | |
43 function f() { | 38 function f() { |
44 var a = 1978; | 39 var a = 1978; |
45 for (state[2] = 0; state[2] < 5; state[2]++) { | 40 for (state[2] = 0; state[2] < 5; state[2]++) { |
46 void String(a); | 41 void String(a); |
47 } | 42 } |
48 } | 43 } |
49 function g() { | 44 function g() { |
50 for (state[1] = 0; state[1] < 5; state[1]++) { | 45 for (state[1] = 0; state[1] < 5; state[1]++) { |
51 f() + e(); | 46 f(); |
52 } | 47 } |
53 } | 48 } |
54 function h() { | 49 function h() { |
55 state = [-1, -1, -1, -1]; | 50 state = [-1, -1, -1]; |
56 for (state[0] = 0; state[0] < 5; state[0]++) { | 51 for (state[0] = 0; state[0] < 5; state[0]++) { |
57 g(); | 52 g(); |
58 } | 53 } |
59 } | 54 } |
60 | 55 |
61 function TestCase(frame_index, step_count, expected_final_state, action) { | 56 function TestCase(frame_index, step_count, expected_final_state) { |
62 action = action || Debug.StepAction.StepNext; | 57 print("Test case, parameters " + frame_index + "/" + step_count); |
63 print("Test case, parameters " + frame_index + "/" + step_count + | |
64 ", action " + action); | |
65 | 58 |
66 var listener_exception = null; | 59 var listener_exception = null; |
67 var state_snapshot; | 60 var state_snapshot; |
68 var listener_state; | 61 var listener_state; |
69 var bp; | 62 var bp; |
70 | 63 |
71 function listener(event, exec_state, event_data, data) { | 64 function listener(event, exec_state, event_data, data) { |
72 print("Here ("+event+"/"+listener_state+"): " + | 65 print("Here ("+event+"/"+listener_state+"): " + |
73 exec_state.frame(0).sourceLineText()); | 66 exec_state.frame(0).sourceLineText()); |
74 try { | 67 try { |
75 if (event == Debug.DebugEvent.Break) { | 68 if (event == Debug.DebugEvent.Break) { |
76 if (listener_state == 0) { | 69 if (listener_state == 0) { |
77 Debug.clearBreakPoint(bp); | 70 Debug.clearBreakPoint(bp); |
78 var context_frame; | 71 var context_frame; |
79 if (frame_index !== undefined) { | 72 if (frame_index !== undefined) { |
80 context_frame = exec_state.frame(frame_index); | 73 context_frame = exec_state.frame(frame_index); |
81 } | 74 } |
82 exec_state.prepareStep(action, step_count, context_frame); | 75 exec_state.prepareStep(Debug.StepAction.StepNext, |
| 76 step_count, context_frame); |
83 listener_state = 1; | 77 listener_state = 1; |
84 } else if (listener_state == 1) { | 78 } else if (listener_state == 1) { |
85 state_snapshot = String(state); | 79 state_snapshot = String(state); |
86 print("State: " + state_snapshot); | 80 print("State: " + state_snapshot); |
87 Debug.setListener(null); | 81 Debug.setListener(null); |
88 listener_state = 2; | 82 listener_state = 2; |
89 } | 83 } |
90 } | 84 } |
91 } catch (e) { | 85 } catch (e) { |
92 listener_exception = e; | 86 listener_exception = e; |
93 } | 87 } |
94 } | 88 } |
95 | 89 |
96 | 90 |
97 // Add the debug event listener. | 91 // Add the debug event listener. |
98 listener_state = 0; | 92 listener_state = 0; |
99 Debug.setListener(listener); | 93 Debug.setListener(listener); |
100 bp = Debug.setBreakPoint(f, 1); | 94 bp = Debug.setBreakPoint(f, 1); |
101 | 95 |
102 h(); | 96 h(); |
103 Debug.setListener(null); | 97 Debug.setListener(null); |
104 if (listener_exception !== null) { | 98 if (listener_exception !== null) { |
105 print("Exception caught: " + listener_exception); | 99 print("Exception caught: " + listener_exception); |
106 assertUnreachable(); | 100 assertUnreachable(); |
107 } | 101 } |
108 | 102 |
109 assertEquals(expected_final_state, state_snapshot); | 103 assertEquals(expected_final_state, state_snapshot); |
110 } | 104 } |
111 | 105 |
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 } | |
116 | 106 |
117 // Warm-up -- make sure all is compiled and ready for breakpoint. | 107 // Warm-up -- make sure all is compiled and ready for breakpoint. |
118 h(); | 108 h(); |
119 | 109 |
120 | 110 |
121 // Stepping over on the default (top) frame. | 111 // Stepping in the default (top) frame. |
122 TestCase(undefined, 0, "0,0,-1,-1"); | 112 TestCase(undefined, 0, "0,0,-1"); |
123 TestCase(undefined, 1, "0,0,-1,-1"); | 113 TestCase(undefined, 1, "0,0,-1"); |
124 TestCase(undefined, 2, "0,0,0,-1"); | 114 TestCase(undefined, 2, "0,0,0"); |
125 TestCase(undefined, 5, "0,0,1,-1"); | 115 TestCase(undefined, 5, "0,0,1"); |
126 TestCase(undefined, 8, "0,0,3,-1"); | 116 TestCase(undefined, 8, "0,0,3"); |
127 | 117 |
128 // Stepping over on the frame #0 (should be exactly the same as above). | 118 // Stepping in the frame #0 (should be exactly the same as above). |
129 TestCase(0, 0, "0,0,-1,-1"); | 119 TestCase(0, 0, "0,0,-1"); |
130 TestCase(0, 1, "0,0,-1,-1"); | 120 TestCase(0, 1, "0,0,-1"); |
131 TestCase(0, 2, "0,0,0,-1"); | 121 TestCase(0, 2, "0,0,0"); |
132 TestCase(0, 5, "0,0,1,-1"); | 122 TestCase(0, 5, "0,0,1"); |
133 TestCase(0, 8, "0,0,3,-1"); | 123 TestCase(0, 8, "0,0,3"); |
134 | 124 |
135 // Stepping over on the frame #1. | 125 // Stepping in the frame #1. |
136 TestCase(1, 0, "0,0,5,5"); | 126 TestCase(1, 0, "0,0,5"); |
137 TestCase(1, 3, "0,1,5,5"); | 127 TestCase(1, 3, "0,1,5"); |
138 TestCase(1, 8, "0,4,5,5"); | 128 TestCase(1, 8, "0,4,5"); |
139 | 129 |
140 // Stepping over on the frame #2. | 130 // Stepping in the frame #2. |
141 TestCase(2, 3, "1,5,5,5"); | 131 TestCase(2, 3, "1,5,5"); |
142 TestCase(2, 8, "4,5,5,5"); | 132 TestCase(2, 8, "4,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 |