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 data 24 */ 25 struct UnwindErrorData { GetCodeUnwindErrorData26 inline const uint16_t& GetCode() { return code_; } GetAddrUnwindErrorData27 inline const uint64_t& GetAddr() { return addr_; } 28 29 template <typename T1, typename T2> SetAddrAndCodeUnwindErrorData30 inline void SetAddrAndCode(T1 addr, T2 code) 31 { 32 #ifdef DFX_UNWIND_ERROR 33 addr_ = static_cast<uint64_t>(addr); 34 code_ = static_cast<uint16_t>(code); 35 #endif 36 } 37 38 template <typename T> SetCodeUnwindErrorData39 inline void SetCode(T code) 40 { 41 #ifdef DFX_UNWIND_ERROR 42 code_ = static_cast<uint16_t>(code); 43 #endif 44 } 45 46 template <typename T> SetAddrUnwindErrorData47 inline void SetAddr(T addr) 48 { 49 #ifdef DFX_UNWIND_ERROR 50 addr_ = static_cast<uint64_t>(addr); 51 #endif 52 } 53 private: 54 uint16_t code_ = 0; 55 uint64_t addr_ = 0; 56 }; 57 58 /** 59 * @brief Unwind error code 60 */ 61 enum UnwindErrorCode : uint16_t { 62 /** No error */ 63 UNW_ERROR_NONE = 0, 64 /** No unwind info */ 65 UNW_ERROR_NO_UNWIND_INFO, 66 /** Pc Not in unwind info */ 67 UNW_ERROR_PC_NOT_IN_UNWIND_INFO, 68 /** Invalid unwind context */ 69 UNW_ERROR_INVALID_CONTEXT, 70 /** Invalid unwind memory */ 71 UNW_ERROR_INVALID_MEMORY, 72 /** Invalid unwind regs */ 73 UNW_ERROR_INVALID_REGS, 74 /** Invalid unwind map */ 75 UNW_ERROR_INVALID_MAP, 76 /** Invalid unwind elf */ 77 UNW_ERROR_INVALID_ELF, 78 /** Invalid unwind pid */ 79 UNW_ERROR_INVALID_PID, 80 /** Reserved value */ 81 UNW_ERROR_RESERVED_VALUE, 82 /** Illegal value */ 83 UNW_ERROR_ILLEGAL_VALUE, 84 /** Illegal state */ 85 UNW_ERROR_ILLEGAL_STATE, 86 /** unreadable sp */ 87 UNW_ERROR_UNREADABLE_SP, 88 /** The last frame has the same pc/sp as the next frame */ 89 UNW_ERROR_REPEATED_FRAME, 90 /** The last return address has the same */ 91 UNW_ERROR_RETURN_ADDRESS_SAME, 92 /** The last return address undefined */ 93 UNW_ERROR_RETURN_ADDRESS_UNDEFINED, 94 /** The number of frames exceed the total allowed */ 95 UNW_ERROR_MAX_FRAMES_EXCEEDED, 96 /** arm exidx invalid alignment */ 97 UNW_ERROR_INVALID_ALIGNMENT, 98 /** arm exidx invalid personality */ 99 UNW_ERROR_INVALID_PERSONALITY, 100 /** arm exidx cant unwind */ 101 UNW_ERROR_CANT_UNWIND, 102 /** arm exidx spare */ 103 UNW_ERROR_ARM_EXIDX_SPARE, 104 /** arm exidx finish */ 105 UNW_ERROR_ARM_EXIDX_FINISH, 106 /** Dwarf cfa invalid */ 107 UNW_ERROR_DWARF_INVALID_CFA, 108 /** Dwarf fde invalid */ 109 UNW_ERROR_DWARF_INVALID_FDE, 110 /** Dwarf instr invalid */ 111 UNW_ERROR_DWARF_INVALID_INSTR, 112 /** step ark frame error */ 113 UNW_ERROR_STEP_ARK_FRAME, 114 /** Unsupported qut reg */ 115 UNW_ERROR_UNSUPPORTED_QUT_REG, 116 /** Unsupported version */ 117 UNW_ERROR_UNSUPPORTED_VERSION, 118 /** Not support */ 119 UNW_ERROR_NOT_SUPPORT, 120 }; 121 122 /** 123 * @brief Quick unwind table file error code 124 */ 125 enum QutFileError : uint16_t { 126 /** File not found */ 127 QUT_FILE_NONE = 0, 128 /** File not init */ 129 QUT_FILE_NOT_INIT, 130 /** File not warmed up */ 131 QUT_FILE_NOT_WARMEDUP, 132 /** File load requesting */ 133 QUT_FILE_LOAD_REQUESTING, 134 /** File open failed */ 135 QUT_FILE_OPEN_FILE_FAILED, 136 /** File state error */ 137 QUT_FILE_FILE_STATE_ERROR, 138 /** File too short */ 139 QUT_FILE_FILE_TOO_SHORT, 140 /** File mmap failed */ 141 QUT_FILE_MMAP_FAILED, 142 /** Version dismatched */ 143 QUT_FILE_QUTVERSION_NOT_MATCH, 144 /** Archtecture not matched */ 145 QUT_FILE_ARCH_NOT_MATCH, 146 /** File build id dismatched */ 147 QUT_FILE_BUILDID_NOT_MATCH, 148 /** File length dismatched */ 149 QUT_FILE_FILE_LENGTH_NOT_MATCH, 150 /** Insert new quick unwind table failed */ 151 QUT_FILE_INSERT_NEW_QUT_FAILED, 152 /** Try invode request generete */ 153 QUT_FILE_TRY_INVOKE_REQUEST_GENERATE, 154 /** File load failed */ 155 QUT_FILE_LOAD_FAILED, 156 }; 157 } // namespace HiviewDFX 158 } // namespace OHOS 159 #endif 160