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 * 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_ELF_SYMBOL_INFO_H_ 17 #define HIEBPF_ELF_SYMBOL_INFO_H_ 18 19 #include <set> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS { 24 namespace Developtools { 25 namespace Hiebpf { 26 class ElfSymbolInfo { 27 public: 28 struct ElfSymbolTable { 29 uint64_t textVaddr_; 30 uint32_t textOffset_; 31 uint32_t symEntSize_; 32 std::vector<uint8_t> strTable_; 33 std::vector<uint8_t> symTable_; 34 std::string fileName_; 35 }; 36 ElfSymbolInfo()37 ElfSymbolInfo() {}; ~ElfSymbolInfo()38 ~ElfSymbolInfo() {}; 39 IsCached(const std::string &fileName)40 bool IsCached(const std::string &fileName) 41 { 42 return (fileNames_.find(fileName) != fileNames_.end()); 43 } 44 CacheFileName(const std::string &fileName)45 void CacheFileName(const std::string &fileName) 46 { 47 fileNames_.insert(fileName); 48 } 49 50 bool GetSymbolTable(const std::string &fileName, ElfSymbolTable &symbolTable); 51 uint32_t GetBinary(const ElfSymbolTable &symbolTable, std::vector<uint8_t> &buf); 52 53 private: 54 std::set<std::string> fileNames_; 55 }; 56 } // namespace Hiebpf 57 } // namespace Developtools 58 } // namespace OHOS 59 #endif // HIEBPF_ELF_SYMBOL_INFO_H_