summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/ModuleCache.cpp
diff options
context:
space:
mode:
authorOleksiy Vyalov <ovyalov@google.com>2015-03-12 18:18:03 +0000
committerOleksiy Vyalov <ovyalov@google.com>2015-03-12 18:18:03 +0000
commiteda270ee993181e49212332635c7cf8bb2784f71 (patch)
treeef4548c4315fba1d9e553bcfa9925e1e7f5c3303 /lldb/source/Utility/ModuleCache.cpp
parent285dd51b7b416399b5171863432dab56968f1959 (diff)
downloadbcm5719-llvm-eda270ee993181e49212332635c7cf8bb2784f71.tar.gz
bcm5719-llvm-eda270ee993181e49212332635c7cf8bb2784f71.zip
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
Diffstat (limited to 'lldb/source/Utility/ModuleCache.cpp')
-rw-r--r--lldb/source/Utility/ModuleCache.cpp49
1 files changed, 29 insertions, 20 deletions
diff --git a/lldb/source/Utility/ModuleCache.cpp b/lldb/source/Utility/ModuleCache.cpp
index a58c5a87e50..3040e12f1d6 100644
--- a/lldb/source/Utility/ModuleCache.cpp
+++ b/lldb/source/Utility/ModuleCache.cpp
@@ -10,6 +10,7 @@
#include "ModuleCache.h"
#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/FileSystem.h"
#include "llvm/Support/FileSystem.h"
@@ -52,16 +53,15 @@ MakeDirectory (const FileSpec &dir_path)
Error
ModuleCache::Put (const FileSpec &root_dir_spec,
const char *hostname,
- const UUID &uuid,
- const FileSpec &platform_module_spec,
+ const ModuleSpec &module_spec,
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);
if (error.Fail ())
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 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.
- 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);
}
Error
ModuleCache::Get (const FileSpec &root_dir_spec,
const char *hostname,
- const UUID &uuid,
- const FileSpec &platform_module_spec,
- FileSpec &cached_module_spec)
+ const ModuleSpec &module_spec,
+ ModuleSP &cached_module_sp)
{
- cached_module_spec.Clear ();
+ const auto find_it = m_loaded_modules.find (module_spec.GetUUID ().GetAsString());
+ if (find_it != m_loaded_modules.end ())
+ {
+ cached_module_sp = (*find_it).second.lock ();
+ if (cached_module_sp)
+ return Error ();
+ m_loaded_modules.erase (find_it);
+ }
- const auto module_spec_dir = GetModuleDirectory (root_dir_spec, uuid);
- const auto module_file_path = JoinPath (module_spec_dir, platform_module_spec.GetFilename ().AsCString ());
+ 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 ());
- Error error;
if (!module_file_path.Exists ())
- {
- error.SetErrorStringWithFormat ("module %s not found", module_file_path.GetPath ().c_str ());
- return error;
- }
- cached_module_spec = module_file_path;
+ 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.
- 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 ())
- CreateHostSysRootModuleSymLink (sysroot_module_path_spec, cached_module_spec);
+ CreateHostSysRootModuleSymLink (sysroot_module_path_spec, module_spec.GetFileSpec ());
+
+ 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;
+ return Error ();
}
FileSpec
OpenPOWER on IntegriCloud