DebugInformation.cs 2.7 KB

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