blob: 6c1fceff317398e76798f1a1fe7f09f110dc76ab [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005// Flags: --expose-debug-as debug --turbo-filter=g --allow-natives-syntax
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006
7// Test that Debug::PrepareForBreakPoints can deal with turbofan code (g)
8// on the stack. Without deoptimization support, we will not be able to
9// replace optimized code for g by unoptimized code with debug break slots.
10// This would cause stepping to fail (V8 issue 3660).
11
12function f(x) {
13 g(x);
14 var a = 0; // Break 6
15 return a; // Break 7
16} // Break 8
17
18function g(x) {
19 if (x) h();
20 var a = 0; // Break 2
21 var b = 1; // Break 3
22 return a + b; // Break 4
23} // Break 5
24
25function h() {
26 debugger; // Break 0
27} // Break 1
28
29Debug = debug.Debug;
30var exception = null;
31var break_count = 0;
32
33function listener(event, exec_state, event_data, data) {
34 if (event != Debug.DebugEvent.Break) return;
35 try {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 exec_state.prepareStep(Debug.StepAction.StepNext);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040037 print(exec_state.frame(0).sourceLineText());
38 var match = exec_state.frame(0).sourceLineText().match(/Break (\d)/);
39 assertNotNull(match);
40 assertEquals(break_count++, parseInt(match[1]));
41 } catch (e) {
42 print(e + e.stack);
43 exception = e;
44 }
45}
46
47f(0);
48f(0);
49%OptimizeFunctionOnNextCall(g);
50
51Debug.setListener(listener);
52
53f(1);
54
55Debug.setListener(null); // Break 9
56assertNull(exception);
57assertEquals(10, break_count);