1 | //===-- ModuleCache.h -------------------------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLDB_TARGET_MODULECACHE_H |
10 | #define LLDB_TARGET_MODULECACHE_H |
11 | |
12 | #include "lldb/lldb-forward.h" |
13 | #include "lldb/lldb-types.h" |
14 | |
15 | #include "lldb/Host/File.h" |
16 | #include "lldb/Utility/FileSpec.h" |
17 | #include "lldb/Utility/Status.h" |
18 | |
19 | #include <functional> |
20 | #include <string> |
21 | #include <unordered_map> |
22 | |
23 | namespace lldb_private { |
24 | |
25 | class Module; |
26 | class UUID; |
27 | |
28 | /// \class ModuleCache ModuleCache.h "lldb/Target/ModuleCache.h" |
29 | /// A module cache class. |
30 | /// |
31 | /// Caches locally modules that are downloaded from remote targets. Each |
32 | /// cached module maintains 2 views: |
33 | /// - UUID view: |
34 | /// /${CACHE_ROOT}/${PLATFORM_NAME}/.cache/${UUID}/${MODULE_FILENAME} |
35 | /// - Sysroot view: |
36 | /// /${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 : |
43 | /// /tmp/lldb/remote- |
44 | /// linux/.cache/30C94DC6-6A1F-E951-80C3-D68D2B89E576-D5AE213C/libc.so.6 |
45 | /// Sysroot view: /tmp/lldb/remote-linux/ubuntu/lib/x86_64-linux-gnu/libc.so.6 |
46 | |
47 | class ModuleCache { |
48 | public: |
49 | using ModuleDownloader = |
50 | std::function<Status(const ModuleSpec &, const FileSpec &)>; |
51 | using SymfileDownloader = |
52 | std::function<Status(const lldb::ModuleSP &, const FileSpec &)>; |
53 | |
54 | Status GetAndPut(const FileSpec &root_dir_spec, const char *hostname, |
55 | const ModuleSpec &module_spec, |
56 | const ModuleDownloader &module_downloader, |
57 | const SymfileDownloader &symfile_downloader, |
58 | lldb::ModuleSP &cached_module_sp, bool *did_create_ptr); |
59 | |
60 | private: |
61 | Status Put(const FileSpec &root_dir_spec, const char *hostname, |
62 | const ModuleSpec &module_spec, const FileSpec &tmp_file, |
63 | const FileSpec &target_file); |
64 | |
65 | Status Get(const FileSpec &root_dir_spec, const char *hostname, |
66 | const ModuleSpec &module_spec, lldb::ModuleSP &cached_module_sp, |
67 | bool *did_create_ptr); |
68 | |
69 | std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules; |
70 | }; |
71 | |
72 | } // namespace lldb_private |
73 | |
74 | #endif // LLDB_TARGET_MODULECACHE_H |
75 | |