DiagStackFrame.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Js
  7. {
  8. class DiagNativeStackFrame;
  9. //
  10. // Unified stack frame used by debugger (F12, inside VS)
  11. // -- interpreter or native stack frame.
  12. //
  13. class DiagStackFrame
  14. {
  15. public:
  16. virtual ~DiagStackFrame() {}
  17. virtual JavascriptFunction* GetJavascriptFunction() = 0;
  18. virtual int GetByteCodeOffset() = 0;
  19. virtual DWORD_PTR GetStackAddress() = 0;
  20. virtual Var GetRegValue(RegSlot slotId, bool allowTemp = false) = 0;
  21. virtual Var GetNonVarRegValue(RegSlot slotId) = 0;
  22. virtual void SetRegValue(RegSlot slotId, Var value) = 0;
  23. virtual Var GetArgumentsObject() = 0;
  24. virtual Var CreateHeapArguments() = 0;
  25. virtual ScriptContext* GetScriptContext();
  26. virtual PCWSTR GetDisplayName();
  27. virtual bool IsInterpreterFrame();
  28. virtual InterpreterStackFrame* AsInterpreterFrame();
  29. virtual ArenaAllocator * GetArena();
  30. virtual FrameDisplay * GetFrameDisplay();
  31. virtual Var GetScopeObjectFromFrameDisplay(uint index);
  32. virtual Var GetRootObject();
  33. virtual Var GetInnerScopeFromRegSlot(RegSlot location);
  34. bool IsTopFrame();
  35. void SetIsTopFrame();
  36. ScriptFunction* GetScriptFunction();
  37. FunctionBody* GetFunction();
  38. BOOL IsStrictMode();
  39. BOOL IsThisAvailable();
  40. Js::Var GetThisFromFrame(Js::IDiagObjectAddress ** ppOutAddress, Js::IDiagObjectModelWalkerBase * localsWalker = nullptr);
  41. // This function will try to populate obj and address field of the ResolvedObject.
  42. void TryFetchValueAndAddress(const char16 *source, int sourceLength, Js::ResolvedObject * pObj);
  43. Js::ScriptFunction* TryGetFunctionForEval(Js::ScriptContext* scriptContext, const char16 *source, int sourceLength, BOOL isLibraryCode = FALSE);
  44. void EvaluateImmediate(const char16 *source, int sourceLength, BOOL isLibraryCode, Js::ResolvedObject * pObj);
  45. Js::Var DoEval(Js::ScriptFunction* pfuncScript);
  46. protected:
  47. DiagStackFrame();
  48. private:
  49. bool isTopFrame;
  50. };
  51. class DiagInterpreterStackFrame : public DiagStackFrame
  52. {
  53. InterpreterStackFrame* m_interpreterFrame;
  54. public:
  55. DiagInterpreterStackFrame(InterpreterStackFrame* frame);
  56. virtual JavascriptFunction* GetJavascriptFunction() override;
  57. virtual ScriptContext* GetScriptContext() override;
  58. virtual int GetByteCodeOffset() override;
  59. virtual DWORD_PTR GetStackAddress() override;
  60. virtual bool IsInterpreterFrame() override;
  61. virtual InterpreterStackFrame* AsInterpreterFrame() override;
  62. virtual Var GetRegValue(RegSlot slotId, bool allowTemp = false) override;
  63. virtual Var GetNonVarRegValue(RegSlot slotId) override;
  64. virtual void SetRegValue(RegSlot slotId, Var value) override;
  65. virtual Var GetArgumentsObject() override;
  66. virtual Var CreateHeapArguments() override;
  67. virtual FrameDisplay * GetFrameDisplay() override;
  68. virtual Var GetInnerScopeFromRegSlot(RegSlot location) override;
  69. };
  70. #if ENABLE_NATIVE_CODEGEN
  71. class DiagNativeStackFrame : public DiagStackFrame
  72. {
  73. ScriptFunction* m_function;
  74. int m_byteCodeOffset;
  75. void* m_stackAddr;
  76. int32 m_localVarSlotsOffset; // the offset on the native stack frame where the locals are residing.
  77. int32 m_localVarChangedOffset; // The offset which stores if any locals is changed from the debugger.
  78. static const int32 InvalidOffset = -1;
  79. public:
  80. DiagNativeStackFrame(ScriptFunction* function, int byteCodeOffset, void* stackAddr, void *codeAddr);
  81. virtual JavascriptFunction* GetJavascriptFunction() override;
  82. virtual ScriptContext* GetScriptContext() override;
  83. virtual int GetByteCodeOffset() override;
  84. virtual DWORD_PTR GetStackAddress() override;
  85. virtual Var GetRegValue(RegSlot slotId, bool allowTemp = false) override;
  86. virtual Var GetNonVarRegValue(RegSlot slotId) override;
  87. virtual void SetRegValue(RegSlot slotId, Var value) override;
  88. virtual Var GetArgumentsObject() override;
  89. virtual Var CreateHeapArguments() override;
  90. private:
  91. Var * GetSlotOffsetLocation(RegSlot slotId, bool allowTemp = false);
  92. };
  93. #endif
  94. class DiagRuntimeStackFrame : public DiagStackFrame
  95. {
  96. JavascriptFunction* m_function;
  97. PCWSTR m_displayName;
  98. void* m_stackAddr;
  99. public:
  100. DiagRuntimeStackFrame(JavascriptFunction* function, PCWSTR displayName, void* stackAddr);
  101. virtual JavascriptFunction* GetJavascriptFunction() override;
  102. virtual int GetByteCodeOffset() override;
  103. virtual DWORD_PTR GetStackAddress() override;
  104. virtual Var GetRegValue(RegSlot slotId, bool allowTemp = false) override;
  105. virtual Var GetNonVarRegValue(RegSlot slotId) override;
  106. virtual void SetRegValue(RegSlot slotId, Var value) override;
  107. virtual Var GetArgumentsObject() override;
  108. virtual Var CreateHeapArguments() override;
  109. virtual PCWSTR GetDisplayName() override;
  110. };
  111. }