1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _LIBUNWINDSTACK_DEX_FILES_H 18 #define _LIBUNWINDSTACK_DEX_FILES_H 19 20 #include <stdint.h> 21 22 #include <memory> 23 #include <mutex> 24 #include <string> 25 #include <unordered_map> 26 #include <vector> 27 28 #include <unwindstack/Global.h> 29 #include <unwindstack/Memory.h> 30 31 namespace unwindstack { 32 33 // Forward declarations. 34 class DexFile; 35 class Maps; 36 struct MapInfo; 37 enum ArchEnum : uint8_t; 38 39 class DexFiles : public Global { 40 public: 41 explicit DexFiles(std::shared_ptr<Memory>& memory); 42 DexFiles(std::shared_ptr<Memory>& memory, std::vector<std::string>& search_libs); 43 virtual ~DexFiles(); 44 45 DexFile* GetDexFile(uint64_t dex_file_offset, MapInfo* info); 46 47 void GetMethodInformation(Maps* maps, MapInfo* info, uint64_t dex_pc, std::string* method_name, 48 uint64_t* method_offset); 49 50 private: 51 void Init(Maps* maps); 52 53 bool GetAddr(size_t index, uint64_t* addr); 54 55 uint64_t ReadEntryPtr32(uint64_t addr); 56 57 uint64_t ReadEntryPtr64(uint64_t addr); 58 59 bool ReadEntry32(); 60 61 bool ReadEntry64(); 62 63 bool ReadVariableData(uint64_t ptr_offset) override; 64 65 void ProcessArch() override; 66 67 std::mutex lock_; 68 bool initialized_ = false; 69 std::unordered_map<uint64_t, std::unique_ptr<DexFile>> files_; 70 71 uint64_t entry_addr_ = 0; 72 uint64_t (DexFiles::*read_entry_ptr_func_)(uint64_t) = nullptr; 73 bool (DexFiles::*read_entry_func_)() = nullptr; 74 std::vector<uint64_t> addrs_; 75 }; 76 77 } // namespace unwindstack 78 79 #endif // _LIBUNWINDSTACK_DEX_FILES_H 80