From 0642cd768b80665585c8500bed2933a3b99123dc Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 27 Aug 2024 10:59:31 -0700 Subject: [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 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. --- .../Plugins/Process/Linux/NativeProcessLinux.cpp | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp') diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index 59fc8726b767..92fd2fcfe20c 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -1050,10 +1050,10 @@ Status NativeProcessLinux::Resume(const ResumeActionList &resume_actions) { Status error = ResumeThread(static_cast(*thread), action->state, signo); if (error.Fail()) - return Status("NativeProcessLinux::%s: failed to resume thread " - "for pid %" PRIu64 ", tid %" PRIu64 ", error = %s", - __FUNCTION__, GetID(), thread->GetID(), - error.AsCString()); + return Status::FromErrorStringWithFormat( + "NativeProcessLinux::%s: failed to resume thread " + "for pid %" PRIu64 ", tid %" PRIu64 ", error = %s", + __FUNCTION__, GetID(), thread->GetID(), error.AsCString()); break; } @@ -1063,10 +1063,11 @@ Status NativeProcessLinux::Resume(const ResumeActionList &resume_actions) { break; default: - return Status("NativeProcessLinux::%s (): unexpected state %s specified " - "for pid %" PRIu64 ", tid %" PRIu64, - __FUNCTION__, StateAsCString(action->state), GetID(), - thread->GetID()); + return Status::FromErrorStringWithFormat( + "NativeProcessLinux::%s (): unexpected state %s specified " + "for pid %" PRIu64 ", tid %" PRIu64, + __FUNCTION__, StateAsCString(action->state), GetID(), + thread->GetID()); } } @@ -1209,7 +1210,7 @@ Status NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr, if (m_supports_mem_region == LazyBool::eLazyBoolNo) { // We're done. - return Status("unsupported"); + return Status::FromErrorString("unsupported"); } Status error = PopulateMemoryRegionCache(); @@ -1318,7 +1319,7 @@ Status NativeProcessLinux::PopulateMemoryRegionCache() { LLDB_LOG(log, "failed to find any procfs maps entries, assuming no support " "for memory region metadata retrieval"); - return Status("not supported"); + return Status::FromErrorString("not supported"); } LLDB_LOG(log, "read {0} memory region entries from /proc/{1}/maps", @@ -1853,8 +1854,9 @@ Status NativeProcessLinux::GetLoadedModuleFileSpec(const char *module_path, return Status(); } } - return Status("Module file (%s) not found in /proc/%" PRIu64 "/maps file!", - module_file_spec.GetFilename().AsCString(), GetID()); + return Status::FromErrorStringWithFormat( + "Module file (%s) not found in /proc/%" PRIu64 "/maps file!", + module_file_spec.GetFilename().AsCString(), GetID()); } Status NativeProcessLinux::GetFileLoadAddress(const llvm::StringRef &file_name, @@ -1871,7 +1873,7 @@ Status NativeProcessLinux::GetFileLoadAddress(const llvm::StringRef &file_name, return Status(); } } - return Status("No load address found for specified file."); + return Status::FromErrorString("No load address found for specified file."); } NativeThreadLinux *NativeProcessLinux::GetThreadByID(lldb::tid_t tid) { -- cgit v1.2.3