• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 /* This files contains feader file of maps module. */
17 
18 #ifndef DFX_MAPS_H
19 #define DFX_MAPS_H
20 
21 #include <string>
22 #include <sys/types.h>
23 #include "iosfwd"
24 #include "dfx_elf.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 class DfxElfMap {
29 public:
30     DfxElfMap() = default;
31     ~DfxElfMap() = default;
32     static std::shared_ptr<DfxElfMap> Create(const std::string mapInfo, int size);
33     bool IsValid();
34     std::string PrintMap();
35 
36     uint64_t GetMapBegin() const;
37     uint64_t GetMapEnd() const;
38     uint64_t GetMapOffset() const;
39     std::string GetMapPerms() const;
40     std::string GetMapPath() const;
41     std::shared_ptr<DfxElf> GetMapImage() const;
42 
43     void SetMapBegin(uint64_t begin);
44     void SetMapEnd(uint64_t end);
45     void SetMapOffset(uint64_t offset);
46     void SetMapPerms(const std::string perms, int size);
47     void SetMapPath(const std::string path);
48     void SetMapImage(std::shared_ptr<DfxElf> image);
49 
50 private:
51     uint64_t begin_ = 0;
52     uint64_t end_ = 0;
53     uint64_t offset_ = 0;
54     std::string perms_; // 5:rwxp
55     std::string path_;
56     std::shared_ptr<DfxElf> image_;
57 };
58 
59 class DfxElfMaps {
60 public:
61     DfxElfMaps() = default;
62     ~DfxElfMaps() = default;
63     static std::shared_ptr<DfxElfMaps> Create(pid_t pid);
64     void InsertMapToElfMaps(std::shared_ptr<DfxElfMap> map);
65     std::shared_ptr<DfxElf> GetMapElf(std::shared_ptr<DfxElfMap> map);
66     bool FindMapByPath(const std::string path, std::shared_ptr<DfxElfMap>& map) const;
67     bool FindMapByAddr(uintptr_t address, std::shared_ptr<DfxElfMap>& map) const;
68 
69     std::vector<std::shared_ptr<DfxElfMap>> GetValues() const;
70     bool CheckPcIsValid(uint64_t pc) const;
71 
72 private:
73     std::vector<std::shared_ptr<DfxElfMap>> maps_;
74 };
75 } // namespace HiviewDFX
76 } // namespace OHOS
77 
78 #endif
79