1 //===-- ModuleCache.h -------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLDB_TARGET_MODULECACHE_H 11 #define LLDB_TARGET_MODULECACHE_H 12 13 #include "lldb/lldb-forward.h" 14 #include "lldb/lldb-types.h" 15 16 #include "lldb/Host/File.h" 17 #include "lldb/Utility/FileSpec.h" 18 #include "lldb/Utility/Status.h" 19 20 #include <functional> 21 #include <string> 22 #include <unordered_map> 23 24 namespace lldb_private { 25 26 class Module; 27 class UUID; 28 29 //---------------------------------------------------------------------- 30 /// @class ModuleCache ModuleCache.h "lldb/Target/ModuleCache.h" 31 /// A module cache class. 32 /// 33 /// Caches locally modules that are downloaded from remote targets. Each 34 /// cached module maintains 2 views: 35 /// - UUID view: 36 /// /${CACHE_ROOT}/${PLATFORM_NAME}/.cache/${UUID}/${MODULE_FILENAME} 37 /// - Sysroot view: 38 /// /${CACHE_ROOT}/${PLATFORM_NAME}/${HOSTNAME}/${MODULE_FULL_FILEPATH} 39 /// 40 /// UUID views stores a real module file, whereas Sysroot view holds a symbolic 41 /// link to UUID-view file. 42 /// 43 /// Example: 44 /// UUID view : 45 /// /tmp/lldb/remote- 46 /// linux/.cache/30C94DC6-6A1F-E951-80C3-D68D2B89E576-D5AE213C/libc.so.6 47 /// Sysroot view: /tmp/lldb/remote-linux/ubuntu/lib/x86_64-linux-gnu/libc.so.6 48 //---------------------------------------------------------------------- 49 50 class ModuleCache { 51 public: 52 using ModuleDownloader = 53 std::function<Status(const ModuleSpec &, const FileSpec &)>; 54 using SymfileDownloader = 55 std::function<Status(const lldb::ModuleSP &, const FileSpec &)>; 56 57 Status GetAndPut(const FileSpec &root_dir_spec, const char *hostname, 58 const ModuleSpec &module_spec, 59 const ModuleDownloader &module_downloader, 60 const SymfileDownloader &symfile_downloader, 61 lldb::ModuleSP &cached_module_sp, bool *did_create_ptr); 62 63 private: 64 Status Put(const FileSpec &root_dir_spec, const char *hostname, 65 const ModuleSpec &module_spec, const FileSpec &tmp_file, 66 const FileSpec &target_file); 67 68 Status Get(const FileSpec &root_dir_spec, const char *hostname, 69 const ModuleSpec &module_spec, lldb::ModuleSP &cached_module_sp, 70 bool *did_create_ptr); 71 72 std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules; 73 }; 74 75 } // namespace lldb_private 76 77 #endif // utility_ModuleCache_h_ 78