1800b99b8Sopenharmony_ci/* 2800b99b8Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License. 5800b99b8Sopenharmony_ci * You may obtain a copy of the License at 6800b99b8Sopenharmony_ci * 7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8800b99b8Sopenharmony_ci * 9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and 13800b99b8Sopenharmony_ci * limitations under the License. 14800b99b8Sopenharmony_ci */ 15800b99b8Sopenharmony_ci 16800b99b8Sopenharmony_ci#ifndef DFX_EXCEPTION_H 17800b99b8Sopenharmony_ci#define DFX_EXCEPTION_H 18800b99b8Sopenharmony_ci 19800b99b8Sopenharmony_ci#include <inttypes.h> 20800b99b8Sopenharmony_ci#include "dfx_define.h" 21800b99b8Sopenharmony_ci 22800b99b8Sopenharmony_ci#ifdef __cplusplus 23800b99b8Sopenharmony_ciextern "C" { 24800b99b8Sopenharmony_ci#endif 25800b99b8Sopenharmony_ci 26800b99b8Sopenharmony_cienum CrashExceptionCode : int32_t { 27800b99b8Sopenharmony_ci CRASH_ESUCCESS = 0, /* No error */ 28800b99b8Sopenharmony_ci 29800b99b8Sopenharmony_ci CRASH_SIGNAL_EMASKED = 101, /* Signal has been masked */ 30800b99b8Sopenharmony_ci CRASH_SIGNAL_EFORK, /* Failed to fork child process */ 31800b99b8Sopenharmony_ci CRASH_SIGNAL_ECLONE, /* Failed to clone thread of recycle dump process */ 32800b99b8Sopenharmony_ci CRASH_SIGNAL_ESETSTATE, /* Failed to set dump state */ 33800b99b8Sopenharmony_ci CRASH_SIGNAL_EINHERITCAP, /* Failed to inherit capabilities */ 34800b99b8Sopenharmony_ci CRASH_SIGNAL_EEXECL, /* Failed to execl processdump */ 35800b99b8Sopenharmony_ci CRASH_SIGNAL_EWAITEXIT, /* Failed to wait vm process exit */ 36800b99b8Sopenharmony_ci CRASH_SIGNAL_EREADPIPE, /* Failed to read pipe due to timeout */ 37800b99b8Sopenharmony_ci CRASH_SIGNAL_ECREATEPIPE, /* Failed to init create pipe */ 38800b99b8Sopenharmony_ci CRASH_SIGNAL_EDUMPREQUEST, /* Failed to find symbol to dump request */ 39800b99b8Sopenharmony_ci 40800b99b8Sopenharmony_ci CRASH_DUMP_EREADREQ = 201, /* Failed to read dump request */ 41800b99b8Sopenharmony_ci CRASH_DUMP_EPARENTPID, /* Failed to check parent pid */ 42800b99b8Sopenharmony_ci CRASH_DUMP_EATTACH, /* Failed to attach target process */ 43800b99b8Sopenharmony_ci CRASH_DUMP_EWRITEFD, /* Failed to request writen fd */ 44800b99b8Sopenharmony_ci CRASH_DUMP_EKILLED, /* Tagert process has been killed */ 45800b99b8Sopenharmony_ci CRASH_DUMP_LOCAL_REPORT, /* Local Handler DumpInfo Report*/ 46800b99b8Sopenharmony_ci CRASH_DUMP_EREADPID, /* Failed to read real pid*/ 47800b99b8Sopenharmony_ci 48800b99b8Sopenharmony_ci CRASH_UNWIND_ECONTEXT = 301, /* Unwind context illegal */ 49800b99b8Sopenharmony_ci CRASH_UNWIND_EFRAME, /* Failed to step ark js frame */ 50800b99b8Sopenharmony_ci CRASH_UNWIND_ESTACK, /* Stack corruption */ 51800b99b8Sopenharmony_ci 52800b99b8Sopenharmony_ci CRASH_LOG_ESTACKLOS = 401, /* Crash thread stack not found */ 53800b99b8Sopenharmony_ci CRASH_LOG_ECHILDSTACK, /* Child thread stack not found */ 54800b99b8Sopenharmony_ci CRASH_LOG_EREGLOS, /* Registers not found */ 55800b99b8Sopenharmony_ci CRASH_LOG_EMEMLOS, /* Memory not found */ 56800b99b8Sopenharmony_ci CRASH_LOG_ESTACKMEMLOS, /* Fault stack not found */ 57800b99b8Sopenharmony_ci CRASH_LOG_EMAPLOS, /* Maps not found */ 58800b99b8Sopenharmony_ci CRASH_LOG_EHILOGLOS, /* Hilog not found */ 59800b99b8Sopenharmony_ci CRASH_LOG_ESUMMARYLOS, /* Fault Summary not found */ 60800b99b8Sopenharmony_ci 61800b99b8Sopenharmony_ci CRASH_UNKNOWN = 500, /* Unknown reason */ 62800b99b8Sopenharmony_ci}; 63800b99b8Sopenharmony_ci 64800b99b8Sopenharmony_cistruct ErrCodeToStr { 65800b99b8Sopenharmony_ci /** Crash exception stage code */ 66800b99b8Sopenharmony_ci int32_t errCode; 67800b99b8Sopenharmony_ci /** Crash exception string */ 68800b99b8Sopenharmony_ci const char* str; 69800b99b8Sopenharmony_ci}; 70800b99b8Sopenharmony_ci 71800b99b8Sopenharmony_cistatic struct ErrCodeToStr g_crashExceptionMap[] = { 72800b99b8Sopenharmony_ci {CRASH_SIGNAL_EMASKED, "Signal has been masked." }, 73800b99b8Sopenharmony_ci {CRASH_SIGNAL_EFORK, "Failed to fork child process." }, 74800b99b8Sopenharmony_ci {CRASH_SIGNAL_ECLONE, "Failed to clone thread of recycle dump process." }, 75800b99b8Sopenharmony_ci {CRASH_SIGNAL_ESETSTATE, "Failed to set dump state." }, 76800b99b8Sopenharmony_ci {CRASH_SIGNAL_EINHERITCAP, "Failed to inherit capabilities." }, 77800b99b8Sopenharmony_ci {CRASH_SIGNAL_EEXECL, "Failed to execl processdump." }, 78800b99b8Sopenharmony_ci {CRASH_SIGNAL_EWAITEXIT, "Failed to wait vm process exit." }, 79800b99b8Sopenharmony_ci {CRASH_SIGNAL_EREADPIPE, "Failed to read pipe due to timeout."}, 80800b99b8Sopenharmony_ci {CRASH_SIGNAL_ECREATEPIPE, "Failed to init create pipe."}, 81800b99b8Sopenharmony_ci {CRASH_SIGNAL_EDUMPREQUEST, "Failed to find symbol to dump request."}, 82800b99b8Sopenharmony_ci {CRASH_DUMP_EREADREQ, "Failed to read dump request." }, 83800b99b8Sopenharmony_ci {CRASH_DUMP_EPARENTPID, "Failed to check parent pid." }, 84800b99b8Sopenharmony_ci {CRASH_DUMP_EATTACH, "Failed to attach target process." }, 85800b99b8Sopenharmony_ci {CRASH_DUMP_EWRITEFD, "Failed to request writen fd." }, 86800b99b8Sopenharmony_ci {CRASH_DUMP_EKILLED, "Tagert process has been killed." }, 87800b99b8Sopenharmony_ci {CRASH_DUMP_EREADPID, "Failed to read real pid."}, 88800b99b8Sopenharmony_ci {CRASH_UNWIND_ECONTEXT, "Unwind context illegal." }, 89800b99b8Sopenharmony_ci {CRASH_UNWIND_EFRAME, "Failed to step ark js frame." }, 90800b99b8Sopenharmony_ci {CRASH_UNWIND_ESTACK, "Stack corruption." }, 91800b99b8Sopenharmony_ci {CRASH_LOG_ESTACKLOS, "Crash thread stack not found." }, 92800b99b8Sopenharmony_ci {CRASH_LOG_ECHILDSTACK, "Child thread stack not found." }, 93800b99b8Sopenharmony_ci {CRASH_LOG_EREGLOS, "Registers not found." }, 94800b99b8Sopenharmony_ci {CRASH_LOG_EMEMLOS, "Memory not found." }, 95800b99b8Sopenharmony_ci {CRASH_LOG_ESTACKMEMLOS, "Fault stack not found." }, 96800b99b8Sopenharmony_ci {CRASH_LOG_EMAPLOS, "Maps not found." }, 97800b99b8Sopenharmony_ci {CRASH_LOG_EHILOGLOS, "Hilog not found." }, 98800b99b8Sopenharmony_ci {CRASH_LOG_ESUMMARYLOS, "Fault Summary not found."}, 99800b99b8Sopenharmony_ci {CRASH_UNKNOWN, "Unknown reason." }, 100800b99b8Sopenharmony_ci}; 101800b99b8Sopenharmony_ci 102800b99b8Sopenharmony_ci/** 103800b99b8Sopenharmony_ci * @brief Process crash dump exception description 104800b99b8Sopenharmony_ci*/ 105800b99b8Sopenharmony_cistruct CrashDumpException { 106800b99b8Sopenharmony_ci /** Crash process id */ 107800b99b8Sopenharmony_ci int32_t pid; 108800b99b8Sopenharmony_ci /** Crash process user id */ 109800b99b8Sopenharmony_ci int32_t uid; 110800b99b8Sopenharmony_ci /** event happen time */ 111800b99b8Sopenharmony_ci int64_t time; 112800b99b8Sopenharmony_ci /** Crash exception error code */ 113800b99b8Sopenharmony_ci int32_t error; 114800b99b8Sopenharmony_ci /** Crash exception message */ 115800b99b8Sopenharmony_ci char message[LINE_BUF_SIZE]; 116800b99b8Sopenharmony_ci}; 117800b99b8Sopenharmony_ci 118800b99b8Sopenharmony_ci#ifdef __cplusplus 119800b99b8Sopenharmony_ci} 120800b99b8Sopenharmony_ci#endif 121800b99b8Sopenharmony_ci#endif 122