1 /* 2 * Copyright (c) 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_dump_request.h" 31 #include "dfx_process.h" 32 #include "dfx_symbols.h" 33 #include "dfx_thread.h" 34 #include "nocopyable.h" 35 36 namespace OHOS { 37 namespace HiviewDFX { 38 class DfxUnwindRemote final { 39 public: 40 static DfxUnwindRemote &GetInstance(); 41 ~DfxUnwindRemote() = default; 42 43 bool UnwindProcess(std::shared_ptr<ProcessDumpRequest> request, std::shared_ptr<DfxProcess> process); 44 bool UnwindThread(std::shared_ptr<DfxProcess> process, std::shared_ptr<DfxThread> thread); 45 void UnwindThreadFallback(std::shared_ptr<DfxProcess> process, std::shared_ptr<DfxThread> thread); 46 bool GetArkJsHeapFuncName(std::string& funcName, std::shared_ptr<DfxThread> thread); 47 48 private: 49 bool DoUnwindStep(size_t const &index, 50 std::shared_ptr<DfxThread> &thread, unw_cursor_t &cursor, std::shared_ptr<DfxProcess> process); 51 uint64_t DoAdjustPc(unw_cursor_t &cursor, uint64_t pc); 52 bool UpdateAndFillFrame(unw_cursor_t& cursor, DfxFrame& frame, 53 std::shared_ptr<DfxProcess> process, std::shared_ptr<DfxThread> thread, bool enableBuildId); 54 static std::string GetReadableBuildId(uint8_t* buildId, size_t length); 55 static void UnwindThreadByParseStackIfNeed(std::shared_ptr<DfxProcess> &process, 56 std::shared_ptr<DfxThread> &thread); 57 58 private: 59 DfxUnwindRemote(); 60 DISALLOW_COPY_AND_MOVE(DfxUnwindRemote); 61 62 private: 63 unw_addr_space_t as_; 64 std::unique_ptr<DfxSymbols> symbols_; 65 std::map<std::string, std::string> buildIds_; 66 }; 67 } // namespace HiviewDFX 68 } // namespace OHOS 69 70 #endif // DFX_UNWIND_REMOTE_H 71