1 /*
2  * Copyright (c) 2021 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 #ifndef FAULTLOGGER_SIGNAL_INFO_H
16 #define FAULTLOGGER_SIGNAL_INFO_H
17 #include <csignal>
18 #include <sstream>
19 #include <string>
20 namespace OHOS {
21 namespace HiviewDFX {
22 class SignalInfo {
23 public:
24     static void FormatSignalInfo(std::stringstream &ss, const siginfo_t &siginfo);
25 
26 private:
27     static bool IsSignalInfoAvaliable(int32_t signal);
28     static bool IsSignalAddrAvaliable(int32_t signal);
29     static bool IsSignalPidAvaliable(int32_t sigCode);
30     static std::string FormatSignalName(int32_t signal);
31     static std::string FormatCodeName(int32_t signal, int32_t signalCode);
32 
33     static std::string FormatSIGBUSCodeName(int32_t signalCode);
34     static std::string FormatSIGILLCodeName(int32_t signalCode);
35     static std::string FormatSIGFPECodeName(int32_t signalCode);
36     static std::string FormatSIGSEGVCodeName(int32_t signalCode);
37     static std::string FormatSIGTRAPCodeName(int32_t signalCode);
38     static std::string FormatCommonSignalCodeName(int32_t signalCode);
39 };
40 }  // namespace HiviewDFX
41 }  // namespace OHOS
42 #endif  // FAULTLOGGER_SIGNAL_INFO_H