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 #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_cache.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 46 private: 47 bool DfxUnwindRemoteDoUnwindStep(size_t const & index, 48 std::shared_ptr<DfxThread> & thread, unw_cursor_t & cursor, std::shared_ptr<DfxProcess> process); 49 uint64_t DfxUnwindRemoteDoAdjustPc(unw_cursor_t & cursor, uint64_t pc); 50 bool UpdateAndPrintFrameInfo(unw_cursor_t& cursor, std::shared_ptr<DfxThread> thread, 51 std::shared_ptr<DfxFrame> frame, bool enableBuildId); 52 std::string GetReadableBuildId(uint8_t* buildId, size_t length); 53 54 private: 55 DfxUnwindRemote(); 56 DISALLOW_COPY_AND_MOVE(DfxUnwindRemote); 57 58 private: 59 unw_addr_space_t as_; 60 std::unique_ptr<DfxSymbolsCache> cache_; 61 std::map<std::string, std::string> buildIds_; 62 }; 63 } // namespace HiviewDFX 64 } // namespace OHOS 65 66 #endif // DFX_UNWIND_REMOTE_H 67