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: DfxSignal(const int32_t signal)27 explicit DfxSignal(const int32_t signal) : signal_(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; GetSignal()35 int32_t GetSignal() const 36 { 37 return signal_; 38 } 39 40 private: 41 DfxSignal() = delete; 42 43 static std::string FormatSignalName(const int32_t signal); 44 static std::string FormatCodeName(const int32_t signal, const int32_t signalCode); 45 static std::string FormatSIGBUSCodeName(const int32_t signalCode); 46 static std::string FormatSIGILLCodeName(const int32_t signalCode); 47 static std::string FormatSIGFPECodeName(const int32_t signalCode); 48 static std::string FormatSIGSEGVCodeName(const int32_t signalCode); 49 static std::string FormatSIGTRAPCodeName(const int32_t signalCode); 50 static std::string FormatCommonSignalCodeName(const int32_t signalCode); 51 private: 52 int32_t signal_ = 0; 53 }; 54 } // namespace Dfx 55 } // namespace OHOS 56 #endif 57