• 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 #include "dfx_socket_request.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 enum CrashExceptionCode : int32_t {
28     CRASH_ESUCCESS = 0,                 /* No error */
29 
30     CRASH_SIGNAL_EMASKED = 101,         /* Signal has been masked */
31     CRASH_SIGNAL_EFORK,                 /* Failed to fork child process */
32     CRASH_SIGNAL_ECLONE,                /* Failed to clone thread of recycle dump process */
33     CRASH_SIGNAL_ESETSTATE,             /* Failed to set dump state */
34     CRASH_SIGNAL_EINHERITCAP,           /* Failed to inherit capabilities */
35     CRASH_SIGNAL_EEXECL,                /* Failed to execl processdump */
36     CRASH_SIGNAL_EWAITEXIT,             /* Failed to wait vm process exit */
37     CRASH_SIGNAL_EREADPIPE,             /* Failed to read pipe due to timeout */
38     CRASH_SIGNAL_ECREATEPIPE,           /* Failed to init create pipe */
39     CRASH_SIGNAL_EDUMPREQUEST,          /* Failed to find symbol to dump request */
40     CRASH_SIGNAL_EWAITPIDTIMEOUT,       /* Signal handler waitpid timeout */
41 
42     CRASH_DUMP_EREADREQ = 201,          /* Failed to read dump request */
43     CRASH_DUMP_EPARENTPID,              /* Failed to check parent pid */
44     CRASH_DUMP_EATTACH,                 /* Failed to attach target process */
45     CRASH_DUMP_EWRITEFD,                /* Failed to request writen fd */
46     CRASH_DUMP_EKILLED,                 /* Tagert process has been killed */
47     CRASH_DUMP_LOCAL_REPORT,            /* Local Handler DumpInfo Report*/
48     CRASH_DUMP_EREADPID,                /* Failed to read real pid*/
49 
50     CRASH_UNWIND_ECONTEXT = 301,        /* Unwind context illegal */
51     CRASH_UNWIND_EFRAME,                /* Failed to step ark js frame */
52     CRASH_UNWIND_ESTACK,                /* Stack corruption */
53 
54     CRASH_LOG_ESTACKLOS = 401,          /* Crash thread stack not found */
55     CRASH_LOG_ECHILDSTACK,              /* Child thread stack not found */
56     CRASH_LOG_EREGLOS,                  /* Registers not found */
57     CRASH_LOG_EMEMLOS,                  /* Memory not found */
58     CRASH_LOG_ESTACKMEMLOS,             /* Fault stack not found */
59     CRASH_LOG_EMAPLOS,                  /* Maps not found */
60     CRASH_LOG_EHILOGLOS,                /* Hilog not found */
61     CRASH_LOG_ESUMMARYLOS,              /* Fault Summary not found */
62     CRASH_LOG_EPROCESS_LIFECYCLE,       /* Process lifecycle is null */
63 
64     CRASH_UNKNOWN = 500,                /* Unknown reason */
65 };
66 
67 struct ErrCodeToStr {
68     /** Crash exception stage code */
69     int32_t errCode;
70     /** Crash exception string */
71     const char* str;
72 };
73 
74 static struct ErrCodeToStr g_crashExceptionMap[] = {
75     {CRASH_SIGNAL_EMASKED,      "Signal has been masked." },
76     {CRASH_SIGNAL_EFORK,        "Failed to fork child process." },
77     {CRASH_SIGNAL_ECLONE,       "Failed to clone thread of recycle dump process." },
78     {CRASH_SIGNAL_ESETSTATE,    "Failed to set dump state." },
79     {CRASH_SIGNAL_EINHERITCAP,  "Failed to inherit capabilities." },
80     {CRASH_SIGNAL_EEXECL,       "Failed to execl processdump." },
81     {CRASH_SIGNAL_EWAITEXIT,    "Failed to wait vm process exit." },
82     {CRASH_SIGNAL_EREADPIPE,    "Failed to read pipe due to timeout."},
83     {CRASH_SIGNAL_ECREATEPIPE,  "Failed to init create pipe."},
84     {CRASH_SIGNAL_EDUMPREQUEST, "Failed to find symbol to dump request."},
85     {CRASH_SIGNAL_EWAITPIDTIMEOUT, "Signal handler waitpid timeout"},
86     {CRASH_DUMP_EREADREQ,       "Failed to read dump request." },
87     {CRASH_DUMP_EPARENTPID,     "Failed to check parent pid." },
88     {CRASH_DUMP_EATTACH,        "Failed to attach target process." },
89     {CRASH_DUMP_EWRITEFD,       "Failed to request writen fd." },
90     {CRASH_DUMP_EKILLED,        "Tagert process has been killed." },
91     {CRASH_DUMP_EREADPID,       "Failed to read real pid."},
92     {CRASH_UNWIND_ECONTEXT,     "Unwind context illegal." },
93     {CRASH_UNWIND_EFRAME,       "Failed to step ark js frame." },
94     {CRASH_UNWIND_ESTACK,       "Stack corruption." },
95     {CRASH_LOG_ESTACKLOS,       "Crash thread stack not found." },
96     {CRASH_LOG_ECHILDSTACK,     "Child thread stack not found." },
97     {CRASH_LOG_EREGLOS,         "Registers not found." },
98     {CRASH_LOG_EMEMLOS,         "Memory not found." },
99     {CRASH_LOG_ESTACKMEMLOS,    "Fault stack not found." },
100     {CRASH_LOG_EMAPLOS,         "Maps not found." },
101     {CRASH_LOG_EHILOGLOS,       "Hilog not found." },
102     {CRASH_LOG_ESUMMARYLOS,     "Fault Summary not found."},
103     {CRASH_UNKNOWN,             "Unknown reason." },
104 };
105 
106 /**
107  * @brief Process crash dump exception description
108 */
109 typedef struct CrashDumpException {
110     /** request data head **/
111     RequestDataHead head;
112     /** Crash process id */
113     int32_t pid;
114     /** Crash process user id */
115     int32_t uid;
116     /** event happen time */
117     int64_t time;
118     /** Crash exception error code */
119     int32_t error;
120     /** Crash exception message */
121     char message[LINE_BUF_SIZE];
122 } __attribute__((packed)) CrashDumpException;;
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 #endif
128