From 03595c9cdae08b145193fa139800a46db51e9cd1 Mon Sep 17 00:00:00 2001 From: h00611971 Date: Fri, 24 Dec 2021 16:08:10 +0800 Subject: [PATCH] fix cppcrash when exit Signed-off-by: h00611971 --- ecmascript/napi/include/jsnapi.h | 1 + ecmascript/napi/jsnapi.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ecmascript/napi/include/jsnapi.h b/ecmascript/napi/include/jsnapi.h index a65a826d..28256454 100644 --- a/ecmascript/napi/include/jsnapi.h +++ b/ecmascript/napi/include/jsnapi.h @@ -866,6 +866,7 @@ public: static void EnableUserUncaughtErrorHandler(EcmaVM *vm); static bool StartDebugger(const char *library_path, EcmaVM *vm, bool isDebugMode); + static bool StopDebugger(const char *library_path); // Serialize & Deserialize. static void* SerializeValue(const EcmaVM *vm, Local data, Local transfer); static Local DeserializeValue(const EcmaVM *vm, void* recoder); diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index a5f88fbd..20b742ca 100644 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -239,6 +239,27 @@ bool JSNApi::StartDebugger(const char *library_path, EcmaVM *vm, bool isDebugMod return ret; } +bool JSNApi::StopDebugger(const char *library_path) +{ + auto handle = panda::os::library_loader::Load(std::string(library_path)); + if (!handle) { + return false; + } + + using StopDebug = void (*)(const std::string &); + + auto sym = panda::os::library_loader::ResolveSymbol(handle.Value(), "StopDebug"); + if (!sym) { + LOG(ERROR, RUNTIME) << sym.Error().ToString(); + return false; + } + + reinterpret_cast(sym.Value())("PandaDebugger"); + auto runtime = Runtime::GetCurrent(); + runtime->SetDebugMode(false); + return true; +} + bool JSNApi::Execute(EcmaVM *vm, Local fileName, Local entry) { std::string file = fileName->ToString();