From 37eea576c8a33168765623d6aa429c9fbbe2a70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=AE?= Date: Fri, 31 Mar 2023 14:51:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=BD=92=E4=B8=80=E5=8C=96=E3=80=91JS?= =?UTF-8?q?Environment=E6=8F=90=E4=BE=9BDebug=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨亮 Change-Id: I48dd901b45fff1c0158bf1eaac6632299d81b4a4 --- frameworks/native/runtime/js_runtime.cpp | 23 ++++++++++--------- .../inner_api/runtime/include/js_runtime.h | 2 ++ .../js_environment/src/js_environment.cpp | 12 ++++++++++ .../interfaces/inner_api/js_environment.h | 4 ++++ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 99a5ebf2f1..5957887d4b 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -242,27 +242,28 @@ void JsRuntime::StartDebugMode(bool needBreakPoint) return; } - auto vm = GetEcmaVm(); - CHECK_POINTER(vm); - // Set instance id to tid after the first instance. if (JsRuntime::hasInstance.exchange(true, std::memory_order_relaxed)) { instanceId_ = static_cast(gettid()); } HILOG_INFO("Ark VM is starting debug mode [%{public}s]", needBreakPoint ? "break" : "normal"); - - HdcRegister::Get().StartHdcRegister(bundleName_); - ConnectServerManager::Get().StartConnectServer(bundleName_); - ConnectServerManager::Get().AddInstance(instanceId_); - StartDebuggerInWorkerModule(); - auto debuggerPostTask = [eventHandler = eventHandler_](std::function&& task) { eventHandler->PostTask(task); }; - panda::JSNApi::StartDebugger(ARK_DEBUGGER_LIB_PATH, vm, needBreakPoint, instanceId_, debuggerPostTask); - debugMode_ = true; + debugMode_ = StartDebugMode(bundleName_, needBreakPoint, instanceId_, debuggerPostTask); +} + +bool JsRuntime::StartDebugMode(const std::string& bundleName, bool needBreakPoint, uint32_t instanceId, + const DebuggerPostTask& debuggerPostTask) +{ + CHECK_POINTER_AND_RETURN(jsEnv_, false); + HdcRegister::Get().StartHdcRegister(bundleName); + ConnectServerManager::Get().StartConnectServer(bundleName); + ConnectServerManager::Get().AddInstance(instanceId); + StartDebuggerInWorkerModule(); + return jsEnv_->StartDebugger(ARK_DEBUGGER_LIB_PATH, needBreakPoint, instanceId, debuggerPostTask); } bool JsRuntime::GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector& buffer) diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 0342517a08..ba88648f3d 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -135,6 +135,8 @@ private: void InitSourceMap(const Options& options); bool InitLoop(const std::shared_ptr& eventRunner); inline bool IsUseAbilityRuntime(const Options& options) const; + bool StartDebugMode(const std::string& bundleName, bool needBreakPoint, uint32_t instanceId, + const DebuggerPostTask& debuggerPostTask = {}); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/js_environment/frameworks/js_environment/src/js_environment.cpp b/js_environment/frameworks/js_environment/src/js_environment.cpp index caf83f30d3..da8b9fca85 100644 --- a/js_environment/frameworks/js_environment/src/js_environment.cpp +++ b/js_environment/frameworks/js_environment/src/js_environment.cpp @@ -133,5 +133,17 @@ bool JsEnvironment::LoadScript(const std::string& path, std::vector* bu return engine_->RunScriptBuffer(path.c_str(), *buffer, isBundle) != nullptr; } + +bool JsEnvironment::StartDebugger(const char* libraryPath, bool needBreakPoint, uint32_t instanceId, + const DebuggerPostTask& debuggerPostTask) +{ + if (vm_ == nullptr) { + JSENV_LOG_E("Invalid vm."); + return false; + } + + panda::JSNApi::StartDebugger(libraryPath, vm_, needBreakPoint, instanceId, debuggerPostTask); + return true; +} } // namespace JsEnv } // namespace OHOS diff --git a/js_environment/interfaces/inner_api/js_environment.h b/js_environment/interfaces/inner_api/js_environment.h index b2b1361fcb..4e1b11a927 100644 --- a/js_environment/interfaces/inner_api/js_environment.h +++ b/js_environment/interfaces/inner_api/js_environment.h @@ -64,6 +64,10 @@ public: void RegisterUncaughtExceptionHandler(const JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo); bool LoadScript(const std::string& path, std::vector* buffer = nullptr, bool isBundle = false); + + bool StartDebugger(const char* libraryPath, bool needBreakPoint, uint32_t instanceId, + const DebuggerPostTask& debuggerPostTask = {}); + private: std::unique_ptr impl_ = nullptr; NativeEngine* engine_ = nullptr;