本文整理汇总了C++中ModuleSpec::GetUUID方法的典型用法代码示例。如果您正苦于以下问题:C++ ModuleSpec::GetUUID方法的具体用法?C++ ModuleSpec::GetUUID怎么用?C++ ModuleSpec::GetUUID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleSpec
的用法示例。
在下文中一共展示了ModuleSpec::GetUUID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: kext_bundle_cs
Error
PlatformDarwinKernel::GetSharedModule (const ModuleSpec &module_spec,
Process *process,
ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
ModuleSP *old_module_sp_ptr,
bool *did_create_ptr)
{
Error error;
module_sp.reset();
const FileSpec &platform_file = module_spec.GetFileSpec();
// Treat the file's path as a kext bundle ID (e.g. "com.apple.driver.AppleIRController") and search our kext index.
std::string kext_bundle_id = platform_file.GetPath();
if (!kext_bundle_id.empty())
{
ConstString kext_bundle_cs(kext_bundle_id.c_str());
if (m_name_to_kext_path_map.count(kext_bundle_cs) > 0)
{
for (BundleIDToKextIterator it = m_name_to_kext_path_map.begin (); it != m_name_to_kext_path_map.end (); ++it)
{
if (it->first == kext_bundle_cs)
{
error = ExamineKextForMatchingUUID (it->second, module_spec.GetUUID(), module_spec.GetArchitecture(), module_sp);
if (module_sp.get())
{
return error;
}
}
}
}
}
if (kext_bundle_id.compare("mach_kernel") == 0 && module_spec.GetUUID().IsValid())
{
for (auto possible_kernel : m_kernel_binaries)
{
if (possible_kernel.Exists())
{
ModuleSpec kern_spec (possible_kernel);
kern_spec.GetUUID() = module_spec.GetUUID();
ModuleSP module_sp (new Module (kern_spec));
if (module_sp && module_sp->GetObjectFile() && module_sp->MatchesModuleSpec (kern_spec))
{
Error error;
error = ModuleList::GetSharedModule (kern_spec, module_sp, NULL, NULL, NULL);
if (module_sp && module_sp->GetObjectFile())
{
return error;
}
}
}
}
}
// Else fall back to treating the file's path as an actual file path - defer to PlatformDarwin's GetSharedModule.
return PlatformDarwin::GetSharedModule (module_spec, process, module_sp, module_search_paths_ptr, old_module_sp_ptr, did_create_ptr);
}
示例2: Get
Error ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname,
const ModuleSpec &module_spec,
ModuleSP &cached_module_sp, bool *did_create_ptr) {
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, 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());
if (module_file_path.GetByteSize() != module_spec.GetObjectSize())
return Error("Module %s has invalid file size",
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 link to it.
auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname,
module_spec.GetFileSpec(),
module_file_path, false);
if (error.Fail())
return Error("Failed to create link to %s: %s",
module_file_path.GetPath().c_str(), error.AsCString());
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();
error = ModuleList::GetSharedModule(cached_module_spec, cached_module_sp,
nullptr, nullptr, did_create_ptr, false);
if (error.Fail())
return error;
FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec());
if (symfile_spec.Exists())
cached_module_sp->SetSymbolFileFileSpec(symfile_spec);
m_loaded_modules.insert(
std::make_pair(module_spec.GetUUID().GetAsString(), cached_module_sp));
return Error();
}
示例3: kext_bundle_cs
Error
PlatformDarwinKernel::GetSharedModule (const ModuleSpec &module_spec,
ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
ModuleSP *old_module_sp_ptr,
bool *did_create_ptr)
{
Error error;
module_sp.reset();
const FileSpec &platform_file = module_spec.GetFileSpec();
// Treat the file's path as a kext bundle ID (e.g. "com.apple.driver.AppleIRController") and search our kext index.
std::string kext_bundle_id = platform_file.GetPath();
if (!kext_bundle_id.empty())
{
ConstString kext_bundle_cs(kext_bundle_id.c_str());
if (m_name_to_kext_path_map.count(kext_bundle_cs) > 0)
{
for (BundleIDToKextIterator it = m_name_to_kext_path_map.begin (); it != m_name_to_kext_path_map.end (); ++it)
{
if (it->first == kext_bundle_cs)
{
error = ExamineKextForMatchingUUID (it->second, module_spec.GetUUID(), module_spec.GetArchitecture(), module_sp);
if (module_sp.get())
{
return error;
}
}
}
}
}
// Else fall back to treating the file's path as an actual file path - defer to PlatformDarwin's GetSharedModule.
return PlatformDarwin::GetSharedModule (module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr, did_create_ptr);
}
示例4: CreateHostSysRootModuleSymLink
Error
ModuleCache::Put (const FileSpec &root_dir_spec,
const char *hostname,
const ModuleSpec &module_spec,
const FileSpec &tmp_file)
{
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, 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 ());
if (err_code)
{
error.SetErrorStringWithFormat ("failed to copy file %s to %s: %s",
tmp_file_path.c_str (),
module_file_path.GetPath ().c_str (),
err_code.message ().c_str ());
}
// Create sysroot link to a module.
const auto sysroot_module_path_spec = GetHostSysRootModulePath (root_dir_spec, hostname, module_spec.GetFileSpec ());
return CreateHostSysRootModuleSymLink (sysroot_module_path_spec, module_file_path);
}
示例5:
Error
PlatformDarwin::ResolveSymbolFile (Target &target,
const ModuleSpec &sym_spec,
FileSpec &sym_file)
{
Error error;
sym_file = sym_spec.GetSymbolFileSpec();
if (sym_file.Exists())
{
if (sym_file.GetFileType() == FileSpec::eFileTypeDirectory)
{
sym_file = Symbols::FindSymbolFileInBundle (sym_file,
sym_spec.GetUUIDPtr(),
sym_spec.GetArchitecturePtr());
}
}
else
{
if (sym_spec.GetUUID().IsValid())
{
}
}
return error;
}
示例6: sizeof
FileSpec
Symbols::FindSymbolFileInBundle (const FileSpec& dsym_bundle_fspec,
const lldb_private::UUID *uuid,
const ArchSpec *arch)
{
char path[PATH_MAX];
FileSpec dsym_fspec;
if (dsym_bundle_fspec.GetPath(path, sizeof(path)))
{
::strncat (path, "/Contents/Resources/DWARF", sizeof(path) - strlen(path) - 1);
lldb_utility::CleanUp <DIR *, int> dirp (opendir(path), NULL, closedir);
if (dirp.is_valid())
{
dsym_fspec.GetDirectory().SetCString(path);
struct dirent* dp;
while ((dp = readdir(dirp.get())) != NULL)
{
// Only search directories
if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
{
if (dp->d_namlen == 1 && dp->d_name[0] == '.')
continue;
if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
continue;
}
if (dp->d_type == DT_REG || dp->d_type == DT_UNKNOWN)
{
dsym_fspec.GetFilename().SetCString(dp->d_name);
ModuleSpecList module_specs;
if (ObjectFile::GetModuleSpecifications(dsym_fspec, 0, 0, module_specs))
{
ModuleSpec spec;
for (size_t i = 0; i < module_specs.GetSize(); ++i)
{
assert(module_specs.GetModuleSpecAtIndex(i, spec));
if ((uuid == NULL || (spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
(arch == NULL || (spec.GetArchitecturePtr() && spec.GetArchitecture().IsCompatibleMatch(*arch))))
{
return dsym_fspec;
}
}
}
}
}
}
}
dsym_fspec.Clear();
return dsym_fspec;
}
示例7: FindSymbolFileInBundle
FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
const lldb_private::UUID *uuid,
const ArchSpec *arch) {
char path[PATH_MAX];
if (dsym_bundle_fspec.GetPath(path, sizeof(path)) == 0)
return {};
::strncat(path, "/Contents/Resources/DWARF", sizeof(path) - strlen(path) - 1);
DIR *dirp = opendir(path);
if (!dirp)
return {};
// Make sure we close the directory before exiting this scope.
CleanUp cleanup_dir(closedir, dirp);
FileSpec dsym_fspec;
dsym_fspec.GetDirectory().SetCString(path);
struct dirent *dp;
while ((dp = readdir(dirp)) != NULL) {
// Only search directories
if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN) {
if (dp->d_namlen == 1 && dp->d_name[0] == '.')
continue;
if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
continue;
}
if (dp->d_type == DT_REG || dp->d_type == DT_UNKNOWN) {
dsym_fspec.GetFilename().SetCString(dp->d_name);
ModuleSpecList module_specs;
if (ObjectFile::GetModuleSpecifications(dsym_fspec, 0, 0, module_specs)) {
ModuleSpec spec;
for (size_t i = 0; i < module_specs.GetSize(); ++i) {
bool got_spec = module_specs.GetModuleSpecAtIndex(i, spec);
UNUSED_IF_ASSERT_DISABLED(got_spec);
assert(got_spec);
if ((uuid == NULL ||
(spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
(arch == NULL ||
(spec.GetArchitecturePtr() &&
spec.GetArchitecture().IsCompatibleMatch(*arch)))) {
return dsym_fspec;
}
}
}
}
}
return {};
}
示例8: Error
Error
ModuleCache::Get (const FileSpec &root_dir_spec,
const char *hostname,
const ModuleSpec &module_spec,
ModuleSP &cached_module_sp,
bool *did_create_ptr)
{
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, 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.
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, 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));
if (did_create_ptr)
*did_create_ptr = true;
m_loaded_modules.insert (std::make_pair (module_spec.GetUUID ().GetAsString (), cached_module_sp));
return Error ();
}
示例9: FileAtPathContainsArchAndUUID
static bool FileAtPathContainsArchAndUUID(const FileSpec &file_fspec,
const ArchSpec *arch,
const lldb_private::UUID *uuid) {
ModuleSpecList module_specs;
if (ObjectFile::GetModuleSpecifications(file_fspec, 0, 0, module_specs)) {
ModuleSpec spec;
for (size_t i = 0; i < module_specs.GetSize(); ++i) {
assert(module_specs.GetModuleSpecAtIndex(i, spec));
if ((uuid == NULL || (spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
(arch == NULL || (spec.GetArchitecturePtr() &&
spec.GetArchitecture().IsCompatibleMatch(*arch)))) {
return true;
}
}
}
return false;
}
示例10:
bool
Module::MatchesModuleSpec (const ModuleSpec &module_ref)
{
const UUID &uuid = module_ref.GetUUID();
if (uuid.IsValid())
{
// If the UUID matches, then nothing more needs to match...
if (uuid == GetUUID())
return true;
else
return false;
}
const FileSpec &file_spec = module_ref.GetFileSpec();
if (file_spec)
{
if (!FileSpec::Equal (file_spec, m_file, file_spec.GetDirectory()))
return false;
}
const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
if (platform_file_spec)
{
if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), platform_file_spec.GetDirectory()))
return false;
}
const ArchSpec &arch = module_ref.GetArchitecture();
if (arch.IsValid())
{
if (m_arch != arch)
return false;
}
const ConstString &object_name = module_ref.GetObjectName();
if (object_name)
{
if (object_name != GetObjectName())
return false;
}
return true;
}
示例11: Error
Error
ModuleCache::Put (const FileSpec &root_dir_spec,
const char *hostname,
const ModuleSpec &module_spec,
const FileSpec &tmp_file,
const FileSpec &target_file)
{
const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
const auto module_file_path = JoinPath (module_spec_dir, target_file.GetFilename ().AsCString ());
const auto tmp_file_path = tmp_file.GetPath ();
const auto err_code = llvm::sys::fs::rename (tmp_file_path.c_str (), module_file_path.GetPath ().c_str ());
if (err_code)
return Error ("Failed to rename file %s to %s: %s",
tmp_file_path.c_str (), module_file_path.GetPath ().c_str (), err_code.message ().c_str ());
const auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, target_file, module_file_path);
if (error.Fail ())
return Error ("Failed to create link to %s: %s", module_file_path.GetPath ().c_str (), error.AsCString ());
return Error ();
}
示例12: LocateExecutableSymbolFile
FileSpec Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec) {
FileSpec symbol_file_spec = module_spec.GetSymbolFileSpec();
if (symbol_file_spec.IsAbsolute() && symbol_file_spec.Exists())
return symbol_file_spec;
const char *symbol_filename = symbol_file_spec.GetFilename().AsCString();
if (symbol_filename && symbol_filename[0]) {
FileSpecList debug_file_search_paths(
Target::GetDefaultDebugFileSearchPaths());
// Add module directory.
const ConstString &file_dir = module_spec.GetFileSpec().GetDirectory();
debug_file_search_paths.AppendIfUnique(
FileSpec(file_dir.AsCString("."), true));
// Add current working directory.
debug_file_search_paths.AppendIfUnique(FileSpec(".", true));
#ifndef LLVM_ON_WIN32
// Add /usr/lib/debug directory.
debug_file_search_paths.AppendIfUnique(FileSpec("/usr/lib/debug", true));
#endif // LLVM_ON_WIN32
std::string uuid_str;
const UUID &module_uuid = module_spec.GetUUID();
if (module_uuid.IsValid()) {
// Some debug files are stored in the .build-id directory like this:
// /usr/lib/debug/.build-id/ff/e7fe727889ad82bb153de2ad065b2189693315.debug
uuid_str = module_uuid.GetAsString("");
uuid_str.insert(2, 1, '/');
uuid_str = uuid_str + ".debug";
}
size_t num_directories = debug_file_search_paths.GetSize();
for (size_t idx = 0; idx < num_directories; ++idx) {
FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
dirspec.ResolvePath();
if (!dirspec.Exists() || !dirspec.IsDirectory())
continue;
std::vector<std::string> files;
std::string dirname = dirspec.GetPath();
files.push_back(dirname + "/" + symbol_filename);
files.push_back(dirname + "/.debug/" + symbol_filename);
files.push_back(dirname + "/.build-id/" + uuid_str);
// Some debug files may stored in the module directory like this:
// /usr/lib/debug/usr/lib/library.so.debug
if (!file_dir.IsEmpty())
files.push_back(dirname + file_dir.AsCString() + "/" + symbol_filename);
const uint32_t num_files = files.size();
for (size_t idx_file = 0; idx_file < num_files; ++idx_file) {
const std::string &filename = files[idx_file];
FileSpec file_spec(filename, true);
if (llvm::sys::fs::equivalent(file_spec.GetPath(),
module_spec.GetFileSpec().GetPath()))
continue;
if (file_spec.Exists()) {
lldb_private::ModuleSpecList specs;
const size_t num_specs =
ObjectFile::GetModuleSpecifications(file_spec, 0, 0, specs);
assert(num_specs <= 1 &&
"Symbol Vendor supports only a single architecture");
if (num_specs == 1) {
ModuleSpec mspec;
if (specs.GetModuleSpecAtIndex(0, mspec)) {
if (mspec.GetUUID() == module_uuid)
return file_spec;
}
}
}
}
}
}
return LocateExecutableSymbolFileDsym(module_spec);
}
示例13: resolved_module_spec
Error
PlatformRemoteGDBServer::ResolveExecutable (const ModuleSpec &module_spec,
lldb::ModuleSP &exe_module_sp,
const FileSpecList *module_search_paths_ptr)
{
// copied from PlatformRemoteiOS
Error error;
// Nothing special to do here, just use the actual file and architecture
ModuleSpec resolved_module_spec(module_spec);
// Resolve any executable within an apk on Android?
//Host::ResolveExecutableInBundle (resolved_module_spec.GetFileSpec());
if (resolved_module_spec.GetFileSpec().Exists() ||
module_spec.GetUUID().IsValid())
{
if (resolved_module_spec.GetArchitecture().IsValid() || resolved_module_spec.GetUUID().IsValid())
{
error = ModuleList::GetSharedModule (resolved_module_spec,
exe_module_sp,
module_search_paths_ptr,
NULL,
NULL);
if (exe_module_sp && exe_module_sp->GetObjectFile())
return error;
exe_module_sp.reset();
}
// No valid architecture was specified or the exact arch wasn't
// found so ask the platform for the architectures that we should be
// using (in the correct order) and see if we can find a match that way
StreamString arch_names;
for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, resolved_module_spec.GetArchitecture()); ++idx)
{
error = ModuleList::GetSharedModule (resolved_module_spec,
exe_module_sp,
module_search_paths_ptr,
NULL,
NULL);
// Did we find an executable using one of the
if (error.Success())
{
if (exe_module_sp && exe_module_sp->GetObjectFile())
break;
else
error.SetErrorToGenericError();
}
if (idx > 0)
arch_names.PutCString (", ");
arch_names.PutCString (resolved_module_spec.GetArchitecture().GetArchitectureName());
}
if (error.Fail() || !exe_module_sp)
{
if (resolved_module_spec.GetFileSpec().Readable())
{
error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
resolved_module_spec.GetFileSpec().GetPath().c_str(),
GetPluginName().GetCString(),
arch_names.GetString().c_str());
}
else
{
error.SetErrorStringWithFormat("'%s' is not readable", resolved_module_spec.GetFileSpec().GetPath().c_str());
}
}
}
else
{
error.SetErrorStringWithFormat ("'%s' does not exist",
resolved_module_spec.GetFileSpec().GetPath().c_str());
}
return error;
}
示例14: GetAndPut
Error ModuleCache::GetAndPut(const FileSpec &root_dir_spec,
const char *hostname,
const ModuleSpec &module_spec,
const ModuleDownloader &module_downloader,
const SymfileDownloader &symfile_downloader,
lldb::ModuleSP &cached_module_sp,
bool *did_create_ptr) {
const auto module_spec_dir =
GetModuleDirectory(root_dir_spec, module_spec.GetUUID());
auto error = MakeDirectory(module_spec_dir);
if (error.Fail())
return error;
ModuleLock lock(root_dir_spec, module_spec.GetUUID(), error);
if (error.Fail())
return Error("Failed to lock module %s: %s",
module_spec.GetUUID().GetAsString().c_str(),
error.AsCString());
const auto escaped_hostname(GetEscapedHostname(hostname));
// Check local cache for a module.
error = Get(root_dir_spec, escaped_hostname.c_str(), module_spec,
cached_module_sp, did_create_ptr);
if (error.Success())
return error;
const auto tmp_download_file_spec = JoinPath(module_spec_dir, kTempFileName);
error = module_downloader(module_spec, tmp_download_file_spec);
llvm::FileRemover tmp_file_remover(tmp_download_file_spec.GetPath().c_str());
if (error.Fail())
return Error("Failed to download module: %s", error.AsCString());
// Put downloaded file into local module cache.
error = Put(root_dir_spec, escaped_hostname.c_str(), module_spec,
tmp_download_file_spec, module_spec.GetFileSpec());
if (error.Fail())
return Error("Failed to put module into cache: %s", error.AsCString());
tmp_file_remover.releaseFile();
error = Get(root_dir_spec, escaped_hostname.c_str(), module_spec,
cached_module_sp, did_create_ptr);
if (error.Fail())
return error;
// Fetching a symbol file for the module
const auto tmp_download_sym_file_spec =
JoinPath(module_spec_dir, kTempSymFileName);
error = symfile_downloader(cached_module_sp, tmp_download_sym_file_spec);
llvm::FileRemover tmp_symfile_remover(
tmp_download_sym_file_spec.GetPath().c_str());
if (error.Fail())
// Failed to download a symfile but fetching the module was successful. The
// module might
// contain the necessary symbols and the debugging is also possible without
// a symfile.
return Error();
error = Put(root_dir_spec, escaped_hostname.c_str(), module_spec,
tmp_download_sym_file_spec,
GetSymbolFileSpec(module_spec.GetFileSpec()));
if (error.Fail())
return Error("Failed to put symbol file into cache: %s", error.AsCString());
tmp_symfile_remover.releaseFile();
FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec());
cached_module_sp->SetSymbolFileFileSpec(symfile_spec);
return Error();
}
示例15: lock_file
Error
ModuleCache::GetAndPut (const FileSpec &root_dir_spec,
const char *hostname,
const ModuleSpec &module_spec,
const ModuleDownloader &module_downloader,
const SymfileDownloader &symfile_downloader,
lldb::ModuleSP &cached_module_sp,
bool *did_create_ptr)
{
const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
auto error = MakeDirectory (module_spec_dir);
if (error.Fail ())
return error;
// Open lock file.
const auto lock_file_spec = JoinPath (module_spec_dir, kLockFileName);
File lock_file (lock_file_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate | File::eOpenOptionCloseOnExec);
if (!lock_file)
{
error.SetErrorToErrno ();
return Error("Failed to open lock file %s: %s", lock_file_spec.GetPath ().c_str (), error.AsCString ());
}
LockFile lock (lock_file.GetDescriptor ());
error = lock.WriteLock (0, 1);
if (error.Fail ())
return Error("Failed to lock file %s:%s", lock_file_spec.GetPath ().c_str (), error.AsCString ());
// Check local cache for a module.
error = Get (root_dir_spec, hostname, module_spec, cached_module_sp, did_create_ptr);
if (error.Success ())
return error;
const auto tmp_download_file_spec = JoinPath (module_spec_dir, kTempFileName);
error = module_downloader (module_spec, tmp_download_file_spec);
llvm::FileRemover tmp_file_remover (tmp_download_file_spec.GetPath ().c_str ());
if (error.Fail ())
return Error("Failed to download module: %s", error.AsCString ());
// Put downloaded file into local module cache.
error = Put (root_dir_spec, hostname, module_spec, tmp_download_file_spec, module_spec.GetFileSpec ());
if (error.Fail ())
return Error ("Failed to put module into cache: %s", error.AsCString ());
tmp_file_remover.releaseFile ();
error = Get (root_dir_spec, hostname, module_spec, cached_module_sp, did_create_ptr);
if (error.Fail ())
return error;
// Fetching a symbol file for the module
const auto tmp_download_sym_file_spec = JoinPath (module_spec_dir, kTempSymFileName);
error = symfile_downloader (cached_module_sp, tmp_download_sym_file_spec);
llvm::FileRemover tmp_symfile_remover (tmp_download_sym_file_spec.GetPath ().c_str ());
if (error.Fail ())
// Failed to download a symfile but fetching the module was successful. The module might
// contain the neccessary symbols and the debugging is also possible without a symfile.
return Error ();
FileSpec symfile_spec = GetSymbolFileSpec (cached_module_sp->GetFileSpec ());
error = Put (root_dir_spec, hostname, module_spec, tmp_download_sym_file_spec, symfile_spec);
if (error.Fail ())
return Error ("Failed to put symbol file into cache: %s", error.AsCString ());
tmp_symfile_remover.releaseFile();
cached_module_sp->SetSymbolFileFileSpec (symfile_spec);
return Error ();
}