1 /* 2 * Copyright (c) 2023-2024 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 DFX_MAPS_H 17 #define DFX_MAPS_H 18 19 #include <mutex> 20 #include <string> 21 #include <vector> 22 #include "dfx_map.h" 23 #include "string_util.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 class DfxMaps { 28 public: 29 DfxMaps() = default; 30 ~DfxMaps() = default; 31 static const std::string GetMapsFile(pid_t pid = 0); 32 static std::shared_ptr<DfxMaps> Create(pid_t pid = 0); 33 static bool Create(const pid_t pid, std::vector<std::shared_ptr<DfxMap>>& maps, std::vector<int>& mapIndex); 34 static std::shared_ptr<DfxMaps> Create(const pid_t pid, const std::string& path, bool enableMapIndex = false); 35 static bool IsLegalMapItem(const std::string& name); 36 static void FormatMapName(pid_t pid, std::string& mapName); 37 static void UnFormatMapName(std::string& mapName); 38 39 void AddMap(std::shared_ptr<DfxMap> map, bool enableMapIndex = false); 40 void Sort(bool less = true); 41 bool FindMapByAddr(uintptr_t addr, std::shared_ptr<DfxMap>& map) const; 42 bool FindMapByFileInfo(std::string name, uint64_t offset, std::shared_ptr<DfxMap>& map) const; 43 bool FindMapsByName(std::string name, std::vector<std::shared_ptr<DfxMap>>& maps) const; GetMaps()44 const std::vector<std::shared_ptr<DfxMap>>& GetMaps() const { return maps_; } GetMapIndexVec()45 const std::vector<int>& GetMapIndexVec() const { return mapIndex_; } GetMapsSize()46 size_t GetMapsSize() const { return maps_.size(); } 47 bool GetStackRange(uintptr_t& bottom, uintptr_t& top); 48 49 bool IsArkExecutedMap(uintptr_t addr); 50 uint32_t filePathId_ {0}; // for maps item filePath id 51 protected: 52 std::vector<std::shared_ptr<DfxMap>> maps_; 53 std::vector<int> mapIndex_; 54 private: 55 uintptr_t stackBottom_ = 0; 56 uintptr_t stackTop_ = 0; 57 }; 58 } // namespace HiviewDFX 59 } // namespace OHOS 60 61 #endif 62