1 /* 2 * Copyright (c) 2021-2023 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_SIGNAL_H 17 #define DFX_SIGNAL_H 18 19 #include <csignal> 20 #include <cstdint> 21 #include <string> 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 class DfxSignal { 26 public: 27 explicit DfxSignal(const int32_t signal); 28 ~DfxSignal() = default; 29 30 static std::string PrintSignal(const siginfo_t &info); 31 32 bool IsAvailable() const; 33 bool IsAddrAvailable() const; 34 bool IsPidAvailable() const; 35 int32_t GetSignal() const; 36 private: 37 DfxSignal() = delete; 38 39 static std::string FormatSignalName(const int32_t signal); 40 static std::string FormatCodeName(const int32_t signal, const int32_t signalCode); 41 static std::string FormatSIGBUSCodeName(const int32_t signalCode); 42 static std::string FormatSIGILLCodeName(const int32_t signalCode); 43 static std::string FormatSIGFPECodeName(const int32_t signalCode); 44 static std::string FormatSIGSEGVCodeName(const int32_t signalCode); 45 static std::string FormatSIGTRAPCodeName(const int32_t signalCode); 46 static std::string FormatCommonSignalCodeName(const int32_t signalCode); 47 private: 48 int32_t signal_ = 0; 49 }; 50 } // namespace Dfx 51 } // namespace OHOS 52 #endif 53