• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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     /** The last frame has the same pc/sp as the next frame */
87     UNW_ERROR_REPEATED_FRAME,
88     /** The number of frames exceed the total allowed */
89     UNW_ERROR_MAX_FRAMES_EXCEEDED,
90     /** arm exidx invalid alignment */
91     UNW_ERROR_INVALID_ALIGNMENT,
92     /** arm exidx invalid personality */
93     UNW_ERROR_INVALID_PERSONALITY,
94     /** arm exidx cant unwind */
95     UNW_ERROR_CANT_UNWIND,
96     /** arm exidx spare */
97     UNW_ERROR_ARM_EXIDX_SPARE,
98     /** arm exidx finish */
99     UNW_ERROR_ARM_EXIDX_FINISH,
100     /** Dwarf cfa invalid */
101     UNW_ERROR_DWARF_INVALID_CFA,
102     /** Dwarf fde invalid */
103     UNW_ERROR_DWARF_INVALID_FDE,
104     /** Dwarf instr invalid */
105     UNW_ERROR_DWARF_INVALID_INSTR,
106     /** Unsupported qut reg */
107     UNW_ERROR_UNSUPPORTED_QUT_REG,
108     /** Unsupported version */
109     UNW_ERROR_UNSUPPORTED_VERSION,
110     /** Not support */
111     UNW_ERROR_NOT_SUPPORT,
112 };
113 
114 /**
115  * @brief Quick unwind table file error code
116  */
117 enum QutFileError : uint16_t {
118     /** File not found */
119     QUT_FILE_NONE = 0,
120     /** File not init */
121     QUT_FILE_NOT_INIT,
122     /** File not warmed up */
123     QUT_FILE_NOT_WARMEDUP,
124     /** File load requesting */
125     QUT_FILE_LOAD_REQUESTING,
126     /** File open failed */
127     QUT_FILE_OPEN_FILE_FAILED,
128     /** File state error */
129     QUT_FILE_FILE_STATE_ERROR,
130     /** File too short */
131     QUT_FILE_FILE_TOO_SHORT,
132     /** File mmap failed */
133     QUT_FILE_MMAP_FAILED,
134     /** Version dismatched */
135     QUT_FILE_QUTVERSION_NOT_MATCH,
136     /** Archtecture not matched */
137     QUT_FILE_ARCH_NOT_MATCH,
138     /** File build id dismatched */
139     QUT_FILE_BUILDID_NOT_MATCH,
140     /** File length dismatched */
141     QUT_FILE_FILE_LENGTH_NOT_MATCH,
142     /** Insert new quick unwind table failed */
143     QUT_FILE_INSERT_NEW_QUT_FAILED,
144     /** Try invode request generete */
145     QUT_FILE_TRY_INVOKE_REQUEST_GENERATE,
146     /** File load failed */
147     QUT_FILE_LOAD_FAILED,
148 };
149 } // namespace HiviewDFX
150 } // namespace OHOS
151 #endif
152