debug-break-mixed-stack.js 1.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


Debug = debug.Debug

var exception = null;
var frame_depth = 10;

function listener(event, exec_state, event_data, data) {
  if (event != Debug.DebugEvent.Break) return;
  try {
    assertEquals(frame_depth, exec_state.frameCount());
    assertTrue(/\/\/ Break$/.test(exec_state.frame(0).sourceLineText()));
    assertEquals(12 - frame_depth, exec_state.frame(0).evaluate("x").value());
    frame_depth--;
  } catch (e) {
    exception = e;
    print(e + e.stack);
  }
}

function ChooseCode(f, x) {
  if (x == 1) {
    Debug.setBreakPoint(factorial, 4);
  }
  switch (x % 2) {
    case 0:
      %BaselineFunctionOnNextCall(f);
      break;
    case 1:
      %InterpretFunctionOnNextCall(f);
      break;
  }
}

function factorial(x) {
  ChooseCode(factorial, x);
  if (x == 1) return 1;
  var factor = factorial(x - 1);
  return x * factor;  // Break
}

Debug.setListener(listener);

assertEquals(3628800, factorial(10));

Debug.setListener(null);
assertNull(exception);
assertEquals(1, frame_depth);