• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <stdint.h>
20 
21 namespace unwindstack {
22 
23 // A bit map of warnings, multiple warnings can be set at the same time.
24 enum WarningCode : uint64_t {
25   WARNING_NONE = 0,
26   WARNING_DEX_PC_NOT_IN_MAP = 0x1,  // A dex pc was found, but it doesn't exist
27                                     // in any valid map.
28 };
29 
30 enum ErrorCode : uint8_t {
31   ERROR_NONE,                   // No error.
32   ERROR_MEMORY_INVALID,         // Memory read failed.
33   ERROR_UNWIND_INFO,            // Unable to use unwind information to unwind.
34   ERROR_UNSUPPORTED,            // Encountered unsupported feature.
35   ERROR_INVALID_MAP,            // Unwind in an invalid map.
36   ERROR_MAX_FRAMES_EXCEEDED,    // The number of frames exceed the total allowed.
37   ERROR_REPEATED_FRAME,         // The last frame has the same pc/sp as the next.
38   ERROR_INVALID_ELF,            // Unwind in an invalid elf.
39   ERROR_THREAD_DOES_NOT_EXIST,  // Attempt to unwind a local thread that does
40                                 // not exist.
41   ERROR_THREAD_TIMEOUT,         // Timeout trying to unwind a local thread.
42   ERROR_SYSTEM_CALL,            // System call failed while unwinding.
43   ERROR_BAD_ARCH,               // Arch invalid (none, or mismatched).
44   ERROR_MAPS_PARSE,             // Failed to parse maps data.
45   ERROR_INVALID_PARAMETER,      // Invalid parameter passed to function.
46   ERROR_PTRACE_CALL,            // Ptrace call failed while unwinding.
47   ERROR_MAX = ERROR_INVALID_PARAMETER,
48 };
49 
GetErrorCodeString(ErrorCode error)50 static inline const char* GetErrorCodeString(ErrorCode error) {
51   switch (error) {
52     case ERROR_NONE:
53       return "None";
54     case ERROR_MEMORY_INVALID:
55       return "Memory Invalid";
56     case ERROR_UNWIND_INFO:
57       return "Unwind Info";
58     case ERROR_UNSUPPORTED:
59       return "Unsupported";
60     case ERROR_INVALID_MAP:
61       return "Invalid Map";
62     case ERROR_MAX_FRAMES_EXCEEDED:
63       return "Maximum Frames Exceeded";
64     case ERROR_REPEATED_FRAME:
65       return "Repeated Frame";
66     case ERROR_INVALID_ELF:
67       return "Invalid Elf";
68     case ERROR_THREAD_DOES_NOT_EXIST:
69       return "Thread Does Not Exist";
70     case ERROR_THREAD_TIMEOUT:
71       return "Thread Timeout";
72     case ERROR_SYSTEM_CALL:
73       return "System Call Failed";
74     case ERROR_BAD_ARCH:
75       return "Invalid arch detected";
76     case ERROR_MAPS_PARSE:
77       return "Failed to parse maps";
78     case ERROR_INVALID_PARAMETER:
79       return "Invalid parameter";
80     case ERROR_PTRACE_CALL:
81       return "Ptrace Call Failed";
82   }
83 }
84 
85 struct ErrorData {
86   ErrorCode code;
87   uint64_t address;  // Only valid when code is ERROR_MEMORY_INVALID.
88                      // Indicates the failing address.
89 };
90 
91 }  // namespace unwindstack
92