forked from OSchip/llvm-project
Make ModuleCache::Get to return instantiated ModuleSP instance so already created in-memory instance can be returned instead of creating a new one.
http://reviews.llvm.org/D8270 llvm-svn: 232075
This commit is contained in:
parent
285dd51b7b
commit
eda270ee99
|
@ -1134,8 +1134,8 @@ class ModuleCache;
|
||||||
const FileSpec& dst_file_spec);
|
const FileSpec& dst_file_spec);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GetFileFromLocalCache (const ModuleSpec& module_spec,
|
GetModuleFromLocalCache (const ModuleSpec& module_spec,
|
||||||
FileSpec &cached_file_spec);
|
lldb::ModuleSP &module_sp);
|
||||||
|
|
||||||
FileSpec GetModuleCacheRoot ();
|
FileSpec GetModuleCacheRoot ();
|
||||||
|
|
||||||
|
|
|
@ -1756,22 +1756,12 @@ bool
|
||||||
Platform::GetCachedSharedModule (const ModuleSpec &module_spec,
|
Platform::GetCachedSharedModule (const ModuleSpec &module_spec,
|
||||||
lldb::ModuleSP &module_sp)
|
lldb::ModuleSP &module_sp)
|
||||||
{
|
{
|
||||||
FileSpec cached_file_spec;
|
return (m_module_cache && GetModuleFromLocalCache (module_spec, module_sp));
|
||||||
if (m_module_cache && GetFileFromLocalCache (module_spec, cached_file_spec))
|
|
||||||
{
|
|
||||||
auto cached_module_spec (module_spec);
|
|
||||||
cached_module_spec.GetFileSpec () = cached_file_spec;
|
|
||||||
cached_module_spec.GetPlatformFileSpec () = module_spec.GetFileSpec ();
|
|
||||||
module_sp.reset (new Module (cached_module_spec));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Platform::GetFileFromLocalCache (const ModuleSpec& module_spec,
|
Platform::GetModuleFromLocalCache (const ModuleSpec& module_spec,
|
||||||
FileSpec &cached_file_spec)
|
lldb::ModuleSP &module_sp)
|
||||||
{
|
{
|
||||||
Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PLATFORM);
|
Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PLATFORM);
|
||||||
|
|
||||||
|
@ -1783,9 +1773,8 @@ Platform::GetFileFromLocalCache (const ModuleSpec& module_spec,
|
||||||
// Check local cache for a module.
|
// Check local cache for a module.
|
||||||
auto error = m_module_cache->Get (GetModuleCacheRoot (),
|
auto error = m_module_cache->Get (GetModuleCacheRoot (),
|
||||||
GetHostname (),
|
GetHostname (),
|
||||||
resolved_module_spec.GetUUID (),
|
resolved_module_spec,
|
||||||
resolved_module_spec.GetFileSpec (),
|
module_sp);
|
||||||
cached_file_spec);
|
|
||||||
if (error.Success ())
|
if (error.Success ())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -1825,8 +1814,7 @@ Platform::GetFileFromLocalCache (const ModuleSpec& module_spec,
|
||||||
// Put downloaded file into local module cache.
|
// Put downloaded file into local module cache.
|
||||||
error = m_module_cache->Put (GetModuleCacheRoot (),
|
error = m_module_cache->Put (GetModuleCacheRoot (),
|
||||||
GetHostname (),
|
GetHostname (),
|
||||||
resolved_module_spec.GetUUID (),
|
resolved_module_spec,
|
||||||
resolved_module_spec.GetFileSpec (),
|
|
||||||
tmp_download_file_spec);
|
tmp_download_file_spec);
|
||||||
if (error.Fail ())
|
if (error.Fail ())
|
||||||
{
|
{
|
||||||
|
@ -1839,9 +1827,8 @@ Platform::GetFileFromLocalCache (const ModuleSpec& module_spec,
|
||||||
|
|
||||||
error = m_module_cache->Get (GetModuleCacheRoot (),
|
error = m_module_cache->Get (GetModuleCacheRoot (),
|
||||||
GetHostname (),
|
GetHostname (),
|
||||||
resolved_module_spec.GetUUID (),
|
resolved_module_spec,
|
||||||
resolved_module_spec.GetFileSpec (),
|
module_sp);
|
||||||
cached_file_spec);
|
|
||||||
return error.Success ();
|
return error.Success ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "ModuleCache.h"
|
#include "ModuleCache.h"
|
||||||
|
|
||||||
#include "lldb/Core/Module.h"
|
#include "lldb/Core/Module.h"
|
||||||
|
#include "lldb/Core/ModuleSpec.h"
|
||||||
#include "lldb/Host/FileSystem.h"
|
#include "lldb/Host/FileSystem.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
|
|
||||||
|
@ -52,16 +53,15 @@ MakeDirectory (const FileSpec &dir_path)
|
||||||
Error
|
Error
|
||||||
ModuleCache::Put (const FileSpec &root_dir_spec,
|
ModuleCache::Put (const FileSpec &root_dir_spec,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
const UUID &uuid,
|
const ModuleSpec &module_spec,
|
||||||
const FileSpec &platform_module_spec,
|
|
||||||
const FileSpec &tmp_file)
|
const FileSpec &tmp_file)
|
||||||
{
|
{
|
||||||
const auto module_spec_dir = GetModuleDirectory (root_dir_spec, uuid);
|
const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
|
||||||
auto error = MakeDirectory (module_spec_dir);
|
auto error = MakeDirectory (module_spec_dir);
|
||||||
if (error.Fail ())
|
if (error.Fail ())
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
const auto module_file_path = JoinPath (module_spec_dir, platform_module_spec.GetFilename ().AsCString ());
|
const auto module_file_path = JoinPath (module_spec_dir, module_spec.GetFileSpec ().GetFilename ().AsCString ());
|
||||||
|
|
||||||
const auto tmp_file_path = tmp_file.GetPath ();
|
const auto tmp_file_path = tmp_file.GetPath ();
|
||||||
const auto err_code = llvm::sys::fs::copy_file (tmp_file_path.c_str (), module_file_path.GetPath ().c_str ());
|
const auto err_code = llvm::sys::fs::copy_file (tmp_file_path.c_str (), module_file_path.GetPath ().c_str ());
|
||||||
|
@ -74,36 +74,45 @@ ModuleCache::Put (const FileSpec &root_dir_spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create sysroot link to a module.
|
// Create sysroot link to a module.
|
||||||
const auto sysroot_module_path_spec = GetHostSysRootModulePath (root_dir_spec, hostname, platform_module_spec);
|
const auto sysroot_module_path_spec = GetHostSysRootModulePath (root_dir_spec, hostname, module_spec.GetFileSpec ());
|
||||||
return CreateHostSysRootModuleSymLink (sysroot_module_path_spec, module_file_path);
|
return CreateHostSysRootModuleSymLink (sysroot_module_path_spec, module_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Error
|
Error
|
||||||
ModuleCache::Get (const FileSpec &root_dir_spec,
|
ModuleCache::Get (const FileSpec &root_dir_spec,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
const UUID &uuid,
|
const ModuleSpec &module_spec,
|
||||||
const FileSpec &platform_module_spec,
|
ModuleSP &cached_module_sp)
|
||||||
FileSpec &cached_module_spec)
|
|
||||||
{
|
{
|
||||||
cached_module_spec.Clear ();
|
const auto find_it = m_loaded_modules.find (module_spec.GetUUID ().GetAsString());
|
||||||
|
if (find_it != m_loaded_modules.end ())
|
||||||
const auto module_spec_dir = GetModuleDirectory (root_dir_spec, uuid);
|
|
||||||
const auto module_file_path = JoinPath (module_spec_dir, platform_module_spec.GetFilename ().AsCString ());
|
|
||||||
|
|
||||||
Error error;
|
|
||||||
if (!module_file_path.Exists ())
|
|
||||||
{
|
{
|
||||||
error.SetErrorStringWithFormat ("module %s not found", module_file_path.GetPath ().c_str ());
|
cached_module_sp = (*find_it).second.lock ();
|
||||||
return error;
|
if (cached_module_sp)
|
||||||
|
return Error ();
|
||||||
|
m_loaded_modules.erase (find_it);
|
||||||
}
|
}
|
||||||
cached_module_spec = module_file_path;
|
|
||||||
|
const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
|
||||||
|
const auto module_file_path = JoinPath (module_spec_dir, module_spec.GetFileSpec ().GetFilename ().AsCString ());
|
||||||
|
|
||||||
|
if (!module_file_path.Exists ())
|
||||||
|
return Error ("module %s not found", module_file_path.GetPath ().c_str ());
|
||||||
|
|
||||||
// We may have already cached module but downloaded from an another host - in this case let's create a symlink to it.
|
// We may have already cached module but downloaded from an another host - in this case let's create a symlink to it.
|
||||||
const auto sysroot_module_path_spec = GetHostSysRootModulePath (root_dir_spec, hostname, platform_module_spec);
|
const auto sysroot_module_path_spec = GetHostSysRootModulePath (root_dir_spec, hostname, module_spec.GetFileSpec ());
|
||||||
if (!sysroot_module_path_spec.Exists ())
|
if (!sysroot_module_path_spec.Exists ())
|
||||||
CreateHostSysRootModuleSymLink (sysroot_module_path_spec, cached_module_spec);
|
CreateHostSysRootModuleSymLink (sysroot_module_path_spec, module_spec.GetFileSpec ());
|
||||||
|
|
||||||
return error;
|
auto cached_module_spec (module_spec);
|
||||||
|
cached_module_spec.GetUUID ().Clear (); // Clear UUID since it may contain md5 content hash instead of real UUID.
|
||||||
|
cached_module_spec.GetFileSpec () = module_file_path;
|
||||||
|
cached_module_spec.GetPlatformFileSpec () = module_spec.GetFileSpec ();
|
||||||
|
cached_module_sp.reset (new Module (cached_module_spec));
|
||||||
|
|
||||||
|
m_loaded_modules.insert (std::make_pair (module_spec.GetUUID ().GetAsString (), cached_module_sp));
|
||||||
|
|
||||||
|
return Error ();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSpec
|
FileSpec
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
#include "lldb/Host/FileSpec.h"
|
#include "lldb/Host/FileSpec.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace lldb_private {
|
namespace lldb_private {
|
||||||
|
|
||||||
|
class Module;
|
||||||
class UUID;
|
class UUID;
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -45,16 +47,14 @@ public:
|
||||||
Error
|
Error
|
||||||
Put (const FileSpec &root_dir_spec,
|
Put (const FileSpec &root_dir_spec,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
const UUID &uuid,
|
const ModuleSpec &module_spec,
|
||||||
const FileSpec &platform_module_spec,
|
|
||||||
const FileSpec &tmp_file);
|
const FileSpec &tmp_file);
|
||||||
|
|
||||||
Error
|
Error
|
||||||
Get (const FileSpec &root_dir_spec,
|
Get (const FileSpec &root_dir_spec,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
const UUID &uuid,
|
const ModuleSpec &module_spec,
|
||||||
const FileSpec &platform_module_spec,
|
lldb::ModuleSP &cached_module_sp);
|
||||||
FileSpec &cached_module_spec);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static FileSpec
|
static FileSpec
|
||||||
|
@ -65,6 +65,8 @@ private:
|
||||||
|
|
||||||
static Error
|
static Error
|
||||||
CreateHostSysRootModuleSymLink (const FileSpec &sysroot_module_path_spec, const FileSpec &module_file_path);
|
CreateHostSysRootModuleSymLink (const FileSpec &sysroot_module_path_spec, const FileSpec &module_file_path);
|
||||||
|
|
||||||
|
std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lldb_private
|
} // namespace lldb_private
|
||||||
|
|
Loading…
Reference in New Issue