1 /* 2 * Copyright (c) 2021-2023 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 #ifndef DFX_UNWIND_REMOTE_H 16 #define DFX_UNWIND_REMOTE_H 17 18 #ifdef __clang__ 19 #pragma clang diagnostic push 20 #pragma clang diagnostic ignored "-Wextern-c-compat" 21 #endif 22 23 #include <map> 24 #include <memory> 25 26 #include <libunwind-ptrace.h> 27 #include <libunwind.h> 28 29 #include "dfx_define.h" 30 #include "dfx_process.h" 31 #include "dfx_symbols.h" 32 #include "dfx_thread.h" 33 #include "nocopyable.h" 34 35 namespace OHOS { 36 namespace HiviewDFX { 37 class DfxUnwindRemote final { 38 public: 39 static DfxUnwindRemote &GetInstance(); 40 ~DfxUnwindRemote() = default; 41 42 bool UnwindProcess(std::shared_ptr<DfxProcess> process); 43 bool UnwindThread(std::shared_ptr<DfxProcess> process, std::shared_ptr<DfxThread> thread); 44 void UnwindThreadFallback(std::shared_ptr<DfxProcess> process, std::shared_ptr<DfxThread> thread); 45 bool GetArkJsHeapFuncName(std::string& funcName, std::shared_ptr<DfxThread> thread); 46 47 private: 48 bool DoUnwindStep(size_t const &index, 49 std::shared_ptr<DfxThread> &thread, unw_cursor_t &cursor, std::shared_ptr<DfxProcess> process); 50 uint64_t DoAdjustPc(unw_cursor_t &cursor, uint64_t pc); 51 bool UpdateAndFillFrame(unw_cursor_t& cursor, std::shared_ptr<DfxFrame> frame, 52 std::shared_ptr<DfxThread> thread, bool enableBuildId); 53 static std::string GetReadableBuildId(uint8_t* buildId, size_t length); 54 55 private: 56 DfxUnwindRemote(); 57 DISALLOW_COPY_AND_MOVE(DfxUnwindRemote); 58 59 private: 60 unw_addr_space_t as_; 61 std::unique_ptr<DfxSymbols> symbols_; 62 std::map<std::string, std::string> buildIds_; 63 }; 64 } // namespace HiviewDFX 65 } // namespace OHOS 66 67 #endif // DFX_UNWIND_REMOTE_H 68