]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Utility/ModuleCache.h
MFV r311899:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Utility / ModuleCache.h
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 ModuleDownloader = std::function<Error (const ModuleSpec&, const FileSpec&)>;
50     using SymfileDownloader = std::function<Error (const lldb::ModuleSP&, const FileSpec&)>;
51
52     Error
53     GetAndPut(const FileSpec &root_dir_spec,
54               const char *hostname,
55               const ModuleSpec &module_spec,
56               const ModuleDownloader &module_downloader,
57               const SymfileDownloader &symfile_downloader,
58               lldb::ModuleSP &cached_module_sp,
59               bool *did_create_ptr);
60
61 private:
62     Error
63     Put (const FileSpec &root_dir_spec,
64          const char *hostname,
65          const ModuleSpec &module_spec,
66          const FileSpec &tmp_file,
67          const FileSpec &target_file);
68
69     Error
70     Get (const FileSpec &root_dir_spec,
71          const char *hostname,
72          const ModuleSpec &module_spec,
73          lldb::ModuleSP &cached_module_sp,
74          bool *did_create_ptr);
75
76     std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules;
77 };
78
79 } // namespace lldb_private
80
81 #endif  // utility_ModuleCache_h_