diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 10fec41bec..a0382b0506 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -247,27 +247,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 b567ffdf86..b3f3779c8f 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -133,6 +133,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 2195e155c5..f20e42841d 100644 --- a/js_environment/frameworks/js_environment/src/js_environment.cpp +++ b/js_environment/frameworks/js_environment/src/js_environment.cpp @@ -134,5 +134,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 80fe919b8c..28e2e1fbbf 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;