2
0

JsrtDebugEventObject.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "JsrtPch.h"
  6. #ifdef ENABLE_SCRIPT_DEBUGGING
  7. #include "JsrtDebugEventObject.h"
  8. #include "RuntimeDebugPch.h"
  9. #include "screrror.h" // For CompileScriptException
  10. JsrtDebugEventObject::JsrtDebugEventObject(Js::ScriptContext *scriptContext)
  11. {
  12. Assert(scriptContext != nullptr);
  13. this->scriptContext = scriptContext;
  14. this->eventDataObject = scriptContext->GetLibrary()->CreateObject();
  15. Assert(this->eventDataObject != nullptr);
  16. }
  17. JsrtDebugEventObject::~JsrtDebugEventObject()
  18. {
  19. this->eventDataObject = nullptr;
  20. this->scriptContext = nullptr;
  21. }
  22. Js::DynamicObject* JsrtDebugEventObject::GetEventDataObject()
  23. {
  24. return this->eventDataObject;
  25. }
  26. JsrtDebugDocumentManager::JsrtDebugDocumentManager(JsrtDebugManager* jsrtDebugManager) :
  27. breakpointDebugDocumentDictionary(nullptr)
  28. {
  29. Assert(jsrtDebugManager != nullptr);
  30. this->jsrtDebugManager = jsrtDebugManager;
  31. }
  32. JsrtDebugDocumentManager::~JsrtDebugDocumentManager()
  33. {
  34. if (this->breakpointDebugDocumentDictionary != nullptr)
  35. {
  36. AssertMsg(this->breakpointDebugDocumentDictionary->Count() == 0, "Should have cleared all entries by now?");
  37. Adelete(this->jsrtDebugManager->GetDebugObjectArena(), this->breakpointDebugDocumentDictionary);
  38. this->breakpointDebugDocumentDictionary = nullptr;
  39. }
  40. this->jsrtDebugManager = nullptr;
  41. }
  42. void JsrtDebugDocumentManager::AddDocument(UINT bpId, Js::DebugDocument * debugDocument)
  43. {
  44. BreakpointDebugDocumentDictionary* breakpointDebugDocumentDictionary = this->GetBreakpointDictionary();
  45. Assert(!breakpointDebugDocumentDictionary->ContainsKey(bpId));
  46. breakpointDebugDocumentDictionary->Add(bpId, debugDocument);
  47. }
  48. void JsrtDebugDocumentManager::ClearDebugDocument(Js::ScriptContext * scriptContext)
  49. {
  50. if (scriptContext != nullptr)
  51. {
  52. scriptContext->MapScript([&](Js::Utf8SourceInfo* sourceInfo)
  53. {
  54. if (sourceInfo->HasDebugDocument())
  55. {
  56. Js::DebugDocument* debugDocument = sourceInfo->GetDebugDocument();
  57. // Remove the debugdocument from breakpoint dictionary
  58. if (this->breakpointDebugDocumentDictionary != nullptr)
  59. {
  60. this->breakpointDebugDocumentDictionary->MapAndRemoveIf([&](JsUtil::SimpleDictionaryEntry<UINT, Js::DebugDocument *> keyValue)
  61. {
  62. if (keyValue.Value() != nullptr && keyValue.Value() == debugDocument)
  63. {
  64. return true;
  65. }
  66. return false;
  67. });
  68. }
  69. debugDocument->GetUtf8SourceInfo()->ClearDebugDocument();
  70. HeapDelete(debugDocument);
  71. debugDocument = nullptr;
  72. }
  73. });
  74. }
  75. }
  76. void JsrtDebugDocumentManager::ClearBreakpointDebugDocumentDictionary()
  77. {
  78. if (this->breakpointDebugDocumentDictionary != nullptr)
  79. {
  80. this->breakpointDebugDocumentDictionary->Clear();
  81. }
  82. }
  83. bool JsrtDebugDocumentManager::RemoveBreakpoint(UINT breakpointId)
  84. {
  85. if (this->breakpointDebugDocumentDictionary != nullptr)
  86. {
  87. BreakpointDebugDocumentDictionary* breakpointDebugDocumentDictionary = this->GetBreakpointDictionary();
  88. Js::DebugDocument* debugDocument = nullptr;
  89. if (breakpointDebugDocumentDictionary->TryGetValue(breakpointId, &debugDocument))
  90. {
  91. Js::StatementLocation statement;
  92. if (debugDocument->FindBPStatementLocation(breakpointId, &statement))
  93. {
  94. debugDocument->SetBreakPoint(statement, BREAKPOINT_DELETED);
  95. return true;
  96. }
  97. }
  98. }
  99. return false;
  100. }
  101. JsrtDebugDocumentManager::BreakpointDebugDocumentDictionary * JsrtDebugDocumentManager::GetBreakpointDictionary()
  102. {
  103. if (this->breakpointDebugDocumentDictionary == nullptr)
  104. {
  105. this->breakpointDebugDocumentDictionary = Anew(this->jsrtDebugManager->GetDebugObjectArena(), BreakpointDebugDocumentDictionary, this->jsrtDebugManager->GetDebugObjectArena(), 10);
  106. }
  107. return breakpointDebugDocumentDictionary;
  108. }
  109. #endif