1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
28 // Flags: --expose-debug-as debug
29 // Get the Debug object exposed from the debug context global object.
32 function f() {a=1;b=2}
38 bp = Debug.setBreakPoint(f, 0, 0);
39 assertEquals("() {[B0]a=1;b=2}", Debug.showBreakPoints(f));
40 Debug.clearBreakPoint(bp);
41 assertEquals("() {a=1;b=2}", Debug.showBreakPoints(f));
42 bp1 = Debug.setBreakPoint(f, 0, 8);
43 assertEquals("() {a=1;[B0]b=2}", Debug.showBreakPoints(f));
44 bp2 = Debug.setBreakPoint(f, 0, 4);
45 assertEquals("() {[B0]a=1;[B1]b=2}", Debug.showBreakPoints(f));
46 bp3 = Debug.setBreakPoint(f, 0, 11);
47 assertEquals("() {[B0]a=1;[B1]b=2[B2]}", Debug.showBreakPoints(f));
48 Debug.clearBreakPoint(bp1);
49 assertEquals("() {[B0]a=1;b=2[B1]}", Debug.showBreakPoints(f));
50 Debug.clearBreakPoint(bp2);
51 assertEquals("() {a=1;b=2[B0]}", Debug.showBreakPoints(f));
52 Debug.clearBreakPoint(bp3);
53 assertEquals("() {a=1;b=2}", Debug.showBreakPoints(f));
55 // The following test checks that the Debug.showBreakPoints(g) produces output
56 // like follows when changein breakpoints.
63 // Test set and clear breakpoint at the first possible location (line 0,
65 bp = Debug.setBreakPoint(g, 0, 0);
70 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
71 Debug.clearBreakPoint(bp);
76 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]") < 0);
78 // Second test set and clear breakpoints on lines 1, 2 and 3 (position = 0).
79 bp1 = Debug.setBreakPoint(g, 2, 0);
84 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]b=2;") > 0);
85 bp2 = Debug.setBreakPoint(g, 1, 0);
90 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
91 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]b=2;") > 0);
92 bp3 = Debug.setBreakPoint(g, 3, 0);
97 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
98 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]b=2;") > 0);
99 assertTrue(Debug.showBreakPoints(g).indexOf("[B2]}") > 0);
100 Debug.clearBreakPoint(bp1);
105 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
106 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]}") > 0);
107 assertTrue(Debug.showBreakPoints(g).indexOf("[B2]") < 0);
108 Debug.clearBreakPoint(bp2);
113 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]}") > 0);
114 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]") < 0);
115 Debug.clearBreakPoint(bp3);
120 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]") < 0);
123 // Tests for setting break points by script id and position.
124 function setBreakpointByPosition(f, position, opt_position_alignment)
126 var break_point = Debug.setBreakPointByScriptIdAndPosition(
127 Debug.findScript(f).id,
128 position + Debug.sourcePosition(f),
130 true, opt_position_alignment);
131 return break_point.number();
134 bp = setBreakpointByPosition(f, 0);
135 assertEquals("() {[B0]a=1;b=2}", Debug.showBreakPoints(f));
136 Debug.clearBreakPoint(bp);
137 assertEquals("() {a=1;b=2}", Debug.showBreakPoints(f));
138 bp1 = setBreakpointByPosition(f, 8);
139 assertEquals("() {a=1;[B0]b=2}", Debug.showBreakPoints(f));
140 bp2 = setBreakpointByPosition(f, 4);
141 assertEquals("() {[B0]a=1;[B1]b=2}", Debug.showBreakPoints(f));
142 bp3 = setBreakpointByPosition(f, 11);
143 assertEquals("() {[B0]a=1;[B1]b=2[B2]}", Debug.showBreakPoints(f));
144 Debug.clearBreakPoint(bp1);
145 assertEquals("() {[B0]a=1;b=2[B1]}", Debug.showBreakPoints(f));
146 Debug.clearBreakPoint(bp2);
147 assertEquals("() {a=1;b=2[B0]}", Debug.showBreakPoints(f));
148 Debug.clearBreakPoint(bp3);
149 assertEquals("() {a=1;b=2}", Debug.showBreakPoints(f));
151 bp = setBreakpointByPosition(g, 0);
156 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
157 Debug.clearBreakPoint(bp);
162 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]") < 0);
164 //Second test set and clear breakpoints on lines 1, 2 and 3 (column = 0).
165 bp1 = setBreakpointByPosition(g, 12);
170 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]b=2;") > 0);
171 bp2 = setBreakpointByPosition(g, 5);
176 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
177 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]b=2;") > 0);
178 bp3 = setBreakpointByPosition(g, 19);
183 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
184 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]b=2;") > 0);
185 assertTrue(Debug.showBreakPoints(g).indexOf("[B2]}") > 0);
186 Debug.clearBreakPoint(bp1);
191 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0);
192 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]}") > 0);
193 assertTrue(Debug.showBreakPoints(g).indexOf("[B2]") < 0);
194 Debug.clearBreakPoint(bp2);
199 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]}") > 0);
200 assertTrue(Debug.showBreakPoints(g).indexOf("[B1]") < 0);
201 Debug.clearBreakPoint(bp3);
206 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]") < 0);
208 // Tests for setting break points without statement aligment.
209 // (This may be sensitive to compiler break position map generation).
210 function h() {a=f(f2(1,2),f3())+f3();b=f3();}
215 [16, "f2(1,2),[B0]f3()"],
218 for(var i = 0; i < scenario.length; i++) {
219 bp1 = setBreakpointByPosition(h, scenario[i][0],
220 Debug.BreakPositionAlignment.BreakPosition);
221 assertTrue(Debug.showBreakPoints(h, undefined,
222 Debug.BreakPositionAlignment.BreakPosition).indexOf(scenario[i][1]) > 0);
223 Debug.clearBreakPoint(bp1);