1 /* 2 * Copyright (c) 2023-2024 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_ERRORS_H 16 #define DFX_ERRORS_H 17 18 #include <cinttypes> 19 20 namespace OHOS { 21 namespace HiviewDFX { 22 /** 23 * @brief Unwind error code 24 */ 25 enum UnwindErrorCode : uint16_t { 26 /** No error */ 27 UNW_ERROR_NONE = 0, 28 /** No unwind info */ 29 UNW_ERROR_NO_UNWIND_INFO, 30 /** Pc Not in unwind info */ 31 UNW_ERROR_PC_NOT_IN_UNWIND_INFO, 32 /** Invalid unwind context */ 33 UNW_ERROR_INVALID_CONTEXT, 34 /** Invalid unwind memory */ 35 UNW_ERROR_INVALID_MEMORY, 36 /** Invalid unwind regs */ 37 UNW_ERROR_INVALID_REGS, 38 /** Invalid unwind map */ 39 UNW_ERROR_INVALID_MAP, 40 /** Invalid unwind elf */ 41 UNW_ERROR_INVALID_ELF, 42 /** Invalid unwind pid */ 43 UNW_ERROR_INVALID_PID, 44 /** Reserved value */ 45 UNW_ERROR_RESERVED_VALUE, 46 /** Illegal value */ 47 UNW_ERROR_ILLEGAL_VALUE, 48 /** Illegal state */ 49 UNW_ERROR_ILLEGAL_STATE, 50 /** unreadable sp */ 51 UNW_ERROR_UNREADABLE_SP, 52 /** The last frame has the same pc/sp as the next frame */ 53 UNW_ERROR_REPEATED_FRAME, 54 /** The last return address has the same */ 55 UNW_ERROR_RETURN_ADDRESS_SAME, 56 /** The last return address undefined */ 57 UNW_ERROR_RETURN_ADDRESS_UNDEFINED, 58 /** The number of frames exceed the total allowed */ 59 UNW_ERROR_MAX_FRAMES_EXCEEDED, 60 /** arm exidx invalid alignment */ 61 UNW_ERROR_INVALID_ALIGNMENT, 62 /** arm exidx invalid personality */ 63 UNW_ERROR_INVALID_PERSONALITY, 64 /** arm exidx cant unwind */ 65 UNW_ERROR_CANT_UNWIND, 66 /** arm exidx spare */ 67 UNW_ERROR_ARM_EXIDX_SPARE, 68 /** arm exidx finish */ 69 UNW_ERROR_ARM_EXIDX_FINISH, 70 /** Dwarf cfa invalid */ 71 UNW_ERROR_DWARF_INVALID_CFA, 72 /** Dwarf fde invalid */ 73 UNW_ERROR_DWARF_INVALID_FDE, 74 /** Dwarf instr invalid */ 75 UNW_ERROR_DWARF_INVALID_INSTR, 76 /** step ark frame error */ 77 UNW_ERROR_STEP_ARK_FRAME, 78 /** Unknown ark map */ 79 UNW_ERROR_UNKNOWN_ARK_MAP, 80 /** Unsupported qut reg */ 81 UNW_ERROR_UNSUPPORTED_QUT_REG, 82 /** Unsupported version */ 83 UNW_ERROR_UNSUPPORTED_VERSION, 84 /** Not support */ 85 UNW_ERROR_NOT_SUPPORT, 86 }; 87 88 /** 89 * @brief Unwind error data 90 */ 91 struct UnwindErrorData { GetCodeUnwindErrorData92 inline const uint16_t& GetCode() { return code_; } GetAddrUnwindErrorData93 inline const uint64_t& GetAddr() { return addr_; } 94 95 template <typename T1, typename T2> 96 inline void SetAddrAndCode([[maybe_unused]] T1 addr, [[maybe_unused]] T2 code) 97 { 98 #ifdef DFX_UNWIND_ERROR 99 addr_ = static_cast<uint64_t>(addr); 100 code_ = static_cast<uint16_t>(code); 101 #endif 102 } 103 104 template <typename T> 105 inline void SetCode([[maybe_unused]] T code) 106 { 107 #ifdef DFX_UNWIND_ERROR 108 code_ = static_cast<uint16_t>(code); 109 #endif 110 } 111 112 template <typename T> 113 inline void SetAddr([[maybe_unused]] T addr) 114 { 115 #ifdef DFX_UNWIND_ERROR 116 addr_ = static_cast<uint64_t>(addr); 117 #endif 118 } 119 private: 120 uint16_t code_ = 0; 121 uint64_t addr_ = 0; 122 }; 123 } // namespace HiviewDFX 124 } // namespace OHOS 125 #endif 126