• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef DFX_EXCEPTION_H
17 #define DFX_EXCEPTION_H
18 
19 #include <inttypes.h>
20 #include "dfx_define.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 enum CrashExceptionCode : int32_t {
27     CRASH_ESUCCESS = 0,                 /* No error */
28 
29     CRASH_SIGNAL_EMASKED = 101,         /* Signal has been masked */
30     CRASH_SIGNAL_EFORK,                 /* Failed to fork child process */
31     CRASH_SIGNAL_ECLONE,                /* Failed to clone thread of recycle dump process */
32     CRASH_SIGNAL_ESETSTATE,             /* Failed to set dump state */
33     CRASH_SIGNAL_EINHERITCAP,           /* Failed to inherit capabilities */
34     CRASH_SIGNAL_EEXECL,                /* Failed to execl processdump */
35     CRASH_SIGNAL_EWAITEXIT,             /* Failed to wait vm process exit */
36 
37     CRASH_DUMP_EREADREQ = 201,          /* Failed to read dump request */
38     CRASH_DUMP_EPARENTPID,              /* Failed to check parent pid */
39     CRASH_DUMP_EATTACH,                 /* Failed to attach target process */
40     CRASH_DUMP_EWRITEFD,                /* Failed to request writen fd */
41     CRASH_DUMP_EKILLED,                 /* Tagert process has been killed */
42     CRASH_DUMP_LOCAL_REPORT,            /* Local Handler DumpInfo Report*/
43 
44     CRASH_UNWIND_ECONTEXT = 301,        /* Unwind context illegal */
45     CRASH_UNWIND_EFRAME,                /* Failed to step ark js frame */
46     CRASH_UNWIND_ESTACK,                /* Stack corruption */
47 
48     CRASH_LOG_ESTACKLOS = 401,          /* Crash thread stack not found */
49     CRASH_LOG_ECHILDSTACK,              /* Child thread stack not found */
50     CRASH_LOG_EREGLOS,                  /* Registers not found */
51     CRASH_LOG_EMEMLOS,                  /* Memory not found */
52     CRASH_LOG_ESTACKMEMLOS,             /* Fault stack not found */
53     CRASH_LOG_EMAPLOS,                  /* Maps not found */
54     CRASH_LOG_EHILOGLOS,                /* Hilog not found */
55 
56     CRASH_UNKNOWN = 500,                /* Unknown reason */
57 };
58 
59 struct ErrCodeToStr {
60     /** Crash exception stage code */
61     int32_t errCode;
62     /** Crash exception string */
63     const char* str;
64 };
65 
66 static struct ErrCodeToStr g_crashExceptionMap[] = {
67     {CRASH_SIGNAL_EMASKED,      "Signal has been masked." },
68     {CRASH_SIGNAL_EFORK,        "Failed to fork child process." },
69     {CRASH_SIGNAL_ECLONE,       "Failed to clone thread of recycle dump process." },
70     {CRASH_SIGNAL_ESETSTATE,    "Failed to set dump state." },
71     {CRASH_SIGNAL_EINHERITCAP,  "Failed to inherit capabilities." },
72     {CRASH_SIGNAL_EEXECL,       "Failed to execl processdump." },
73     {CRASH_SIGNAL_EWAITEXIT,    "Failed to wait vm process exit." },
74     {CRASH_DUMP_EREADREQ,       "Failed to read dump request." },
75     {CRASH_DUMP_EPARENTPID,     "Failed to check parent pid." },
76     {CRASH_DUMP_EATTACH,        "Failed to attach target process." },
77     {CRASH_DUMP_EWRITEFD,       "Failed to request writen fd." },
78     {CRASH_DUMP_EKILLED,        "Tagert process has been killed." },
79     {CRASH_UNWIND_ECONTEXT,     "Unwind context illegal." },
80     {CRASH_UNWIND_EFRAME,       "Failed to step ark js frame." },
81     {CRASH_UNWIND_ESTACK,       "Stack corruption." },
82     {CRASH_LOG_ESTACKLOS,       "Crash thread stack not found." },
83     {CRASH_LOG_ECHILDSTACK,     "Child thread stack not found." },
84     {CRASH_LOG_EREGLOS,         "Registers not found." },
85     {CRASH_LOG_EMEMLOS,         "Memory not found." },
86     {CRASH_LOG_ESTACKMEMLOS,    "Fault stack not found." },
87     {CRASH_LOG_EMAPLOS,         "Maps not found." },
88     {CRASH_LOG_EHILOGLOS,       "Hilog not found." },
89     {CRASH_UNKNOWN,             "Unknown reason." },
90 };
91 
92 /**
93  * @brief Process crash dump exception description
94 */
95 struct CrashDumpException {
96     /** Crash process id */
97     int32_t pid;
98     /** Crash process user id */
99     int32_t uid;
100     /** event happen time */
101     int64_t time;
102     /** Crash exception error code */
103     int32_t error;
104     /** Crash exception message */
105     char message[LINE_BUF_SIZE];
106 };
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 #endif
112