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