• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 HIEBPF_MAPS_INFO_H_
17 #define HIEBPF_MAPS_INFO_H_
18 
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 namespace OHOS {
24 namespace Developtools {
25 namespace Hiebpf {
26 class MapsInfo {
27 public:
28     struct MapsItem {
29         uint64_t start_ = 0;
30         uint64_t end_ = 0;
31         uint32_t offset_ = 0;
32         uint32_t pid_ = 0;
33         std::string fileName_;
34     };
35 
MapsInfo()36     MapsInfo() {};
~MapsInfo()37     ~MapsInfo() {};
38 
IsCached(uint32_t pid)39     bool IsCached(uint32_t pid)
40     {
41         return (pids_.find(pid) != pids_.end());
42     }
43 
CachePid(uint32_t pid)44     void CachePid(uint32_t pid)
45     {
46         pids_.insert(pid);
47     }
48 
RemovePid(uint32_t pid)49     void RemovePid(uint32_t pid)
50     {
51         if (auto item = pids_.find(pid); item != pids_.end()) {
52             pids_.erase(item);
53         }
54     }
55 
56     void GetMaps(uint32_t pid, std::vector<MapsItem> &mapsItems);
57     uint32_t GetBinary(const MapsItem &map, std::vector<uint8_t> &buf);
58 
59 private:
60     void ParseMapsLine(uint32_t pid, std::string &line, std::vector<MapsItem> &maps);
61     bool IsLegalFileName(const std::string &fileName);
62 
63     std::set<uint32_t> pids_;
64 };
65 } // namespace Hiebpf
66 } // namespace Developtools
67 } // namespace OHOS
68 #endif // HIEBPF_MAPS_INFO_H_