]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Target/ModuleCache.h
Vendor import of lldb trunk r303197:
[FreeBSD/FreeBSD.git] / include / lldb / Target / 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 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 /// @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:
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-linux/.cache/30C94DC6-6A1F-E951-80C3-D68D2B89E576-D5AE213C/libc.so.6
46 /// Sysroot view: /tmp/lldb/remote-linux/ubuntu/lib/x86_64-linux-gnu/libc.so.6
47 //----------------------------------------------------------------------
48
49 class ModuleCache {
50 public:
51   using ModuleDownloader =
52       std::function<Status(const ModuleSpec &, const FileSpec &)>;
53   using SymfileDownloader =
54       std::function<Status(const lldb::ModuleSP &, const FileSpec &)>;
55
56   Status GetAndPut(const FileSpec &root_dir_spec, const char *hostname,
57                    const ModuleSpec &module_spec,
58                    const ModuleDownloader &module_downloader,
59                    const SymfileDownloader &symfile_downloader,
60                    lldb::ModuleSP &cached_module_sp, bool *did_create_ptr);
61
62 private:
63   Status Put(const FileSpec &root_dir_spec, const char *hostname,
64              const ModuleSpec &module_spec, const FileSpec &tmp_file,
65              const FileSpec &target_file);
66
67   Status Get(const FileSpec &root_dir_spec, const char *hostname,
68              const ModuleSpec &module_spec, lldb::ModuleSP &cached_module_sp,
69              bool *did_create_ptr);
70
71   std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules;
72 };
73
74 } // namespace lldb_private
75
76 #endif // utility_ModuleCache_h_