1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2022. 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  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 #ifndef EBPF_COVERTER_H
16 #define EBPF_COVERTER_H
17 
18 #include <sstream>
19 #include <map>
20 #include <vector>
21 
22 #include "ebpf_std_type.h"
23 
24 namespace OHOS {
25 namespace EBPF_TOOLS {
26 class EbpfConverter {
27 public:
28     EbpfConverter(const std::string& inputPath, const std::string& outPath);
29     virtual ~EbpfConverter();
30     void StartParsing();
31 
32 private:
33     bool Read(void* buffer, size_t size);
34     void EventFsParsing();
35     void EventMapsParsing();
36     void SymbolInfoParsing();
37     void EventMemParsing();
38     void EventStrParsing();
39     void EventBIOParsing();
40     std::pair<std::string, std::vector<std::string>> GetSymbolInfo(uint64_t pid, uint64_t ip);
41 public:
42     static std::pair<bool, std::string> CheckNotExistsFilePath(const std::string& filePath);
43 
44 private:
45     std::stringstream outData_;
46     std::string inputPath_;
47     std::string outputPath_;
48     int32_t fileSize_ { 0 };
49     int32_t fd_ { -1 };
50     std::vector<EventStr> str_;
51     std::map<std::string, Record> record_;
52     std::map<std::string, SymbolInfo> symbolInfo_;
53     std::map<uint32_t, std::vector<EventMaps>> maps_;
54     std::map<uint64_t, uint64_t> vAddr_;
55 };
56 } // EBPF_TOOLS
57 } // OHOS
58 
59 #endif // EBPF_COVERTER_H