xref: /NextBSD/contrib/llvm/tools/lldb/source/Utility/ModuleCache.h (revision 84d351007654069f9643c8e4b4802a7f5f08ee42)
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 utility_ModuleCache_h_
11 #define utility_ModuleCache_h_
12 
13 #include "lldb/lldb-types.h"
14 #include "lldb/lldb-forward.h"
15 
16 #include "lldb/Core/Error.h"
17 #include "lldb/Host/File.h"
18 #include "lldb/Host/FileSpec.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 "Utility/ModuleCache.h"
31 /// @brief A module cache class.
32 ///
33 /// Caches locally modules that are downloaded from remote targets.
34 /// Each cached module maintains 2 views:
35 ///  - UUID view:    /${CACHE_ROOT}/${PLATFORM_NAME}/.cache/${UUID}/${MODULE_FILENAME}
36 ///  - Sysroot view: /${CACHE_ROOT}/${PLATFORM_NAME}/${HOSTNAME}/${MODULE_FULL_FILEPATH}
37 ///
38 /// UUID views stores a real module file, whereas Sysroot view holds a symbolic
39 /// link to UUID-view file.
40 ///
41 /// Example:
42 /// UUID view   : /tmp/lldb/remote-linux/.cache/30C94DC6-6A1F-E951-80C3-D68D2B89E576-D5AE213C/libc.so.6
43 /// Sysroot view: /tmp/lldb/remote-linux/ubuntu/lib/x86_64-linux-gnu/libc.so.6
44 //----------------------------------------------------------------------
45 
46 class ModuleCache
47 {
48 public:
49     using Downloader = std::function<Error (const ModuleSpec&, const FileSpec&)>;
50 
51     Error
52     GetAndPut(const FileSpec &root_dir_spec,
53               const char *hostname,
54               const ModuleSpec &module_spec,
55               const Downloader &downloader,
56               lldb::ModuleSP &cached_module_sp,
57               bool *did_create_ptr);
58 
59 private:
60     Error
61     Put (const FileSpec &root_dir_spec,
62          const char *hostname,
63          const ModuleSpec &module_spec,
64          const FileSpec &tmp_file);
65 
66     Error
67     Get (const FileSpec &root_dir_spec,
68          const char *hostname,
69          const ModuleSpec &module_spec,
70          lldb::ModuleSP &cached_module_sp,
71          bool *did_create_ptr);
72 
73     std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules;
74 };
75 
76 } // namespace lldb_private
77 
78 #endif  // utility_ModuleCache_h_
79