• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved.
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 GWPASAN_COLLECTOR_H
16 #define GWPASAN_COLLECTOR_H
17 
18 #include <algorithm>
19 #include <cstdint>
20 #include <cstdio>
21 #include <map>
22 #include <string>
23 #include <vector>
24 #include <regex>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 void WriteGwpAsanLog(char* buf, size_t sz);
30 #ifdef __cplusplus
31 }
32 #endif
33 
34 struct GwpAsanCurrInfo {
35     /** the time of happening fault */
36     uint64_t happenTime;
37     /** the id of current user when fault happened  */
38     int32_t uid;
39     /** the id of process which fault happened*/
40     int32_t pid;
41     /** type of fault */
42     std::string procName;
43     /** name of module which fault occurred */
44     std::string logPath;
45     /** logPath of module which fault occurred */
46     std::string appVersion;
47     /** the reason why fault occurred */
48     std::string errType;
49     /** the summary of fault information */
50     std::string description;
51     /** information about faultlog using <key,value> */
52     std::map<std::string, std::string> sectionMaps;
53 };
54 
55 void ReadGwpAsanRecord(const std::string& gwpAsanBuffer, const std::string& errType);
56 std::string GetNameByPid(int32_t pid);
57 std::string CalcCollectedLogName(const GwpAsanCurrInfo &currInfo);
58 std::string GetErrorTypeFromHwAsanLog(const std::string& hwAsanBuffer);
59 std::string GetErrorTypeFromAsanLog(const std::string& asanBuffer);
60 std::string GetErrorTypeFromLog(const std::string& logBuffer, const std::regex& recordRe,
61     int errTypeField, const std::string& defaultType);
62 
63 #endif // GWPASAN_COLLECTOR_H