1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef _LIBUNWINDSTACK_ERROR_H
18 #define _LIBUNWINDSTACK_ERROR_H
19
20 #include <stdint.h>
21
22 namespace unwindstack {
23
24 // A bit map of warnings, multiple warnings can be set at the same time.
25 enum WarningCode : uint64_t {
26 WARNING_NONE = 0,
27 WARNING_DEX_PC_NOT_IN_MAP = 0x1, // A dex pc was found, but it doesn't exist
28 // in any valid map.
29 };
30
31 enum ErrorCode : uint8_t {
32 ERROR_NONE, // No error.
33 ERROR_MEMORY_INVALID, // Memory read failed.
34 ERROR_UNWIND_INFO, // Unable to use unwind information to unwind.
35 ERROR_UNSUPPORTED, // Encountered unsupported feature.
36 ERROR_INVALID_MAP, // Unwind in an invalid map.
37 ERROR_MAX_FRAMES_EXCEEDED, // The number of frames exceed the total allowed.
38 ERROR_REPEATED_FRAME, // The last frame has the same pc/sp as the next.
39 ERROR_INVALID_ELF, // Unwind in an invalid elf.
40 ERROR_THREAD_DOES_NOT_EXIST, // Attempt to unwind a local thread that does
41 // not exist.
42 ERROR_THREAD_TIMEOUT, // Timeout trying to unwind a local thread.
43 ERROR_SYSTEM_CALL, // System call failed while unwinding.
44 ERROR_MAX = ERROR_SYSTEM_CALL,
45 };
46
GetErrorCodeString(ErrorCode error)47 static inline const char* GetErrorCodeString(ErrorCode error) {
48 switch (error) {
49 case ERROR_NONE:
50 return "None";
51 case ERROR_MEMORY_INVALID:
52 return "Memory Invalid";
53 case ERROR_UNWIND_INFO:
54 return "Unwind Info";
55 case ERROR_UNSUPPORTED:
56 return "Unsupported";
57 case ERROR_INVALID_MAP:
58 return "Invalid Map";
59 case ERROR_MAX_FRAMES_EXCEEDED:
60 return "Maximum Frames Exceeded";
61 case ERROR_REPEATED_FRAME:
62 return "Repeated Frame";
63 case ERROR_INVALID_ELF:
64 return "Invalid Elf";
65 case ERROR_THREAD_DOES_NOT_EXIST:
66 return "Thread Does Not Exist";
67 case ERROR_THREAD_TIMEOUT:
68 return "Thread Timeout";
69 case ERROR_SYSTEM_CALL:
70 return "System Call Failed";
71 }
72 }
73
74 struct ErrorData {
75 ErrorCode code;
76 uint64_t address; // Only valid when code is ERROR_MEMORY_INVALID.
77 // Indicates the failing address.
78 };
79
80 } // namespace unwindstack
81
82 #endif // _LIBUNWINDSTACK_ERROR_H
83