1800b99b8Sopenharmony_ci/* 2800b99b8Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License. 5800b99b8Sopenharmony_ci * You may obtain a copy of the License at 6800b99b8Sopenharmony_ci * 7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8800b99b8Sopenharmony_ci * 9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and 13800b99b8Sopenharmony_ci * limitations under the License. 14800b99b8Sopenharmony_ci */ 15800b99b8Sopenharmony_ci#ifndef DFX_ERRORS_H 16800b99b8Sopenharmony_ci#define DFX_ERRORS_H 17800b99b8Sopenharmony_ci 18800b99b8Sopenharmony_ci#include <cinttypes> 19800b99b8Sopenharmony_ci 20800b99b8Sopenharmony_cinamespace OHOS { 21800b99b8Sopenharmony_cinamespace HiviewDFX { 22800b99b8Sopenharmony_ci/** 23800b99b8Sopenharmony_ci * @brief Unwind error code 24800b99b8Sopenharmony_ci */ 25800b99b8Sopenharmony_cienum UnwindErrorCode : uint16_t { 26800b99b8Sopenharmony_ci /** No error */ 27800b99b8Sopenharmony_ci UNW_ERROR_NONE = 0, 28800b99b8Sopenharmony_ci /** No unwind info */ 29800b99b8Sopenharmony_ci UNW_ERROR_NO_UNWIND_INFO, 30800b99b8Sopenharmony_ci /** Pc Not in unwind info */ 31800b99b8Sopenharmony_ci UNW_ERROR_PC_NOT_IN_UNWIND_INFO, 32800b99b8Sopenharmony_ci /** Invalid unwind context */ 33800b99b8Sopenharmony_ci UNW_ERROR_INVALID_CONTEXT, 34800b99b8Sopenharmony_ci /** Invalid unwind memory */ 35800b99b8Sopenharmony_ci UNW_ERROR_INVALID_MEMORY, 36800b99b8Sopenharmony_ci /** Invalid unwind regs */ 37800b99b8Sopenharmony_ci UNW_ERROR_INVALID_REGS, 38800b99b8Sopenharmony_ci /** Invalid unwind map */ 39800b99b8Sopenharmony_ci UNW_ERROR_INVALID_MAP, 40800b99b8Sopenharmony_ci /** Invalid unwind elf */ 41800b99b8Sopenharmony_ci UNW_ERROR_INVALID_ELF, 42800b99b8Sopenharmony_ci /** Invalid unwind pid */ 43800b99b8Sopenharmony_ci UNW_ERROR_INVALID_PID, 44800b99b8Sopenharmony_ci /** Reserved value */ 45800b99b8Sopenharmony_ci UNW_ERROR_RESERVED_VALUE, 46800b99b8Sopenharmony_ci /** Illegal value */ 47800b99b8Sopenharmony_ci UNW_ERROR_ILLEGAL_VALUE, 48800b99b8Sopenharmony_ci /** Illegal state */ 49800b99b8Sopenharmony_ci UNW_ERROR_ILLEGAL_STATE, 50800b99b8Sopenharmony_ci /** unreadable sp */ 51800b99b8Sopenharmony_ci UNW_ERROR_UNREADABLE_SP, 52800b99b8Sopenharmony_ci /** The last frame has the same pc/sp as the next frame */ 53800b99b8Sopenharmony_ci UNW_ERROR_REPEATED_FRAME, 54800b99b8Sopenharmony_ci /** The last return address has the same */ 55800b99b8Sopenharmony_ci UNW_ERROR_RETURN_ADDRESS_SAME, 56800b99b8Sopenharmony_ci /** The last return address undefined */ 57800b99b8Sopenharmony_ci UNW_ERROR_RETURN_ADDRESS_UNDEFINED, 58800b99b8Sopenharmony_ci /** The number of frames exceed the total allowed */ 59800b99b8Sopenharmony_ci UNW_ERROR_MAX_FRAMES_EXCEEDED, 60800b99b8Sopenharmony_ci /** arm exidx invalid alignment */ 61800b99b8Sopenharmony_ci UNW_ERROR_INVALID_ALIGNMENT, 62800b99b8Sopenharmony_ci /** arm exidx invalid personality */ 63800b99b8Sopenharmony_ci UNW_ERROR_INVALID_PERSONALITY, 64800b99b8Sopenharmony_ci /** arm exidx cant unwind */ 65800b99b8Sopenharmony_ci UNW_ERROR_CANT_UNWIND, 66800b99b8Sopenharmony_ci /** arm exidx spare */ 67800b99b8Sopenharmony_ci UNW_ERROR_ARM_EXIDX_SPARE, 68800b99b8Sopenharmony_ci /** arm exidx finish */ 69800b99b8Sopenharmony_ci UNW_ERROR_ARM_EXIDX_FINISH, 70800b99b8Sopenharmony_ci /** Dwarf cfa invalid */ 71800b99b8Sopenharmony_ci UNW_ERROR_DWARF_INVALID_CFA, 72800b99b8Sopenharmony_ci /** Dwarf fde invalid */ 73800b99b8Sopenharmony_ci UNW_ERROR_DWARF_INVALID_FDE, 74800b99b8Sopenharmony_ci /** Dwarf instr invalid */ 75800b99b8Sopenharmony_ci UNW_ERROR_DWARF_INVALID_INSTR, 76800b99b8Sopenharmony_ci /** step ark frame error */ 77800b99b8Sopenharmony_ci UNW_ERROR_STEP_ARK_FRAME, 78800b99b8Sopenharmony_ci /** Unknown ark map */ 79800b99b8Sopenharmony_ci UNW_ERROR_UNKNOWN_ARK_MAP, 80800b99b8Sopenharmony_ci /** Unsupported qut reg */ 81800b99b8Sopenharmony_ci UNW_ERROR_UNSUPPORTED_QUT_REG, 82800b99b8Sopenharmony_ci /** Unsupported version */ 83800b99b8Sopenharmony_ci UNW_ERROR_UNSUPPORTED_VERSION, 84800b99b8Sopenharmony_ci /** Not support */ 85800b99b8Sopenharmony_ci UNW_ERROR_NOT_SUPPORT, 86800b99b8Sopenharmony_ci}; 87800b99b8Sopenharmony_ci 88800b99b8Sopenharmony_ci/** 89800b99b8Sopenharmony_ci * @brief Unwind error data 90800b99b8Sopenharmony_ci */ 91800b99b8Sopenharmony_cistruct UnwindErrorData { 92800b99b8Sopenharmony_ci inline const uint16_t& GetCode() { return code_; } 93800b99b8Sopenharmony_ci inline const uint64_t& GetAddr() { return addr_; } 94800b99b8Sopenharmony_ci 95800b99b8Sopenharmony_ci template <typename T1, typename T2> 96800b99b8Sopenharmony_ci inline void SetAddrAndCode([[maybe_unused]] T1 addr, [[maybe_unused]] T2 code) 97800b99b8Sopenharmony_ci { 98800b99b8Sopenharmony_ci#ifdef DFX_UNWIND_ERROR 99800b99b8Sopenharmony_ci addr_ = static_cast<uint64_t>(addr); 100800b99b8Sopenharmony_ci code_ = static_cast<uint16_t>(code); 101800b99b8Sopenharmony_ci#endif 102800b99b8Sopenharmony_ci } 103800b99b8Sopenharmony_ci 104800b99b8Sopenharmony_ci template <typename T> 105800b99b8Sopenharmony_ci inline void SetCode([[maybe_unused]] T code) 106800b99b8Sopenharmony_ci { 107800b99b8Sopenharmony_ci#ifdef DFX_UNWIND_ERROR 108800b99b8Sopenharmony_ci code_ = static_cast<uint16_t>(code); 109800b99b8Sopenharmony_ci#endif 110800b99b8Sopenharmony_ci } 111800b99b8Sopenharmony_ci 112800b99b8Sopenharmony_ci template <typename T> 113800b99b8Sopenharmony_ci inline void SetAddr([[maybe_unused]] T addr) 114800b99b8Sopenharmony_ci { 115800b99b8Sopenharmony_ci#ifdef DFX_UNWIND_ERROR 116800b99b8Sopenharmony_ci addr_ = static_cast<uint64_t>(addr); 117800b99b8Sopenharmony_ci#endif 118800b99b8Sopenharmony_ci } 119800b99b8Sopenharmony_ciprivate: 120800b99b8Sopenharmony_ci uint16_t code_ = 0; 121800b99b8Sopenharmony_ci uint64_t addr_ = 0; 122800b99b8Sopenharmony_ci}; 123800b99b8Sopenharmony_ci} // namespace HiviewDFX 124800b99b8Sopenharmony_ci} // namespace OHOS 125800b99b8Sopenharmony_ci#endif 126