1394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Copyright 2011 the V8 project authors. All rights reserved.
2394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Redistribution and use in source and binary forms, with or without
3394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// modification, are permitted provided that the following conditions are
4394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// met:
5394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//
6394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//     * Redistributions of source code must retain the above copyright
7394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//       notice, this list of conditions and the following disclaimer.
8394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//     * Redistributions in binary form must reproduce the above
9394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//       copyright notice, this list of conditions and the following
10394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//       disclaimer in the documentation and/or other materials provided
11394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//       with the distribution.
12394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//     * Neither the name of Google Inc. nor the names of its
13394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//       contributors may be used to endorse or promote products derived
14394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//       from this software without specific prior written permission.
15394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//
16394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
28394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Flags: --expose-debug-as debug
29394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
30394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// This test tests that full code compiled without debug break slots
31394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// is recompiled with debug break slots when debugging is started.
32394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
33394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Get the Debug object exposed from the debug context global object.
34394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comDebug = debug.Debug
35394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
36394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comvar bp;
37394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comvar done = false;
38394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comvar step_count = 0;
39394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comvar set_bp = false
40394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
41394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Debug event listener which steps until the global variable done is true.
42394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comfunction listener(event, exec_state, event_data, data) {
43394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  if (event == Debug.DebugEvent.Break) {
44394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    if (!done) exec_state.prepareStep(Debug.StepAction.StepNext);
45394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    step_count++;
46394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  }
47394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com};
48394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
49394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Set the global variables state to prpare the stepping test.
50394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comfunction prepare_step_test() {
51394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  done = false;
52394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  step_count = 0;
53394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com}
54394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
55394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Test function to step through.
56394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comfunction f() {
57394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  var a = 0;
58394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  if (set_bp) { bp = Debug.setBreakPoint(f, 3); }
59394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  var i = 1;
60394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  var j = 2;
61394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  done = true;
62394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com};
63394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
64394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comprepare_step_test();
65394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comf();
66394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
67394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Add the debug event listener.
68394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comDebug.setListener(listener);
69394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
70394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Make f set a breakpoint with an activation on the stack.
71394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comprepare_step_test();
72394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comset_bp = true;
73394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comf();
74394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// TODO(1782): Fix issue to bring back this assert.
75394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com//assertEquals(4, step_count);
76394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comDebug.clearBreakPoint(bp);
77394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
78394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Set a breakpoint on the first var statement (line 1).
79394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comset_bp = false;
80394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.combp = Debug.setBreakPoint(f, 3);
81394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
82394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Step through the function ensuring that the var statements are hit as well.
83394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comprepare_step_test();
84394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comf();
85ecb9dd69014d1d8aad1a08bd8b593fbf94107324svenpanne@chromium.orgassertEquals(4, step_count);
86394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
87394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Clear the breakpoint and check that no stepping happens.
88394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comDebug.clearBreakPoint(bp);
89394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comprepare_step_test();
90394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comf();
91394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comassertEquals(0, step_count);
92394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
93394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Get rid of the debug event listener.
94394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comDebug.setListener(null);
95