[Lldb-commits] [PATCH] Add Utility/ModuleCache class and integrate it with PlatformGDBRemoteServer - in order to allow modules caching from remote targets.

Greg Clayton clayborg at gmail.com
Tue Mar 3 10:39:06 PST 2015

See my inline comments and let me know what you think. I think it would be nice if we had a global directory that we used for all locally cached files. The module cache would be writeable, and if someone specifies a system root with "platform select --sysroot=/path/to/read/only/root" the system root would be read only. We then cache files locally into /tmp/<platform-name>/<hostname>. We would store a global repository in /tmp/<platform-name> where we store the value using the UUID:


Then in the host specific directory we could symlink to this:


The above two files could be symlinks to the same file. This way if you are connecting to a bunch of somewhat related linux distros, you might be able to share many files between then in your local cache.

So the main ideas here are:
1 - allow a read only sysroot to be specified with --sysroot when selecting the platform, or specify it after the fact
2 - allow a writeable cache that is auto generated for all platforms, but only if they opt into calling Platform::GetCachedSharedModule()
3 - implement a global file cache per platform that each hostname can then symlink to

Let me know what you think.

Comment at: include/lldb/Core/ModuleSpec.h:17
@@ -16,2 +16,3 @@
 #include "lldb/Host/FileSpec.h"
+#include "lldb/Host/Mutex.h"
 #include "lldb/Target/PathMappingList.h"
Remove this?

Comment at: source/Plugins/Platform/POSIX/PlatformPOSIX.h:35-40
@@ +34,8 @@
+    lldb_private::Error
+    GetSharedModule (const lldb_private::ModuleSpec &module_spec,
+                     lldb::ModuleSP &module_sp,
+                     const lldb_private::FileSpecList *module_search_paths_ptr,
+                     lldb::ModuleSP *old_module_sp_ptr,
+                     bool *did_create_ptr) override;
Move this to Platform.h and rename the function to be GetCachedSharedModule? Then all platforms can take advantage of the local cache. It would be nice if we can create a global platform cache that just works for all platforms. The Platform::GetCachedSharedModule() would check the local cache directory for the module first and use it from there and if it isn't there download it via the Platform::GetFile() and update the cache?

Comment at: source/Plugins/Platform/POSIX/PlatformPOSIX.h:127-128
@@ +126,4 @@
+    virtual void
+    SetLocalCacheDirectory (const char* local) override;
Maybe we should just auto compute this path using the current platform name by picking a cache directory from the platform name, hostname, etc. Lets say we have a new setting:

(lldb) settings set platform.file-cache-directory /tmp

This setting would default to the current temporary directory, but it could be changed if desired so that it never goes away (some path into your home directory).

Then we can encode the cache as:


Comment at: source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h:234-246
@@ -215,1 +233,15 @@
+    struct ModuleInfo
+    {
+        lldb_private::UUID m_uuid;
+        lldb_private::ArchSpec m_arch;
+        uint64_t file_offset;
+        uint64_t file_size;
+        ModuleInfo ()
+            : file_offset (0),
+              file_size (0)
+        {
+        }
+    };
Use lldb_private::ModuleSpec instead of a new class?

Comment at: source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h:262-276
@@ -228,2 +261,17 @@
+    void InitModuleCache (const char* local_cache_dir);
+    bool
+    GetModuleInfo (const lldb_private::ModuleSpec& module_spec, ModuleInfo& module_info);
+    lldb_private::Error
+    DownloadModuleSlice (const lldb_private::FileSpec& src_file_spec,
+                         const uint64_t src_offset,
+                         const uint64_t src_size,
+                         const lldb_private::FileSpec& dst_file_spec);
+    bool
+    GetFileFromLocalCache (const lldb_private::ModuleSpec& module_spec,
+                           lldb_private::FileSpec &cached_file_spec);
Can we move this into Platform.h and just use virtual API calls to implement this for all platforms?



More information about the lldb-commits mailing list