From b693516db4d59d5c0265822b8874dca69da8f9e1 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Sat, 28 May 2022 17:43:06 +0800 Subject: [PATCH] Descriptor: support disable debugger and runtime domain details: add disable method for debugger and runtime issue: https://gitee.com/openharmony/ark_js_runtime/issues/I59QMX Signed-off-by: wengchangcheng Change-Id: Iace48b02a2c5fc9b15c1fed94a67e95a4e857933 --- ecmascript/tooling/agent/debugger_impl.cpp | 17 +++++++++++++++++ ecmascript/tooling/agent/debugger_impl.h | 2 ++ ecmascript/tooling/agent/runtime_impl.cpp | 15 ++++++++++++--- ecmascript/tooling/agent/runtime_impl.h | 2 ++ ecmascript/tooling/base/pt_events.cpp | 1 - 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ecmascript/tooling/agent/debugger_impl.cpp b/ecmascript/tooling/agent/debugger_impl.cpp index 4b3347c940..da2718e684 100644 --- a/ecmascript/tooling/agent/debugger_impl.cpp +++ b/ecmascript/tooling/agent/debugger_impl.cpp @@ -27,6 +27,7 @@ DebuggerImpl::DispatcherImpl::DispatcherImpl(FrontEnd *frontend, std::unique_ptr : DispatcherBase(frontend), debugger_(std::move(debugger)) { dispatcherTable_["enable"] = &DebuggerImpl::DispatcherImpl::Enable; + dispatcherTable_["disable"] = &DebuggerImpl::DispatcherImpl::Disable; dispatcherTable_["evaluateOnCallFrame"] = &DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame; dispatcherTable_["getPossibleBreakpoints"] = &DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints; dispatcherTable_["getScriptSource"] = &DebuggerImpl::DispatcherImpl::GetScriptSource; @@ -69,6 +70,12 @@ void DebuggerImpl::DispatcherImpl::Enable(const DispatchRequest &request) SendResponse(request, response, std::move(result)); } +void DebuggerImpl::DispatcherImpl::Disable(const DispatchRequest &request) +{ + DispatchResponse response = debugger_->Disable(); + SendResponse(request, response, nullptr); +} + void DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame(const DispatchRequest &request) { std::unique_ptr params = @@ -226,6 +233,16 @@ DispatchResponse DebuggerImpl::Enable([[maybe_unused]] std::unique_ptr(backend_->GetEcmaVm()); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + backend_->NotifyAllScriptParsed(); + return DispatchResponse::Ok(); +} + +DispatchResponse DebuggerImpl::Disable() +{ + auto ecmaVm = const_cast(backend_->GetEcmaVm()); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(false); return DispatchResponse::Ok(); } diff --git a/ecmascript/tooling/agent/debugger_impl.h b/ecmascript/tooling/agent/debugger_impl.h index 35e6fcda0f..564aaf78f5 100644 --- a/ecmascript/tooling/agent/debugger_impl.h +++ b/ecmascript/tooling/agent/debugger_impl.h @@ -28,6 +28,7 @@ public: ~DebuggerImpl() = default; DispatchResponse Enable(std::unique_ptr params, UniqueDebuggerId *id); + DispatchResponse Disable(); DispatchResponse EvaluateOnCallFrame(std::unique_ptr params, std::unique_ptr *result); DispatchResponse GetPossibleBreakpoints(std::unique_ptr params, @@ -51,6 +52,7 @@ public: ~DispatcherImpl() override = default; void Dispatch(const DispatchRequest &request) override; void Enable(const DispatchRequest &request); + void Disable(const DispatchRequest &request); void EvaluateOnCallFrame(const DispatchRequest &request); void GetPossibleBreakpoints(const DispatchRequest &request); void GetScriptSource(const DispatchRequest &request); diff --git a/ecmascript/tooling/agent/runtime_impl.cpp b/ecmascript/tooling/agent/runtime_impl.cpp index 74f57a06a4..474c6cd820 100644 --- a/ecmascript/tooling/agent/runtime_impl.cpp +++ b/ecmascript/tooling/agent/runtime_impl.cpp @@ -23,6 +23,7 @@ RuntimeImpl::DispatcherImpl::DispatcherImpl(FrontEnd *frontend, std::unique_ptr< : DispatcherBase(frontend), runtime_(std::move(runtime)) { dispatcherTable_["enable"] = &RuntimeImpl::DispatcherImpl::Enable; + dispatcherTable_["disable"] = &RuntimeImpl::DispatcherImpl::Disable; dispatcherTable_["getProperties"] = &RuntimeImpl::DispatcherImpl::GetProperties; dispatcherTable_["runIfWaitingForDebugger"] = &RuntimeImpl::DispatcherImpl::RunIfWaitingForDebugger; dispatcherTable_["callFunctionOn"] = &RuntimeImpl::DispatcherImpl::CallFunctionOn; @@ -49,6 +50,12 @@ void RuntimeImpl::DispatcherImpl::Enable(const DispatchRequest &request) SendResponse(request, response, nullptr); } +void RuntimeImpl::DispatcherImpl::Disable(const DispatchRequest &request) +{ + DispatchResponse response = runtime_->Disable(); + SendResponse(request, response, nullptr); +} + void RuntimeImpl::DispatcherImpl::RunIfWaitingForDebugger(const DispatchRequest &request) { DispatchResponse response = runtime_->RunIfWaitingForDebugger(); @@ -111,9 +118,11 @@ void RuntimeImpl::DispatcherImpl::GetHeapUsage(const DispatchRequest &request) DispatchResponse RuntimeImpl::Enable() { - auto ecmaVm = const_cast(backend_->GetEcmaVm()); - ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); - backend_->NotifyAllScriptParsed(); + return DispatchResponse::Ok(); +} + +DispatchResponse RuntimeImpl::Disable() +{ return DispatchResponse::Ok(); } diff --git a/ecmascript/tooling/agent/runtime_impl.h b/ecmascript/tooling/agent/runtime_impl.h index c23264513d..1ca1f5c157 100644 --- a/ecmascript/tooling/agent/runtime_impl.h +++ b/ecmascript/tooling/agent/runtime_impl.h @@ -28,6 +28,7 @@ public: ~RuntimeImpl() = default; DispatchResponse Enable(); + DispatchResponse Disable(); DispatchResponse RunIfWaitingForDebugger(); DispatchResponse GetProperties( std::unique_ptr params, @@ -47,6 +48,7 @@ public: ~DispatcherImpl() override = default; void Dispatch(const DispatchRequest &request) override; + void Disable(const DispatchRequest &request); void Enable(const DispatchRequest &request); void RunIfWaitingForDebugger(const DispatchRequest &request); void GetProperties(const DispatchRequest &request); diff --git a/ecmascript/tooling/base/pt_events.cpp b/ecmascript/tooling/base/pt_events.cpp index 884a48c0e2..d5d113749f 100644 --- a/ecmascript/tooling/base/pt_events.cpp +++ b/ecmascript/tooling/base/pt_events.cpp @@ -732,7 +732,6 @@ std::unique_ptr AddHeapSnapshotChunk::Create(char* data, i return addHeapSnapshotChunk; } - std::unique_ptr AddHeapSnapshotChunk::Create(const EcmaVM *ecmaVm, const Local ¶ms) { -- Gitee