【归一化】JSEnvironment提供Debug能力

Signed-off-by: 杨亮 <yangliang36@huawei.com>
Change-Id: I48dd901b45fff1c0158bf1eaac6632299d81b4a4
This commit is contained in:
杨亮 2023-03-31 14:51:11 +08:00 committed by zhangyafei.echo
parent 2b4c04efd4
commit a3b66f7f42
4 changed files with 30 additions and 11 deletions

View File

@ -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<uint32_t>(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<void()>&& 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<uint8_t>& buffer)

View File

@ -135,6 +135,8 @@ private:
void InitSourceMap(const Options& options);
bool InitLoop(const std::shared_ptr<AppExecFwk::EventRunner>& 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

View File

@ -133,5 +133,17 @@ bool JsEnvironment::LoadScript(const std::string& path, std::vector<uint8_t>* 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

View File

@ -64,6 +64,10 @@ public:
void RegisterUncaughtExceptionHandler(const JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo);
bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false);
bool StartDebugger(const char* libraryPath, bool needBreakPoint, uint32_t instanceId,
const DebuggerPostTask& debuggerPostTask = {});
private:
std::unique_ptr<JsEnvironmentImpl> impl_ = nullptr;
NativeEngine* engine_ = nullptr;