From 27824111111a26f5750aad272b3ae98c04fbe8ab Mon Sep 17 00:00:00 2001 From: huangfeijie Date: Thu, 23 Dec 2021 10:30:13 +0800 Subject: [PATCH] bugfix in attach Signed-off-by: huangfeijie --- ecmascript/tooling/agent/js_backend.cpp | 20 ++++++++++---------- ecmascript/tooling/agent/js_backend.h | 1 + ecmascript/tooling/agent/runtime_impl.cpp | 1 + ecmascript/tooling/base/pt_events.cpp | 14 ++++++++++++++ ecmascript/tooling/base/pt_events.h | 2 ++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ecmascript/tooling/agent/js_backend.cpp b/ecmascript/tooling/agent/js_backend.cpp index 11f30e83bf..d25314ac22 100644 --- a/ecmascript/tooling/agent/js_backend.cpp +++ b/ecmascript/tooling/agent/js_backend.cpp @@ -105,6 +105,15 @@ void JSBackend::NotifyResume() frontend_->SendNotification(ecmaVm_, std::make_unique()); } +void JSBackend::NotifyAllScriptParsed() +{ + for (auto &script : scripts_) { + if (frontend_ != nullptr) { + frontend_->SendNotification(ecmaVm_, ScriptParsed::Create(script.second)); + } + } +} + bool JSBackend::NotifyScriptParsed(int32_t scriptId, const CString &fileName) { auto scriptFunc = []([[maybe_unused]] PtScript *script) -> bool { @@ -159,17 +168,8 @@ bool JSBackend::NotifyScriptParsed(int32_t scriptId, const CString &fileName) // Notify script parsed event std::unique_ptr script = std::make_unique(scriptId, fileName, url, source); - std::unique_ptr scriptParsed = std::make_unique(); - scriptParsed->SetScriptId(script->GetScriptId()) - .SetUrl(script->GetUrl()) - .SetStartLine(0) - .SetStartColumn(0) - .SetEndLine(script->GetEndLine()) - .SetEndColumn(0) - .SetExecutionContextId(0) - .SetHash(script->GetHash()); if (frontend_ != nullptr) { - frontend_->SendNotification(ecmaVm_, std::move(scriptParsed)); + frontend_->SendNotification(ecmaVm_, ScriptParsed::Create(script)); } // Store parsed script in map diff --git a/ecmascript/tooling/agent/js_backend.h b/ecmascript/tooling/agent/js_backend.h index 2cdff1cff7..add97b2059 100644 --- a/ecmascript/tooling/agent/js_backend.h +++ b/ecmascript/tooling/agent/js_backend.h @@ -36,6 +36,7 @@ public: void WaitForDebugger(); void NotifyPaused(std::optional location, PauseReason reason); void NotifyResume(); + void NotifyAllScriptParsed(); bool NotifyScriptParsed(int32_t scriptId, const CString &fileName); bool StepComplete(const PtLocation &location); diff --git a/ecmascript/tooling/agent/runtime_impl.cpp b/ecmascript/tooling/agent/runtime_impl.cpp index 8d3d3758c1..75b7c9809a 100644 --- a/ecmascript/tooling/agent/runtime_impl.cpp +++ b/ecmascript/tooling/agent/runtime_impl.cpp @@ -80,6 +80,7 @@ void RuntimeImpl::DispatcherImpl::GetProperties(const DispatchRequest &request) DispatchResponse RuntimeImpl::Enable() { Runtime::GetCurrent()->SetDebugMode(true); + backend_->NotifyAllScriptParsed(); return DispatchResponse::Ok(); } diff --git a/ecmascript/tooling/base/pt_events.cpp b/ecmascript/tooling/base/pt_events.cpp index 6b15c56e8e..0bc303cca1 100644 --- a/ecmascript/tooling/base/pt_events.cpp +++ b/ecmascript/tooling/base/pt_events.cpp @@ -449,6 +449,20 @@ Local ScriptFailedToParse::ToObject(const EcmaVM *ecmaVm) return object; } +std::unique_ptr ScriptParsed::Create(const std::unique_ptr &script) +{ + std::unique_ptr scriptParsed = std::make_unique(); + scriptParsed->SetScriptId(script->GetScriptId()) + .SetUrl(script->GetUrl()) + .SetStartLine(0) + .SetStartColumn(0) + .SetEndLine(script->GetEndLine()) + .SetEndColumn(0) + .SetExecutionContextId(0) + .SetHash(script->GetHash()); + return scriptParsed; +} + std::unique_ptr ScriptParsed::Create(const EcmaVM *ecmaVm, const Local ¶ms) { if (params.IsEmpty()) { diff --git a/ecmascript/tooling/base/pt_events.h b/ecmascript/tooling/base/pt_events.h index f60de50e9b..0ef5cf4177 100644 --- a/ecmascript/tooling/base/pt_events.h +++ b/ecmascript/tooling/base/pt_events.h @@ -20,6 +20,7 @@ #include #include "libpandabase/macros.h" +#include "ecmascript/tooling/base/pt_script.h" #include "ecmascript/tooling/base/pt_types.h" #include "ecmascript/tooling/dispatcher.h" #include "ecmascript/mem/c_containers.h" @@ -474,6 +475,7 @@ class ScriptParsed final : public PtBaseEvents { public: ScriptParsed() = default; ~ScriptParsed() override = default; + static std::unique_ptr Create(const std::unique_ptr &script); static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); Local ToObject(const EcmaVM *ecmaVm) override; -- Gitee