DebugManager.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. struct InterpreterHaltState;
  9. class DebugManager
  10. {
  11. friend class RecyclableObjectDisplay;
  12. friend class RecyclableArrayWalker;
  13. template <typename TData> friend class RecyclableCollectionObjectWalker;
  14. template <typename TData> friend class RecyclableCollectionObjectDisplay;
  15. friend class RecyclableKeyValueDisplay;
  16. friend class ProbeContainer;
  17. private:
  18. InterpreterHaltState* pCurrentInterpreterLocation; // NULL if not Halted at a Probe
  19. DWORD_PTR secondaryCurrentSourceContext; // For resolving ambiguity among generated files, e.g. eval, anonymous, etc.
  20. uint32 debugSessionNumber; // A unique number, which will be used to sync all probecontainer when on break
  21. RecyclerRootPtr<Js::DynamicObject> pConsoleScope;
  22. ThreadContext* pThreadContext;
  23. bool isAtDispatchHalt;
  24. PageAllocator diagnosticPageAllocator;
  25. int evalCodeRegistrationCount;
  26. int anonymousCodeRegistrationCount;
  27. int jscriptBlockRegistrationCount;
  28. bool isDebuggerAttaching;
  29. DebuggingFlags debuggingFlags;
  30. UINT nextBreakPointId;
  31. DWORD localsDisplayFlags;
  32. void * dispatchHaltFrameAddress;
  33. public:
  34. StepController stepController;
  35. AsyncBreakController asyncBreakController;
  36. PropertyId mutationNewValuePid; // Holds the property id of $newValue$ property for object mutation breakpoint
  37. PropertyId mutationPropertyNamePid; // Holds the property id of $propertyName$ property for object mutation breakpoint
  38. PropertyId mutationTypePid; // Holds the property id of $mutationType$ property for object mutation breakpoint
  39. DebugManager(ThreadContext* _pThreadContext, AllocationPolicyManager * allocationPolicyManager);
  40. ~DebugManager();
  41. void Close();
  42. DebuggingFlags* GetDebuggingFlags();
  43. intptr_t GetDebuggingFlagsAddr() const;
  44. bool IsAtDispatchHalt() const { return this->isAtDispatchHalt; }
  45. void SetDispatchHalt(bool set) { this->isAtDispatchHalt = set; }
  46. ReferencedArenaAdapter* GetDiagnosticArena();
  47. DWORD_PTR AllocateSecondaryHostSourceContext();
  48. void SetCurrentInterpreterLocation(InterpreterHaltState* pHaltState);
  49. void UnsetCurrentInterpreterLocation();
  50. bool IsMatchTopFrameStackAddress(DiagStackFrame* frame) const;
  51. uint32 GetDebugSessionNumber() const { return debugSessionNumber; }
  52. #ifdef ENABLE_MUTATION_BREAKPOINT
  53. MutationBreakpoint* GetActiveMutationBreakpoint() const;
  54. #endif
  55. DynamicObject* GetConsoleScope(ScriptContext* scriptContext);
  56. FrameDisplay *GetFrameDisplay(ScriptContext* scriptContext, DynamicObject* scopeAtZero, DynamicObject* scopeAtOne);
  57. void UpdateConsoleScope(DynamicObject* copyFromScope, ScriptContext* scriptContext);
  58. PageAllocator * GetDiagnosticPageAllocator() { return &this->diagnosticPageAllocator; }
  59. void SetDispatchHaltFrameAddress(void * returnAddress) { this->dispatchHaltFrameAddress = returnAddress; }
  60. DWORD_PTR GetDispatchHaltFrameAddress() const { return (DWORD_PTR)this->dispatchHaltFrameAddress; }
  61. #if DBG
  62. void ValidateDebugAPICall();
  63. #endif
  64. void SetDebuggerAttaching(bool attaching) { this->isDebuggerAttaching = attaching; }
  65. bool IsDebuggerAttaching() const { return this->isDebuggerAttaching; }
  66. enum DynamicFunctionType
  67. {
  68. DFT_EvalCode,
  69. DFT_AnonymousCode,
  70. DFT_JScriptBlock
  71. };
  72. int GetNextId(DynamicFunctionType eFunc)
  73. {
  74. switch (eFunc)
  75. {
  76. case DFT_EvalCode: return ++evalCodeRegistrationCount;
  77. case DFT_AnonymousCode: return ++anonymousCodeRegistrationCount;
  78. case DFT_JScriptBlock: return ++jscriptBlockRegistrationCount;
  79. }
  80. return -1;
  81. }
  82. UINT GetNextBreakpointId()
  83. {
  84. return ++nextBreakPointId;
  85. }
  86. enum LocalsDisplayFlags
  87. {
  88. LocalsDisplayFlags_None = 0x0,
  89. LocalsDisplayFlags_NoGroupMethods = 0x1
  90. };
  91. void SetLocalsDisplayFlags(LocalsDisplayFlags localsDisplayFlags)
  92. {
  93. this->localsDisplayFlags |= localsDisplayFlags;
  94. }
  95. bool IsLocalsDisplayFlagsSet(LocalsDisplayFlags localsDisplayFlags)
  96. {
  97. return (this->localsDisplayFlags & localsDisplayFlags) == (DWORD)localsDisplayFlags;
  98. }
  99. };
  100. }
  101. class AutoSetDispatchHaltFlag
  102. {
  103. public:
  104. AutoSetDispatchHaltFlag(Js::ScriptContext *scriptContext, ThreadContext *threadContext);
  105. ~AutoSetDispatchHaltFlag();
  106. private:
  107. // Primary reason for caching both because once we break to debugger our engine is open for re-entrancy. That means the
  108. // connection to scriptcontet to threadcontext can go away (imagine the GC is called when we are broken)
  109. Js::ScriptContext * m_scriptContext;
  110. ThreadContext * m_threadContext;
  111. };