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