DebugInformation.cs 2.7 KB

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