DebugInformation.cs 2.5 KB

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