1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2008 the V8 project authors. All rights reserved. 2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without 3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are 4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met: 5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions of source code must retain the above copyright 7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// notice, this list of conditions and the following disclaimer. 8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions in binary form must reproduce the above 9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// copyright notice, this list of conditions and the following 10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// disclaimer in the documentation and/or other materials provided 11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// with the distribution. 12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Neither the name of Google Inc. nor the names of its 13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// contributors may be used to endorse or promote products derived 14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// from this software without specific prior written permission. 15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Flags: --expose-debug-as debug 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Get the Debug object exposed from the debug context global object. 30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug = debug.Debug 31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f() {a=1;b=2}; 33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction g() { 34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block a=1; 35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block b=2; 36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp = Debug.setBreakPoint(f, 0, 0); 39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {[B0]a=1;b=2}", Debug.showBreakPoints(f)); 40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp); 41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {a=1;b=2}", Debug.showBreakPoints(f)); 42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp1 = Debug.setBreakPoint(f, 0, 8); 43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {a=1;[B0]b=2}", Debug.showBreakPoints(f)); 44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp2 = Debug.setBreakPoint(f, 0, 4); 45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {[B0]a=1;[B1]b=2}", Debug.showBreakPoints(f)); 46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp3 = Debug.setBreakPoint(f, 0, 12); 47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {[B0]a=1;[B1]b=2}[B2]", Debug.showBreakPoints(f)); 48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp1); 49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {[B0]a=1;b=2}[B1]", Debug.showBreakPoints(f)); 50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp2); 51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {a=1;b=2}[B0]", Debug.showBreakPoints(f)); 52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp3); 53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals("() {a=1;b=2}", Debug.showBreakPoints(f)); 54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The following test checks that the Debug.showBreakPoints(g) produces output 56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// like follows when changein breakpoints. 57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [BX]a=1; 60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [BX]b=2; 61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// }[BX] 62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Test set and clear breakpoint at the first possible location (line 0, 64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// position 0). 65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp = Debug.setBreakPoint(g, 0, 0); 66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [B0]a=1; 68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// b=2; 69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// } 70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0); 71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp); 72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a=1; 74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// b=2; 75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// } 76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B0]") < 0); 77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Second test set and clear breakpoints on lines 1, 2 and 3 (position = 0). 79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp1 = Debug.setBreakPoint(g, 2, 0); 80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a=1; 82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [B0]b=2; 83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// } 84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B0]b=2;") > 0); 85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp2 = Debug.setBreakPoint(g, 1, 0); 86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [B0]a=1; 88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [B1]b=2; 89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// } 90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0); 91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B1]b=2;") > 0); 92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbp3 = Debug.setBreakPoint(g, 3, 0); 93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [B0]a=1; 95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [B1]b=2; 96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// }[B2] 97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0); 98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B1]b=2;") > 0); 99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("}[B2]") > 0); 100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp1); 101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// [B0]a=1; 103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// b=2; 104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// }[B1] 105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B0]a=1;") > 0); 106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("}[B1]") > 0); 107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B2]") < 0); 108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp2); 109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a=1; 111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// b=2; 112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// }[B0] 113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("}[B0]") > 0); 114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B1]") < 0); 115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDebug.clearBreakPoint(bp3); 116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function g() { 117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a=1; 118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// b=2; 119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// } 120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(Debug.showBreakPoints(g).indexOf("[B0]") < 0); 121