1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H 17 #define ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H 18 19 #include "inspector/ws_server.h" 20 21 #include <string> 22 23 namespace panda::ecmascript { 24 class EcmaVM; 25 } // namespace panda::ecmascript 26 27 namespace OHOS::ArkCompiler::Toolchain { 28 using EcmaVM = panda::ecmascript::EcmaVM; 29 using DebuggerPostTask = std::function<void(std::function<void()>&&)>; 30 31 #if __cplusplus 32 extern "C" { 33 #endif 34 35 bool StartDebug(const std::string& componentName, void* vm, bool isDebugMode, 36 int32_t instanceId, const DebuggerPostTask& debuggerPostTask, int port); 37 38 bool StartDebugForSocketpair(int tid, int socketfd); 39 40 bool InitializeDebuggerForSocketpair(void* vm); 41 42 void StopDebug(const std::string& componentName); 43 44 void StopOldDebug(int tid, const std::string& componentName); 45 46 void WaitForDebugger(void* vm); 47 48 void StoreDebuggerInfo(int tid, void* vm, const DebuggerPostTask& debuggerPostTask); 49 50 #if __cplusplus 51 } 52 #endif 53 54 class Inspector { 55 public: 56 Inspector() = default; 57 ~Inspector() = default; 58 59 void OnMessage(std::string&& msg); 60 61 static constexpr int32_t DELAY_CHECK_DISPATCH_STATUS = 100; 62 63 pthread_t tid_ = 0; 64 int tidForSocketPair_ = 0; 65 void* vm_ = nullptr; 66 std::unique_ptr<WsServer> websocketServer_; 67 DebuggerPostTask debuggerPostTask_; 68 }; 69 } // namespace OHOS::ArkCompiler::Toolchain 70 71 #endif // ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H