blob: ed68c97df858b4ded6c0a07b448cb0536f5f30a4 [file] [log] [blame]
Ben Murdoch589d6972011-11-30 16:04:58 +00001// Copyright 2011 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
4// met:
5//
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.
15//
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.
27
28// Flags: --expose-debug-as debug
29// Get the Debug object exposed from the debug context global object.
30Debug = debug.Debug
31var breaks = 0;
32
33function sendCommand(state, cmd) {
34 // Get the debug command processor in paused state.
35 var dcp = state.debugCommandProcessor(false);
36 var request = JSON.stringify(cmd);
37 var response = dcp.processDebugJSONRequest(request);
38}
39
40function listener(event, exec_state, event_data, data) {
41 try {
42 if (event == Debug.DebugEvent.Break) {
43 var line = event_data.sourceLineText();
44 print('break: ' + line);
45
46 assertEquals(-1, line.indexOf('NOBREAK'),
47 "should not break on unexpected lines")
48 assertEquals('BREAK ' + breaks, line.substr(-7));
49 breaks++;
50 sendCommand(exec_state, {
51 seq: 0,
52 type: "request",
53 command: "continue",
54 arguments: { stepaction: "next" }
55 });
56 }
57 } catch (e) {
58 print(e);
59 }
60}
61
62// Add the debug event listener.
63Debug.setListener(listener);
64
65function a(f) {
66 if (f) { // NOBREAK: should not break here!
67 try {
68 f();
69 } catch(e) {
70 }
71 }
72} // BREAK 2
73
74function b() {
75 c(); // BREAK 0
76} // BREAK 1
77
78function c() {
79 a();
80}
81
82// Set a break point and call to invoke the debug event listener.
83Debug.setBreakPoint(b, 0, 0);
84a(b);
85// BREAK 3