DebugContext.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. class HostDebugContext
  7. {
  8. public:
  9. HostDebugContext(Js::ScriptContext* inScriptContext) { this->scriptContext = inScriptContext; }
  10. virtual void Delete() = 0;
  11. virtual DWORD_PTR GetHostSourceContext(Js::Utf8SourceInfo * sourceInfo) = 0;
  12. virtual HRESULT SetThreadDescription(__in LPCWSTR url) = 0;
  13. virtual HRESULT DbgRegisterFunction(Js::ScriptContext * scriptContext, Js::FunctionBody * functionBody, DWORD_PTR dwDebugSourceContext, LPCWSTR title) = 0;
  14. virtual void ReParentToCaller(Js::Utf8SourceInfo* sourceInfo) = 0;
  15. virtual void SortMembersList(JsUtil::List<Js::DebuggerPropertyDisplayInfo *, ArenaAllocator> * pMembersList, Js::ScriptContext* scriptContext) {/*Do nothing*/}
  16. Js::ScriptContext* GetScriptContext() { return scriptContext; }
  17. private:
  18. Js::ScriptContext* scriptContext;
  19. };
  20. namespace Js
  21. {
  22. // Represents the different modes that the debugger can be placed into.
  23. enum DebuggerMode : unsigned int
  24. {
  25. // The debugger is not running so the engine can be running
  26. // in JITed mode.
  27. NotDebugging,
  28. // The debugger is not running but PDM has been created and
  29. // source rundown was performed to register script documents.
  30. SourceRundown,
  31. // The debugger is running which means that the engine is
  32. // running in interpreted mode.
  33. Debugging,
  34. };
  35. class DebugContext
  36. {
  37. public:
  38. DebugContext(Js::ScriptContext * scriptContext);
  39. ~DebugContext();
  40. void Initialize();
  41. HRESULT RundownSourcesAndReparse(bool shouldPerformSourceRundown, bool shouldReparseFunctions);
  42. void RegisterFunction(Js::ParseableFunctionInfo * func, LPCWSTR title);
  43. bool IsClosed() const { return this->isClosed; };
  44. bool IsSelfOrScriptContextClosed() const;
  45. void Close();
  46. void SetHostDebugContext(HostDebugContext * hostDebugContext);
  47. void SetDebuggerMode(DebuggerMode mode);
  48. #if DBG
  49. DebuggerMode GetDebuggerMode() const { return this->debuggerMode; }
  50. #endif
  51. bool IsDebugContextInNonDebugMode() const { return this->debuggerMode == DebuggerMode::NotDebugging; }
  52. bool IsDebugContextInDebugMode() const { return this->debuggerMode == DebuggerMode::Debugging; }
  53. bool IsDebugContextInSourceRundownMode() const { return this->debuggerMode == DebuggerMode::SourceRundown; }
  54. bool IsDebugContextInSourceRundownOrDebugMode() const { return IsDebugContextInSourceRundownMode() || IsDebugContextInDebugMode(); }
  55. bool IsDebuggerRecording() const { return this->isDebuggerRecording; }
  56. void SetIsDebuggerRecording(bool isDebuggerRecording) { this->isDebuggerRecording = isDebuggerRecording; }
  57. ProbeContainer* GetProbeContainer() const { return this->diagProbesContainer; }
  58. HostDebugContext * GetHostDebugContext() const { return this->hostDebugContext; }
  59. bool GetIsReparsingSource() const { return this->isReparsingSource; }
  60. private:
  61. ScriptContext * scriptContext;
  62. HostDebugContext* hostDebugContext;
  63. ProbeContainer* diagProbesContainer;
  64. DebuggerMode debuggerMode;
  65. bool isClosed : 1;
  66. bool isReparsingSource : 1;
  67. bool isDebuggerRecording : 1;
  68. // Private Functions
  69. void WalkAndAddUtf8SourceInfo(Js::Utf8SourceInfo* sourceInfo, JsUtil::List<Js::Utf8SourceInfo *, Recycler, false, Js::CopyRemovePolicy, RecyclerPointerComparer> *utf8SourceInfoList);
  70. bool CanRegisterFunction() const;
  71. void RegisterFunction(Js::ParseableFunctionInfo * func, DWORD_PTR dwDebugSourceContext, LPCWSTR title);
  72. void RegisterFunction(Js::FunctionBody * functionBody, DWORD_PTR dwDebugSourceContext, LPCWSTR title);
  73. template<class TMapFunction>
  74. void MapUTF8SourceInfoUntil(TMapFunction map);
  75. };
  76. }