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 CRASH_EXCEPTION_H 17 #define CRASH_EXCEPTION_H 18 19 #include <cinttypes> 20 #include <string> 21 #include "dfx_exception.h" 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 26 /** 27 * @brief fault log file check keyword info 28 */ 29 struct LogValidCheckInfo { 30 /** key words for check */ 31 std::string key; 32 /** regex rule */ 33 std::string regx; 34 /** offset of the key words in file */ 35 std::string::size_type start; 36 /** error code when file invalid */ 37 int32_t errCode; 38 }; 39 40 /** 41 * @brief get current time 42 */ 43 uint64_t GetTimeMillisec(void); 44 45 /** 46 * @brief save crashed process info 47 */ 48 void SetCrashProcInfo(std::string& name, int32_t pid, int32_t uid); 49 50 /** 51 * @brief report crash to sysevent 52 */ 53 void ReportCrashException(const char* pName, int32_t pid, int32_t uid, int32_t errCode); 54 55 /** 56 * @brief report crash to sysevent 57 */ 58 void ReportCrashException(std::string name, int32_t pid, int32_t uid, int32_t errCode); 59 60 /** 61 * @brief report crash unwinder error to sysevent 62 */ 63 void ReportUnwinderException(uint16_t unwError); 64 65 /** 66 * @brief Check fault log available 67 * 68 * @return if available return CrashExceptionCode::CRASH_ESUCCESS, otherwise return errCode 69 */ 70 int32_t CheckCrashLogValid(std::string& file); 71 72 /** 73 * @brief Check summary valid,The valid is if the string contains stack information for the first three frames 74 * 75 * @param summary Stack information in the fault info 76 * @return if check valid return true, otherwise return false 77 */ 78 bool CheckFaultSummaryValid(const std::string &summary); 79 } 80 } 81 #endif