[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- ModuleCache.cpp ---------------------------------------------------===//
|
2015-03-10 01:15:28 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-03-10 01:15:28 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2017-02-14 19:06:07 +00:00
|
|
|
#include "lldb/Target/ModuleCache.h"
|
2015-03-10 01:15:28 +00:00
|
|
|
|
|
|
|
|
#include "lldb/Core/Module.h"
|
2015-12-10 17:08:23 +00:00
|
|
|
#include "lldb/Core/ModuleList.h"
|
2015-03-12 18:18:03 +00:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2015-05-07 15:28:49 +00:00
|
|
|
#include "lldb/Host/File.h"
|
|
|
|
|
#include "lldb/Host/LockFile.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2015-03-10 01:15:28 +00:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2015-04-15 14:35:10 +00:00
|
|
|
#include "llvm/Support/FileUtilities.h"
|
2015-03-10 01:15:28 +00:00
|
|
|
|
2021-05-26 12:19:37 +02:00
|
|
|
#include <cassert>
|
2015-03-10 01:15:28 +00:00
|
|
|
|
|
|
|
|
#include <cstdio>
|
2015-05-07 15:28:49 +00:00
|
|
|
|
2015-03-10 01:15:28 +00:00
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const char *kModulesSubdir = ".cache";
|
2015-09-18 18:12:39 +00:00
|
|
|
const char *kLockDirName = ".lock";
|
2015-05-07 15:28:49 +00:00
|
|
|
const char *kTempFileName = ".temp";
|
2015-08-12 11:10:25 +00:00
|
|
|
const char *kTempSymFileName = ".symtemp";
|
|
|
|
|
const char *kSymFileExtension = ".sym";
|
2016-05-24 18:09:05 +00:00
|
|
|
const char *kFSIllegalChars = "\\/:*?\"<>|";
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-05-24 18:09:05 +00:00
|
|
|
std::string GetEscapedHostname(const char *hostname) {
|
2016-10-21 02:32:08 +00:00
|
|
|
if (hostname == nullptr)
|
|
|
|
|
hostname = "unknown";
|
2016-05-24 18:09:05 +00:00
|
|
|
std::string result(hostname);
|
|
|
|
|
size_t size = result.size();
|
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
|
|
|
if ((result[i] >= 1 && result[i] <= 31) ||
|
|
|
|
|
strchr(kFSIllegalChars, result[i]) != nullptr)
|
|
|
|
|
result[i] = '_';
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2015-03-10 01:15:28 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
class ModuleLock {
|
|
|
|
|
private:
|
2019-09-26 17:54:59 +00:00
|
|
|
FileUP m_file_up;
|
2015-09-18 18:12:39 +00:00
|
|
|
std::unique_ptr<lldb_private::LockFile> m_lock;
|
|
|
|
|
FileSpec m_file_spec;
|
|
|
|
|
|
|
|
|
|
public:
|
2017-05-12 04:51:55 +00:00
|
|
|
ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid, Status &error);
|
2015-09-18 18:12:39 +00:00
|
|
|
void Delete();
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-08 17:56:08 +00:00
|
|
|
static FileSpec JoinPath(const FileSpec &path1, const char *path2) {
|
2015-03-10 01:15:28 +00:00
|
|
|
FileSpec result_spec(path1);
|
|
|
|
|
result_spec.AppendPathComponent(path2);
|
|
|
|
|
return result_spec;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
static Status MakeDirectory(const FileSpec &dir_path) {
|
2017-03-08 17:56:08 +00:00
|
|
|
namespace fs = llvm::sys::fs;
|
2015-03-10 01:15:28 +00:00
|
|
|
|
2017-03-08 17:56:08 +00:00
|
|
|
return fs::create_directories(dir_path.GetPath(), true, fs::perms::owner_all);
|
2015-03-10 01:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-08 23:54:34 +00:00
|
|
|
FileSpec GetModuleDirectory(const FileSpec &root_dir_spec, const UUID &uuid) {
|
|
|
|
|
const auto modules_dir_spec = JoinPath(root_dir_spec, kModulesSubdir);
|
|
|
|
|
return JoinPath(modules_dir_spec, uuid.GetAsString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
FileSpec GetSymbolFileSpec(const FileSpec &module_file_spec) {
|
2018-11-01 21:05:36 +00:00
|
|
|
return FileSpec(module_file_spec.GetPath() + kSymFileExtension);
|
2015-09-18 18:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DeleteExistingModule(const FileSpec &root_dir_spec,
|
|
|
|
|
const FileSpec &sysroot_module_path_spec) {
|
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_MODULES));
|
|
|
|
|
UUID module_uuid;
|
|
|
|
|
{
|
|
|
|
|
auto module_sp =
|
|
|
|
|
std::make_shared<Module>(ModuleSpec(sysroot_module_path_spec));
|
|
|
|
|
module_uuid = module_sp->GetUUID();
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
if (!module_uuid.IsValid())
|
|
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2015-09-18 18:12:39 +00:00
|
|
|
ModuleLock lock(root_dir_spec, module_uuid, error);
|
|
|
|
|
if (error.Fail()) {
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "Failed to lock module %s: %s",
|
|
|
|
|
module_uuid.GetAsString().c_str(), error.AsCString());
|
2015-09-18 18:12:39 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-03-21 05:47:57 +00:00
|
|
|
namespace fs = llvm::sys::fs;
|
|
|
|
|
fs::file_status st;
|
|
|
|
|
if (status(sysroot_module_path_spec.GetPath(), st))
|
2015-09-18 18:12:39 +00:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-03-21 05:47:57 +00:00
|
|
|
if (st.getLinkCount() > 2) // module is referred by other hosts.
|
2015-09-18 18:12:39 +00:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
const auto module_spec_dir = GetModuleDirectory(root_dir_spec, module_uuid);
|
2017-03-09 05:12:36 +00:00
|
|
|
llvm::sys::fs::remove_directories(module_spec_dir.GetPath());
|
2015-09-18 18:12:39 +00:00
|
|
|
lock.Delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DecrementRefExistingModule(const FileSpec &root_dir_spec,
|
|
|
|
|
const FileSpec &sysroot_module_path_spec) {
|
|
|
|
|
// Remove $platform/.cache/$uuid folder if nobody else references it.
|
|
|
|
|
DeleteExistingModule(root_dir_spec, sysroot_module_path_spec);
|
|
|
|
|
|
|
|
|
|
// Remove sysroot link.
|
2017-03-21 05:47:57 +00:00
|
|
|
llvm::sys::fs::remove(sysroot_module_path_spec.GetPath());
|
2015-09-18 18:12:39 +00:00
|
|
|
|
|
|
|
|
FileSpec symfile_spec = GetSymbolFileSpec(sysroot_module_path_spec);
|
2017-03-21 05:47:57 +00:00
|
|
|
llvm::sys::fs::remove(symfile_spec.GetPath());
|
2015-09-18 18:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status CreateHostSysRootModuleLink(const FileSpec &root_dir_spec,
|
|
|
|
|
const char *hostname,
|
|
|
|
|
const FileSpec &platform_module_spec,
|
|
|
|
|
const FileSpec &local_module_spec,
|
|
|
|
|
bool delete_existing) {
|
2015-05-08 23:54:34 +00:00
|
|
|
const auto sysroot_module_path_spec =
|
|
|
|
|
JoinPath(JoinPath(root_dir_spec, hostname),
|
|
|
|
|
platform_module_spec.GetPath().c_str());
|
2018-11-01 17:09:25 +00:00
|
|
|
if (FileSystem::Instance().Exists(sysroot_module_path_spec)) {
|
2015-09-18 18:12:39 +00:00
|
|
|
if (!delete_existing)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
DecrementRefExistingModule(root_dir_spec, sysroot_module_path_spec);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-05-08 23:54:34 +00:00
|
|
|
const auto error = MakeDirectory(
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec(sysroot_module_path_spec.GetDirectory().AsCString()));
|
2015-05-08 23:54:34 +00:00
|
|
|
if (error.Fail())
|
|
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-03-21 05:47:57 +00:00
|
|
|
return llvm::sys::fs::create_hard_link(local_module_spec.GetPath(),
|
|
|
|
|
sysroot_module_path_spec.GetPath());
|
2015-05-08 23:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
} // namespace
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
ModuleLock::ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid,
|
2017-05-12 04:51:55 +00:00
|
|
|
Status &error) {
|
2015-09-18 18:12:39 +00:00
|
|
|
const auto lock_dir_spec = JoinPath(root_dir_spec, kLockDirName);
|
|
|
|
|
error = MakeDirectory(lock_dir_spec);
|
|
|
|
|
if (error.Fail())
|
|
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
m_file_spec = JoinPath(lock_dir_spec, uuid.GetAsString().c_str());
|
2019-09-26 17:54:59 +00:00
|
|
|
|
|
|
|
|
auto file = FileSystem::Instance().Open(
|
2021-07-28 20:07:03 +02:00
|
|
|
m_file_spec, File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate |
|
2019-09-26 17:54:59 +00:00
|
|
|
File::eOpenOptionCloseOnExec);
|
|
|
|
|
if (file)
|
|
|
|
|
m_file_up = std::move(file.get());
|
|
|
|
|
else {
|
|
|
|
|
m_file_up.reset();
|
|
|
|
|
error = Status(file.takeError());
|
2015-09-18 18:12:39 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-06-24 17:44:33 -07:00
|
|
|
m_lock = std::make_unique<lldb_private::LockFile>(m_file_up->GetDescriptor());
|
2015-09-18 18:12:39 +00:00
|
|
|
error = m_lock->WriteLock(0, 1);
|
|
|
|
|
if (error.Fail())
|
|
|
|
|
error.SetErrorStringWithFormat("Failed to lock file: %s",
|
|
|
|
|
error.AsCString());
|
2015-08-12 11:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
void ModuleLock::Delete() {
|
2019-09-26 17:54:59 +00:00
|
|
|
if (!m_file_up)
|
2015-09-18 18:12:39 +00:00
|
|
|
return;
|
|
|
|
|
|
2019-09-26 17:54:59 +00:00
|
|
|
m_file_up->Close();
|
|
|
|
|
m_file_up.reset();
|
2017-03-21 05:47:57 +00:00
|
|
|
llvm::sys::fs::remove(m_file_spec.GetPath());
|
2015-09-18 18:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2015-03-10 01:15:28 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status ModuleCache::Put(const FileSpec &root_dir_spec, const char *hostname,
|
|
|
|
|
const ModuleSpec &module_spec, const FileSpec &tmp_file,
|
|
|
|
|
const FileSpec &target_file) {
|
2015-03-12 18:18:03 +00:00
|
|
|
const auto module_spec_dir =
|
|
|
|
|
GetModuleDirectory(root_dir_spec, module_spec.GetUUID());
|
2015-08-12 11:10:25 +00:00
|
|
|
const auto module_file_path =
|
|
|
|
|
JoinPath(module_spec_dir, target_file.GetFilename().AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-03-10 01:15:28 +00:00
|
|
|
const auto tmp_file_path = tmp_file.GetPath();
|
2016-11-02 20:34:10 +00:00
|
|
|
const auto err_code =
|
|
|
|
|
llvm::sys::fs::rename(tmp_file_path, module_file_path.GetPath());
|
2015-03-10 01:15:28 +00:00
|
|
|
if (err_code)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to rename file %s to %s: %s", tmp_file_path.c_str(),
|
|
|
|
|
module_file_path.GetPath().c_str(),
|
|
|
|
|
err_code.message().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
const auto error = CreateHostSysRootModuleLink(
|
|
|
|
|
root_dir_spec, hostname, target_file, module_file_path, true);
|
2015-05-08 23:54:34 +00:00
|
|
|
if (error.Fail())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to create link to %s: %s",
|
|
|
|
|
module_file_path.GetPath().c_str(), error.AsCString());
|
|
|
|
|
return Status();
|
2015-03-10 01:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname,
|
|
|
|
|
const ModuleSpec &module_spec,
|
|
|
|
|
ModuleSP &cached_module_sp, bool *did_create_ptr) {
|
2015-03-12 18:18:03 +00:00
|
|
|
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)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status();
|
2015-03-12 18:18:03 +00:00
|
|
|
m_loaded_modules.erase(find_it);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-05-08 23:54:34 +00:00
|
|
|
const auto module_spec_dir =
|
|
|
|
|
GetModuleDirectory(root_dir_spec, module_spec.GetUUID());
|
2015-03-12 18:18:03 +00:00
|
|
|
const auto module_file_path = JoinPath(
|
|
|
|
|
module_spec_dir, module_spec.GetFileSpec().GetFilename().AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-11-01 17:09:25 +00:00
|
|
|
if (!FileSystem::Instance().Exists(module_file_path))
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Module %s not found", module_file_path.GetPath().c_str());
|
2018-11-01 04:45:28 +00:00
|
|
|
if (FileSystem::Instance().GetByteSize(module_file_path) !=
|
|
|
|
|
module_spec.GetObjectSize())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Module %s has invalid file size",
|
|
|
|
|
module_file_path.GetPath().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-05-08 23:54:34 +00:00
|
|
|
// We may have already cached module but downloaded from an another host - in
|
|
|
|
|
// this case let's create a link to it.
|
2015-12-10 17:08:23 +00:00
|
|
|
auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname,
|
|
|
|
|
module_spec.GetFileSpec(),
|
|
|
|
|
module_file_path, false);
|
2015-05-08 23:54:34 +00:00
|
|
|
if (error.Fail())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to create link to %s: %s",
|
|
|
|
|
module_file_path.GetPath().c_str(), error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-03-12 18:18:03 +00:00
|
|
|
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();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-12-10 17:08:23 +00:00
|
|
|
error = ModuleList::GetSharedModule(cached_module_spec, cached_module_sp,
|
|
|
|
|
nullptr, nullptr, did_create_ptr, false);
|
|
|
|
|
if (error.Fail())
|
|
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec());
|
2018-11-01 17:09:25 +00:00
|
|
|
if (FileSystem::Instance().Exists(symfile_spec))
|
2015-08-12 11:10:25 +00:00
|
|
|
cached_module_sp->SetSymbolFileFileSpec(symfile_spec);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-03-12 18:18:03 +00:00
|
|
|
m_loaded_modules.insert(
|
|
|
|
|
std::make_pair(module_spec.GetUUID().GetAsString(), cached_module_sp));
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status();
|
2015-03-10 01:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status 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) {
|
2015-05-07 15:28:49 +00:00
|
|
|
const auto module_spec_dir =
|
|
|
|
|
GetModuleDirectory(root_dir_spec, module_spec.GetUUID());
|
|
|
|
|
auto error = MakeDirectory(module_spec_dir);
|
|
|
|
|
if (error.Fail())
|
|
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-18 18:12:39 +00:00
|
|
|
ModuleLock lock(root_dir_spec, module_spec.GetUUID(), error);
|
2015-05-07 15:28:49 +00:00
|
|
|
if (error.Fail())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to lock module %s: %s",
|
|
|
|
|
module_spec.GetUUID().GetAsString().c_str(),
|
|
|
|
|
error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-05-24 18:09:05 +00:00
|
|
|
const auto escaped_hostname(GetEscapedHostname(hostname));
|
2015-04-15 14:35:10 +00:00
|
|
|
// Check local cache for a module.
|
2016-05-24 18:09:05 +00:00
|
|
|
error = Get(root_dir_spec, escaped_hostname.c_str(), module_spec,
|
|
|
|
|
cached_module_sp, did_create_ptr);
|
2015-04-15 14:35:10 +00:00
|
|
|
if (error.Success())
|
|
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-05-07 15:28:49 +00:00
|
|
|
const auto tmp_download_file_spec = JoinPath(module_spec_dir, kTempFileName);
|
2015-08-12 11:10:25 +00:00
|
|
|
error = module_downloader(module_spec, tmp_download_file_spec);
|
2016-11-02 20:34:10 +00:00
|
|
|
llvm::FileRemover tmp_file_remover(tmp_download_file_spec.GetPath());
|
2015-04-15 14:35:10 +00:00
|
|
|
if (error.Fail())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to download module: %s", error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-04-15 14:35:10 +00:00
|
|
|
// Put downloaded file into local module cache.
|
2016-05-24 18:09:05 +00:00
|
|
|
error = Put(root_dir_spec, escaped_hostname.c_str(), module_spec,
|
|
|
|
|
tmp_download_file_spec, module_spec.GetFileSpec());
|
2015-04-15 14:35:10 +00:00
|
|
|
if (error.Fail())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to put module into cache: %s", error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-05-07 15:28:49 +00:00
|
|
|
tmp_file_remover.releaseFile();
|
2016-05-24 18:09:05 +00:00
|
|
|
error = Get(root_dir_spec, escaped_hostname.c_str(), module_spec,
|
|
|
|
|
cached_module_sp, did_create_ptr);
|
2015-08-12 11:10:25 +00:00
|
|
|
if (error.Fail())
|
|
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
// 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);
|
2016-11-02 20:34:10 +00:00
|
|
|
llvm::FileRemover tmp_symfile_remover(tmp_download_sym_file_spec.GetPath());
|
2015-08-12 11:10:25 +00:00
|
|
|
if (error.Fail())
|
|
|
|
|
// Failed to download a symfile but fetching the module was successful. The
|
2018-04-30 16:49:04 +00:00
|
|
|
// module might contain the necessary symbols and the debugging is also
|
|
|
|
|
// possible without a symfile.
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-05-24 18:09:05 +00:00
|
|
|
error = Put(root_dir_spec, escaped_hostname.c_str(), module_spec,
|
|
|
|
|
tmp_download_sym_file_spec,
|
|
|
|
|
GetSymbolFileSpec(module_spec.GetFileSpec()));
|
2015-08-12 11:10:25 +00:00
|
|
|
if (error.Fail())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to put symbol file into cache: %s",
|
|
|
|
|
error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
tmp_symfile_remover.releaseFile();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-11-03 00:30:19 +00:00
|
|
|
FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec());
|
2015-08-12 11:10:25 +00:00
|
|
|
cached_module_sp->SetSymbolFileFileSpec(symfile_spec);
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status();
|
2015-04-15 14:35:10 +00:00
|
|
|
}
|