DebugInformation.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Esprima;
  2. using Esprima.Ast;
  3. using Jint.Native;
  4. namespace Jint.Runtime.Debugger
  5. {
  6. public sealed class DebugInformation : EventArgs
  7. {
  8. private readonly Engine _engine;
  9. private readonly Location _currentLocation;
  10. private readonly JsValue? _returnValue;
  11. private DebugCallStack? _callStack;
  12. internal DebugInformation(
  13. Engine engine,
  14. Node? currentNode,
  15. Location currentLocation,
  16. JsValue? returnValue,
  17. long currentMemoryUsage,
  18. PauseType pauseType,
  19. BreakPoint? breakPoint)
  20. {
  21. _engine = engine;
  22. CurrentNode = currentNode;
  23. _currentLocation = currentLocation;
  24. _returnValue = returnValue;
  25. CurrentMemoryUsage = currentMemoryUsage;
  26. PauseType = pauseType;
  27. BreakPoint = breakPoint;
  28. }
  29. /// <summary>
  30. /// Indicates the type of pause that resulted in this DebugInformation being generated.
  31. /// </summary>
  32. public PauseType PauseType { get; }
  33. /// <summary>
  34. /// Breakpoint at the current location. This will be set even if the pause wasn't caused by the breakpoint.
  35. /// </summary>
  36. public BreakPoint? BreakPoint { get; }
  37. /// <summary>
  38. /// The current call stack.
  39. /// </summary>
  40. /// <remarks>This will always include at least a call frame for the global environment.</remarks>
  41. public DebugCallStack CallStack =>
  42. _callStack ??= new DebugCallStack(_engine, _currentLocation, _engine.CallStack, _returnValue);
  43. /// <summary>
  44. /// The AST Node that will be executed on next step.
  45. /// Note that this will be null when execution is at a return point.
  46. /// </summary>
  47. public Node? CurrentNode { get; }
  48. /// <summary>
  49. /// The current source Location.
  50. /// For return points, this starts and ends at the end of the function body.
  51. /// </summary>
  52. public Location Location => CurrentCallFrame.Location;
  53. /// <summary>
  54. /// Not implemented. Will always return 0.
  55. /// </summary>
  56. public long CurrentMemoryUsage { get; }
  57. /// <summary>
  58. /// The currently executing call frame.
  59. /// </summary>
  60. public CallFrame CurrentCallFrame => CallStack[0];
  61. /// <summary>
  62. /// The scope chain of the currently executing call frame.
  63. /// </summary>
  64. public DebugScopes CurrentScopeChain => CurrentCallFrame.ScopeChain;
  65. /// <summary>
  66. /// The return value of the currently executing call frame.
  67. /// This is null if execution is not at a return point.
  68. /// </summary>
  69. public JsValue? ReturnValue => CurrentCallFrame.ReturnValue;
  70. }
  71. }