From 64b7377a8ffe05970d58e39fb2b4b27d3fb51b61 Mon Sep 17 00:00:00 2001 From: Urakov Alexandr Date: Wed, 13 Jul 2022 13:35:46 +0300 Subject: [PATCH] [PT] Extract debugger agents to separate source files Change-Id: Ie6389966bcd2f64d4caab78adc15e8b6ff14ed98 Signed-off-by: Urakov Alexandr --- runtime/CMakeLists.txt | 1 + runtime/napi/jsnapi.cpp | 38 ++------------------ runtime/napi/jsnapi_debugger_agent.cpp | 49 ++++++++++++++++++++++++++ runtime/napi/jsnapi_debugger_agent.h | 36 +++++++++++++++++++ runtime/runtime_sources.gn | 1 + 5 files changed, 89 insertions(+), 36 deletions(-) create mode 100644 runtime/napi/jsnapi_debugger_agent.cpp create mode 100644 runtime/napi/jsnapi_debugger_agent.h diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index c61cb593d..73d1a1155 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -178,6 +178,7 @@ set(ECMASCRIPT_SOURCES ${ECMA_SRC_DIR}/mem/space.cpp ${ECMA_SRC_DIR}/mem/verification.cpp ${ECMA_SRC_DIR}/napi/jsnapi.cpp + ${ECMA_SRC_DIR}/napi/jsnapi_debugger_agent.cpp ${ECMA_SRC_DIR}/object_factory.cpp ${ECMA_SRC_DIR}/object_operator.cpp ${ECMA_SRC_DIR}/platform/platform.cpp diff --git a/runtime/napi/jsnapi.cpp b/runtime/napi/jsnapi.cpp index 454a4edf2..ebf68d0ce 100644 --- a/runtime/napi/jsnapi.cpp +++ b/runtime/napi/jsnapi.cpp @@ -14,6 +14,7 @@ */ #include "jsnapi_helper-inl.h" +#include "jsnapi_debugger_agent.h" #include #include @@ -109,41 +110,6 @@ constexpr uint32_t COMPILER_POOL_SIZE = 2000000; // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) constexpr std::string_view ENTRY_POINTER = "_GLOBAL::func_main_0"; -class JSNDebuggerAgent : public LibraryAgent, public LibraryAgentLoader { -public: - JSNDebuggerAgent(os::memory::Mutex &mutex, const char *libraryPath, EcmaVM *vm, bool isDebugMode) - : LibraryAgent(mutex, libraryPath, "StartDebug", "StopDebug"), vm_(vm), isDebugMode_(isDebugMode) - { - } - -private: - bool CallLoadCallback(void *resolvedFunction) override - { - ASSERT(resolvedFunction); - - using StartDebugger = bool (*)(const std::string &, EcmaVM *, bool); - if (!reinterpret_cast(resolvedFunction)("PandaDebugger", vm_, isDebugMode_)) { - LOG_ECMA(ERROR) << "'StartDebug' has failed"; - return false; - } - - return true; - } - - bool CallUnloadCallback(void *resolvedFunction) override - { - ASSERT(resolvedFunction); - - using StopDebug = void (*)(const std::string &); - reinterpret_cast(resolvedFunction)("PandaDebugger"); - - return true; - } - - EcmaVM *vm_; - bool isDebugMode_; -}; - LoadableAgentHandle s_debugger_agent; // NOLINT(fuchsia-statically-constructed-objects) } // namespace @@ -258,7 +224,7 @@ void JSNApi::ThrowException(const EcmaVM *vm, Local error) bool JSNApi::StartDebugger(const char *library_path, EcmaVM *vm, bool isDebugMode) { - auto agent = JSNDebuggerAgent::LoadInstance(library_path, vm, isDebugMode); + auto agent = JSNApiDebuggerAgent::LoadInstance(library_path, vm, isDebugMode); if (!agent) { LOG_ECMA(ERROR) << "Could not load JSN debugger agent"; return false; diff --git a/runtime/napi/jsnapi_debugger_agent.cpp b/runtime/napi/jsnapi_debugger_agent.cpp new file mode 100644 index 000000000..987a1a1d4 --- /dev/null +++ b/runtime/napi/jsnapi_debugger_agent.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jsnapi_debugger_agent.h" + +#include "plugins/ecmascript/runtime/ecma_macros.h" + +namespace panda { +JSNApiDebuggerAgent::JSNApiDebuggerAgent(os::memory::Mutex &mutex, const char *library_path, EcmaVM *vm, + bool is_debug_mode) + : LibraryAgent(mutex, library_path, "StartDebug", "StopDebug"), vm_(vm), is_debug_mode_(is_debug_mode) +{ +} + +bool JSNApiDebuggerAgent::CallLoadCallback(void *resolved_function) +{ + ASSERT(resolved_function); + + using StartDebugger = bool (*)(const std::string &, EcmaVM *, bool); + if (!reinterpret_cast(resolved_function)("PandaDebugger", vm_, is_debug_mode_)) { + LOG_ECMA(ERROR) << "'StartDebug' has failed"; + return false; + } + + return true; +} + +bool JSNApiDebuggerAgent::CallUnloadCallback(void *resolved_function) +{ + ASSERT(resolved_function); + + using StopDebug = void (*)(const std::string &); + reinterpret_cast(resolved_function)("PandaDebugger"); + + return true; +} +} // namespace panda diff --git a/runtime/napi/jsnapi_debugger_agent.h b/runtime/napi/jsnapi_debugger_agent.h new file mode 100644 index 000000000..215de5be0 --- /dev/null +++ b/runtime/napi/jsnapi_debugger_agent.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_NAPI_JSNAPI_DEBUGGER_AGENT_H +#define ECMASCRIPT_NAPI_JSNAPI_DEBUGGER_AGENT_H + +#include "plugins/ecmascript/runtime/napi/include/jsnapi.h" +#include "runtime/include/loadable_agent.h" + +namespace panda { +class JSNApiDebuggerAgent : public LibraryAgent, public LibraryAgentLoader { +public: + JSNApiDebuggerAgent(os::memory::Mutex &mutex, const char *library_path, EcmaVM *vm, bool is_debug_mode); + +private: + bool CallLoadCallback(void *resolved_function) override; + bool CallUnloadCallback(void *resolved_function) override; + + EcmaVM *vm_; + bool is_debug_mode_; +}; +} // namespace panda + +#endif // ECMASCRIPT_NAPI_JSNAPI_DEBUGGER_AGENT_H diff --git a/runtime/runtime_sources.gn b/runtime/runtime_sources.gn index 5477ac554..29d8c34b0 100644 --- a/runtime/runtime_sources.gn +++ b/runtime/runtime_sources.gn @@ -149,6 +149,7 @@ srcs = [ "mem/space.cpp", "mem/verification.cpp", "napi/jsnapi.cpp", + "napi/jsnapi_debugger_agent.cpp", "object_factory.cpp", "object_operator.cpp", "platform/platform.cpp", -- Gitee