DebugInformation.cs 2.8 KB

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