diff options
| author | Adrian Prantl <aprantl@apple.com> | 2024-08-27 10:59:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-27 10:59:31 -0700 |
| commit | 0642cd768b80665585c8500bed2933a3b99123dc (patch) | |
| tree | a412a5eafff54ef9a7cb884e01907a4f521f5140 /lldb/source/Target/ModuleCache.cpp | |
| parent | acb33a0c9bc902dc1aef703c02b8fd3a1132cb14 (diff) | |
[lldb] Turn lldb_private::Status into a value type. (#106163)
This patch removes all of the Set.* methods from Status.
This cleanup is part of a series of patches that make it harder use the
anti-pattern of keeping a long-lives Status object around and updating
it while dropping any errors it contains on the floor.
This patch is largely NFC, the more interesting next steps this enables
is to:
1. remove Status.Clear()
2. assert that Status::operator=() never overwrites an error
3. remove Status::operator=()
Note that step (2) will bring 90% of the benefits for users, and step
(3) will dramatically clean up the error handling code in various
places. In the end my goal is to convert all APIs that are of the form
` ResultTy DoFoo(Status& error)
`
to
` llvm::Expected<ResultTy> DoFoo()
`
How to read this patch?
The interesting changes are in Status.h and Status.cpp, all other
changes are mostly
` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git
grep -l SetErrorString lldb/source)
`
plus the occasional manual cleanup.
Diffstat (limited to 'lldb/source/Target/ModuleCache.cpp')
| -rw-r--r-- | lldb/source/Target/ModuleCache.cpp | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/lldb/source/Target/ModuleCache.cpp b/lldb/source/Target/ModuleCache.cpp index 29bd2b2394b5..ce009f9b2faf 100644 --- a/lldb/source/Target/ModuleCache.cpp +++ b/lldb/source/Target/ModuleCache.cpp @@ -173,8 +173,8 @@ ModuleLock::ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid, m_lock = std::make_unique<lldb_private::LockFile>(m_file_up->GetDescriptor()); error = m_lock->WriteLock(0, 1); if (error.Fail()) - error.SetErrorStringWithFormat("Failed to lock file: %s", - error.AsCString()); + error = + Status::FromErrorStringWithFormatv("Failed to lock file: {0}", error); } void ModuleLock::Delete() { @@ -200,15 +200,16 @@ Status ModuleCache::Put(const FileSpec &root_dir_spec, const char *hostname, const auto err_code = llvm::sys::fs::rename(tmp_file_path, module_file_path.GetPath()); if (err_code) - 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()); + return Status::FromErrorStringWithFormat( + "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, true); if (error.Fail()) - return Status("Failed to create link to %s: %s", - module_file_path.GetPath().c_str(), error.AsCString()); + return Status::FromErrorStringWithFormat("Failed to create link to %s: %s", + module_file_path.GetPath().c_str(), + error.AsCString()); return Status(); } @@ -230,11 +231,12 @@ Status ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname, module_spec_dir, module_spec.GetFileSpec().GetFilename().AsCString()); if (!FileSystem::Instance().Exists(module_file_path)) - return Status("Module %s not found", module_file_path.GetPath().c_str()); + return Status::FromErrorStringWithFormat( + "Module %s not found", module_file_path.GetPath().c_str()); if (FileSystem::Instance().GetByteSize(module_file_path) != module_spec.GetObjectSize()) - return Status("Module %s has invalid file size", - module_file_path.GetPath().c_str()); + return Status::FromErrorStringWithFormat( + "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. @@ -242,8 +244,9 @@ Status ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname, module_spec.GetFileSpec(), module_file_path, false); if (error.Fail()) - return Status("Failed to create link to %s: %s", - module_file_path.GetPath().c_str(), error.AsCString()); + return Status::FromErrorStringWithFormat("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 @@ -281,9 +284,9 @@ Status ModuleCache::GetAndPut(const FileSpec &root_dir_spec, ModuleLock lock(root_dir_spec, module_spec.GetUUID(), error); if (error.Fail()) - return Status("Failed to lock module %s: %s", - module_spec.GetUUID().GetAsString().c_str(), - error.AsCString()); + return Status::FromErrorStringWithFormat( + "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. @@ -296,13 +299,15 @@ Status ModuleCache::GetAndPut(const FileSpec &root_dir_spec, error = module_downloader(module_spec, tmp_download_file_spec); llvm::FileRemover tmp_file_remover(tmp_download_file_spec.GetPath()); if (error.Fail()) - return Status("Failed to download module: %s", error.AsCString()); + return Status::FromErrorStringWithFormat("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 Status("Failed to put module into cache: %s", error.AsCString()); + return Status::FromErrorStringWithFormat( + "Failed to put module into cache: %s", error.AsCString()); tmp_file_remover.releaseFile(); error = Get(root_dir_spec, escaped_hostname.c_str(), module_spec, @@ -325,8 +330,8 @@ Status ModuleCache::GetAndPut(const FileSpec &root_dir_spec, tmp_download_sym_file_spec, GetSymbolFileSpec(module_spec.GetFileSpec())); if (error.Fail()) - return Status("Failed to put symbol file into cache: %s", - error.AsCString()); + return Status::FromErrorStringWithFormat( + "Failed to put symbol file into cache: %s", error.AsCString()); tmp_symfile_remover.releaseFile(); |
