[Lldb-commits] [lldb] [lldb] Make deep copies of Status explicit (NFC) (PR #107170)

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 5 12:28:08 PDT 2024


https://github.com/adrian-prantl updated https://github.com/llvm/llvm-project/pull/107170

>From 6500c9a1c2cf2812332dd66e35e625f1bc233b89 Mon Sep 17 00:00:00 2001
From: Adrian Prantl <aprantl at apple.com>
Date: Tue, 3 Sep 2024 16:40:41 -0700
Subject: [PATCH] [lldb] Make deep copies of Status explicit (NFC)

---
 lldb/bindings/python/python-swigsafecast.swig |  2 +-
 lldb/include/lldb/API/SBError.h               |  4 +-
 lldb/include/lldb/API/SBValueList.h           |  2 +-
 .../lldb/Core/ValueObjectConstResult.h        |  4 +-
 lldb/include/lldb/Target/Process.h            |  2 -
 lldb/include/lldb/Utility/Status.h            | 29 ++++++++++++-
 lldb/source/API/SBBreakpoint.cpp              |  6 +--
 lldb/source/API/SBBreakpointLocation.cpp      |  4 +-
 lldb/source/API/SBBreakpointName.cpp          | 17 ++++----
 lldb/source/API/SBDebugger.cpp                |  2 +-
 lldb/source/API/SBError.cpp                   | 15 ++++---
 lldb/source/API/SBFile.cpp                    | 15 +++----
 lldb/source/API/SBFormat.cpp                  |  2 +-
 lldb/source/API/SBFrame.cpp                   |  9 ++--
 lldb/source/API/SBPlatform.cpp                |  4 +-
 lldb/source/API/SBProcess.cpp                 |  2 +-
 lldb/source/API/SBSaveCoreOptions.cpp         |  3 +-
 lldb/source/API/SBStructuredData.cpp          |  2 +-
 lldb/source/API/SBTarget.cpp                  |  5 ++-
 lldb/source/API/SBThread.cpp                  |  2 +-
 lldb/source/API/SBValue.cpp                   |  4 +-
 lldb/source/API/SBValueList.cpp               | 13 +++---
 lldb/source/API/SBWatchpoint.cpp              |  2 +-
 .../source/Commands/CommandObjectCommands.cpp |  4 +-
 lldb/source/Core/Debugger.cpp                 |  2 +-
 lldb/source/Core/ModuleList.cpp               |  5 +--
 lldb/source/Core/ValueObject.cpp              |  4 +-
 lldb/source/Core/ValueObjectCast.cpp          |  2 +-
 lldb/source/Core/ValueObjectConstResult.cpp   |  9 ++--
 lldb/source/Core/ValueObjectDynamicValue.cpp  |  2 +-
 .../Core/ValueObjectSyntheticFilter.cpp       |  2 +-
 lldb/source/Expression/FunctionCaller.cpp     |  3 +-
 lldb/source/Expression/LLVMUserExpression.cpp |  6 +--
 lldb/source/Expression/Materializer.cpp       |  2 +-
 lldb/source/Expression/UserExpression.cpp     |  8 ++--
 lldb/source/Host/common/LockFileBase.cpp      |  4 +-
 .../Host/common/NativeProcessProtocol.cpp     |  8 ++--
 .../posix/ConnectionFileDescriptorPosix.cpp   | 12 +++---
 .../source/Interpreter/CommandInterpreter.cpp |  2 +-
 lldb/source/Interpreter/ScriptInterpreter.cpp |  2 +-
 .../Plugins/Platform/Android/AdbClient.cpp    |  8 ++--
 .../PlatformAndroidRemoteGDBServer.cpp        |  4 +-
 ...PlatformiOSSimulatorCoreSimulatorSupport.h |  2 +-
 ...latformiOSSimulatorCoreSimulatorSupport.mm | 12 +++---
 .../Plugins/Platform/POSIX/PlatformPOSIX.cpp  |  4 +-
 .../Platform/Windows/PlatformWindows.cpp      |  4 +-
 .../ScriptedProcessPythonInterface.cpp        |  6 +--
 .../Interfaces/ScriptedPythonInterface.h      |  8 +++-
 .../Plugins/SymbolFile/DWARF/DWARFUnit.h      |  2 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp      |  2 +-
 .../DWARF/SymbolFileDWARFDebugMap.cpp         |  2 +-
 lldb/source/Target/ModuleCache.cpp            |  2 +-
 lldb/source/Target/Platform.cpp               |  4 +-
 lldb/source/Target/Process.cpp                | 41 +------------------
 lldb/source/Target/StackFrame.cpp             |  2 +-
 lldb/source/Target/Target.cpp                 | 12 +++---
 lldb/source/Utility/Status.cpp                | 33 +++++++++++++++
 .../Target/RemoteAwarePlatformTest.cpp        |  9 ++--
 58 files changed, 202 insertions(+), 182 deletions(-)

diff --git a/lldb/bindings/python/python-swigsafecast.swig b/lldb/bindings/python/python-swigsafecast.swig
index 34f8c6f0ff8d35..bffd10ae7b3315 100644
--- a/lldb/bindings/python/python-swigsafecast.swig
+++ b/lldb/bindings/python/python-swigsafecast.swig
@@ -34,7 +34,7 @@ PythonObject SWIGBridge::ToSWIGWrapper(lldb::BreakpointSP breakpoint_sp) {
 }
 
 PythonObject SWIGBridge::ToSWIGWrapper(const Status& status) {
-  return ToSWIGHelper(new lldb::SBError(status), SWIGTYPE_p_lldb__SBError);
+  return ToSWIGHelper(new lldb::SBError(status.Clone()), SWIGTYPE_p_lldb__SBError);
 }
 
 PythonObject SWIGBridge::ToSWIGWrapper(std::unique_ptr<lldb::SBStructuredData> data_sb) {
diff --git a/lldb/include/lldb/API/SBError.h b/lldb/include/lldb/API/SBError.h
index 17f2c6c3027af7..9f55f92131c06e 100644
--- a/lldb/include/lldb/API/SBError.h
+++ b/lldb/include/lldb/API/SBError.h
@@ -97,7 +97,7 @@ class LLDB_API SBError {
   friend class lldb_private::ScriptInterpreter;
   friend class lldb_private::python::SWIGBridge;
 
-  SBError(const lldb_private::Status &error);
+  SBError(lldb_private::Status &&error);
 
   lldb_private::Status *get();
 
@@ -107,7 +107,7 @@ class LLDB_API SBError {
 
   lldb_private::Status &ref();
 
-  void SetError(const lldb_private::Status &lldb_error);
+  void SetError(lldb_private::Status &&lldb_error);
 
 private:
   std::unique_ptr<lldb_private::Status> m_opaque_up;
diff --git a/lldb/include/lldb/API/SBValueList.h b/lldb/include/lldb/API/SBValueList.h
index a5017bccc50533..52a86f989e153a 100644
--- a/lldb/include/lldb/API/SBValueList.h
+++ b/lldb/include/lldb/API/SBValueList.h
@@ -96,7 +96,7 @@ class LLDB_API SBValueList {
 
   std::unique_ptr<ValueListImpl> m_opaque_up;
 
-  void SetError(const lldb_private::Status &status);
+  void SetError(lldb_private::Status &&status);
 };
 
 } // namespace lldb
diff --git a/lldb/include/lldb/Core/ValueObjectConstResult.h b/lldb/include/lldb/Core/ValueObjectConstResult.h
index d3b3362bd0e9ec..9c34617af71d0d 100644
--- a/lldb/include/lldb/Core/ValueObjectConstResult.h
+++ b/lldb/include/lldb/Core/ValueObjectConstResult.h
@@ -61,7 +61,7 @@ class ValueObjectConstResult : public ValueObject {
 
   // When an expression fails to evaluate, we return an error
   static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
-                                    const Status &error);
+                                    Status &&error);
 
   std::optional<uint64_t> GetByteSize() override;
 
@@ -146,7 +146,7 @@ class ValueObjectConstResult : public ValueObject {
                          ConstString name, Module *module = nullptr);
 
   ValueObjectConstResult(ExecutionContextScope *exe_scope,
-                         ValueObjectManager &manager, const Status &error);
+                         ValueObjectManager &manager, Status &&error);
 
   ValueObject *CreateChildAtIndex(size_t idx) override {
     return m_impl.CreateChildAtIndex(idx);
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index a7de991104434d..c66cfb2c245efd 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1296,8 +1296,6 @@ class Process : public std::enable_shared_from_this<Process>,
                 const EvaluateExpressionOptions &options,
                 DiagnosticManager &diagnostic_manager);
 
-  static const char *ExecutionResultAsCString(lldb::ExpressionResults result);
-
   void GetStatus(Stream &ostrm);
 
   size_t GetThreadStatus(Stream &ostrm, bool only_threads_with_stop_reason,
diff --git a/lldb/include/lldb/Utility/Status.h b/lldb/include/lldb/Utility/Status.h
index 3813a3c1604700..45d4be602db1f5 100644
--- a/lldb/include/lldb/Utility/Status.h
+++ b/lldb/include/lldb/Utility/Status.h
@@ -26,6 +26,8 @@ class raw_ostream;
 
 namespace lldb_private {
 
+const char *ExecutionResultAsCString(lldb::ExpressionResults result);
+
 /// \class Status Status.h "lldb/Utility/Status.h" An error handling class.
 ///
 /// This class is designed to be able to hold any error code that can be
@@ -41,13 +43,32 @@ namespace lldb_private {
 /// of themselves for printing results and error codes. The string value will
 /// be fetched on demand and its string value will be cached until the error
 /// is cleared of the value of the error changes.
+///
+/// API design notes:
+///
+/// Most APIs that currently vend a Status would be better served by
+/// returning llvm::Expected<> instead. If possibles APIs should be
+/// refactored to avoid Status. The only legitimate long-term uses of
+/// Status are objects that need to store an error for a long time
+/// (which should be questioned as a design decision, too).
+///
+/// Implementation notes:
+///
+/// Internally, Status stores an llvm::Error.
+///   eErrorTypeInvalid
+///   eErrorTypeGeneric      llvm::StringError
+///   eErrorTypePOSIX        llvm::ECError
+///   eErrorTypeMachKernel   MachKernelError
+///   eErrorTypeExpression   llvm::ErrorList<ExpressionError>
+///   eErrorTypeWin32        Win32Error
+
 class Status {
 public:
-  /// Every error value that this object can contain needs to be able to fit
   /// into ValueType.
   typedef uint32_t ValueType;
 
   Status();
+  Status(Status &&other) = default;
 
   /// Initialize the error object with a generic success value.
   ///
@@ -91,10 +112,14 @@ class Status {
 
   ~Status();
 
+  const Status &operator=(Status &&);
   /// Avoid using this in new code. Migrate APIs to llvm::Expected instead.
   static Status FromError(llvm::Error error);
-  /// FIXME: Replace this with a takeError method.
+  /// FIXME: Replace this with a takeError() method.
   llvm::Error ToError() const;
+  /// Don't call this function in new code. Instead, redesign the API
+  /// to use llvm::Expected instead of Status.
+  Status Clone() const { return Status(ToError()); }
 
   /// Get the error string associated with the current error.
   //
diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp
index 3e9c01080588e5..b2ed034d19983c 100644
--- a/lldb/source/API/SBBreakpoint.cpp
+++ b/lldb/source/API/SBBreakpoint.cpp
@@ -622,7 +622,7 @@ SBError SBBreakpoint::SetScriptCallbackFunction(
                                                callback_function_name,
                                                extra_args.m_impl_up
                                                    ->GetObjectSP());
-    sb_error.SetError(error);
+    sb_error.SetError(std::move(error));
   } else
     sb_error = Status::FromErrorString("invalid breakpoint");
 
@@ -645,7 +645,7 @@ SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
             .GetScriptInterpreter()
             ->SetBreakpointCommandCallback(bp_options, callback_body_text,
                                            /*is_callback=*/false);
-    sb_error.SetError(error);
+    sb_error.SetError(std::move(error));
   } else
     sb_error = Status::FromErrorString("invalid breakpoint");
 
@@ -670,7 +670,7 @@ SBError SBBreakpoint::AddNameWithErrorHandling(const char *new_name) {
         bkpt_sp->GetTarget().GetAPIMutex());
     Status error;
     bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
-    status.SetError(error);
+    status.SetError(std::move(error));
   } else {
     status = Status::FromErrorString("invalid breakpoint");
   }
diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp
index e5c96b81e80904..b2d1da3927c6ea 100644
--- a/lldb/source/API/SBBreakpointLocation.cpp
+++ b/lldb/source/API/SBBreakpointLocation.cpp
@@ -239,7 +239,7 @@ SBError SBBreakpointLocation::SetScriptCallbackFunction(
                                                callback_function_name,
                                                extra_args.m_impl_up
                                                    ->GetObjectSP());
-      sb_error.SetError(error);
+    sb_error.SetError(std::move(error));
     } else
       sb_error = Status::FromErrorString("invalid breakpoint");
 
@@ -264,7 +264,7 @@ SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
             .GetScriptInterpreter()
             ->SetBreakpointCommandCallback(bp_options, callback_body_text,
                                            /*is_callback=*/false);
-    sb_error.SetError(error);
+    sb_error.SetError(std::move(error));
   } else
     sb_error = Status::FromErrorString("invalid breakpoint");
 
diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp
index 7dc8dee19f43d2..831260d44e8e7f 100644
--- a/lldb/source/API/SBBreakpointName.cpp
+++ b/lldb/source/API/SBBreakpointName.cpp
@@ -570,14 +570,13 @@ SBError SBBreakpointName::SetScriptCallbackFunction(
         m_impl_up->GetTarget()->GetAPIMutex());
 
   BreakpointOptions &bp_options = bp_name->GetOptions();
-  Status error;
-  error = m_impl_up->GetTarget()
-              ->GetDebugger()
-              .GetScriptInterpreter()
-              ->SetBreakpointCommandCallbackFunction(
-                  bp_options, callback_function_name,
-                  extra_args.m_impl_up->GetObjectSP());
-  sb_error.SetError(error);
+  Status error = m_impl_up->GetTarget()
+                     ->GetDebugger()
+                     .GetScriptInterpreter()
+                     ->SetBreakpointCommandCallbackFunction(
+                         bp_options, callback_function_name,
+                         extra_args.m_impl_up->GetObjectSP());
+  sb_error.SetError(std::move(error));
   UpdateName(*bp_name);
   return sb_error;
 }
@@ -600,7 +599,7 @@ SBBreakpointName::SetScriptCallbackBody(const char *callback_body_text) {
                      .GetScriptInterpreter()
                      ->SetBreakpointCommandCallback(
                          bp_options, callback_body_text, /*is_callback=*/false);
-  sb_error.SetError(error);
+  sb_error.SetError(std::move(error));
   if (!sb_error.Fail())
     UpdateName(*bp_name);
 
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index c226acc15018ef..b21d7e67290073 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1360,7 +1360,7 @@ SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value,
         "invalid debugger instance name '%s'", debugger_instance_name);
   }
   if (error.Fail())
-    sb_error.SetError(error);
+    sb_error.SetError(std::move(error));
   return sb_error;
 }
 
diff --git a/lldb/source/API/SBError.cpp b/lldb/source/API/SBError.cpp
index 30d9ccc78ee376..31964931649db3 100644
--- a/lldb/source/API/SBError.cpp
+++ b/lldb/source/API/SBError.cpp
@@ -23,7 +23,8 @@ SBError::SBError() { LLDB_INSTRUMENT_VA(this); }
 SBError::SBError(const SBError &rhs) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
-  m_opaque_up = clone(rhs.m_opaque_up);
+  if (rhs.m_opaque_up)
+    m_opaque_up = std::make_unique<Status>(rhs.m_opaque_up->Clone());
 }
 
 SBError::SBError(const char *message) {
@@ -32,8 +33,8 @@ SBError::SBError(const char *message) {
   SetErrorString(message);
 }
 
-SBError::SBError(const lldb_private::Status &status)
-    : m_opaque_up(new Status(status)) {
+SBError::SBError(lldb_private::Status &&status)
+    : m_opaque_up(new Status(std::move(status))) {
   LLDB_INSTRUMENT_VA(this, status);
 }
 
@@ -43,7 +44,9 @@ const SBError &SBError::operator=(const SBError &rhs) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
   if (this != &rhs)
-    m_opaque_up = clone(rhs.m_opaque_up);
+    if (rhs.m_opaque_up)
+      m_opaque_up = std::make_unique<Status>(rhs.m_opaque_up->Clone());
+
   return *this;
 }
 
@@ -111,9 +114,9 @@ void SBError::SetError(uint32_t err, ErrorType type) {
   *m_opaque_up = Status(err, type);
 }
 
-void SBError::SetError(const Status &lldb_error) {
+void SBError::SetError(Status &&lldb_error) {
   CreateIfNeeded();
-  *m_opaque_up = lldb_error;
+  *m_opaque_up = std::move(lldb_error);
 }
 
 void SBError::SetErrorToErrno() {
diff --git a/lldb/source/API/SBFile.cpp b/lldb/source/API/SBFile.cpp
index 623708780f4c67..2ae4b1481afbf2 100644
--- a/lldb/source/API/SBFile.cpp
+++ b/lldb/source/API/SBFile.cpp
@@ -62,8 +62,7 @@ SBError SBFile::Read(uint8_t *buf, size_t num_bytes, size_t *bytes_read) {
     error = Status::FromErrorString("invalid SBFile");
     *bytes_read = 0;
   } else {
-    Status status = m_opaque_sp->Read(buf, num_bytes);
-    error.SetError(status);
+    error.SetError(m_opaque_sp->Read(buf, num_bytes));
     *bytes_read = num_bytes;
   }
   return error;
@@ -78,8 +77,7 @@ SBError SBFile::Write(const uint8_t *buf, size_t num_bytes,
     error = Status::FromErrorString("invalid SBFile");
     *bytes_written = 0;
   } else {
-    Status status = m_opaque_sp->Write(buf, num_bytes);
-    error.SetError(status);
+    error.SetError(m_opaque_sp->Write(buf, num_bytes));
     *bytes_written = num_bytes;
   }
   return error;
@@ -92,8 +90,7 @@ SBError SBFile::Flush() {
   if (!m_opaque_sp) {
     error = Status::FromErrorString("invalid SBFile");
   } else {
-    Status status = m_opaque_sp->Flush();
-    error.SetError(status);
+    error.SetError(m_opaque_sp->Flush());
   }
   return error;
 }
@@ -106,10 +103,8 @@ bool SBFile::IsValid() const {
 SBError SBFile::Close() {
   LLDB_INSTRUMENT_VA(this);
   SBError error;
-  if (m_opaque_sp) {
-    Status status = m_opaque_sp->Close();
-    error.SetError(status);
-  }
+  if (m_opaque_sp)
+    error.SetError(m_opaque_sp->Close());
   return error;
 }
 
diff --git a/lldb/source/API/SBFormat.cpp b/lldb/source/API/SBFormat.cpp
index 51cddceea0372e..080e219d64a362 100644
--- a/lldb/source/API/SBFormat.cpp
+++ b/lldb/source/API/SBFormat.cpp
@@ -36,7 +36,7 @@ SBFormat::SBFormat(const char *format, lldb::SBError &error) {
   FormatEntrySP format_entry_sp = std::make_shared<FormatEntity::Entry>();
   Status status = FormatEntity::Parse(format, *format_entry_sp);
 
-  error.SetError(status);
+  error.SetError(std::move(status));
   if (error.Success())
     m_opaque_sp = format_entry_sp;
 }
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index b1360e88bcd3af..30c44b974988d0 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -809,7 +809,7 @@ SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
         Status var_error;
         variable_list = frame->GetVariableList(true, &var_error);
         if (var_error.Fail())
-          value_list.SetError(var_error);
+          value_list.SetError(std::move(var_error));
         if (variable_list) {
           const size_t num_variables = variable_list->GetSize();
           if (num_variables) {
@@ -1033,7 +1033,8 @@ SBValue SBFrame::EvaluateExpression(const char *expr) {
     Status error;
     error = Status::FromErrorString("can't evaluate expressions when the "
                                     "process is running.");
-    ValueObjectSP error_val_sp = ValueObjectConstResult::Create(nullptr, error);
+    ValueObjectSP error_val_sp =
+        ValueObjectConstResult::Create(nullptr, std::move(error));
     result.SetSP(error_val_sp, false);
   }
   return result;
@@ -1129,13 +1130,13 @@ lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
       Status error;
       error = Status::FromErrorString("can't evaluate expressions when the "
                                       "process is running.");
-      expr_value_sp = ValueObjectConstResult::Create(nullptr, error);
+      expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
       expr_result.SetSP(expr_value_sp, false);
     }
   } else {
       Status error;
       error = Status::FromErrorString("sbframe object is not valid.");
-      expr_value_sp = ValueObjectConstResult::Create(nullptr, error);
+      expr_value_sp = ValueObjectConstResult::Create(nullptr, std::move(error));
       expr_result.SetSP(expr_value_sp, false);
   }
 
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 2f0f925302f16e..394268b77aa21f 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -586,7 +586,7 @@ SBProcess SBPlatform::Attach(SBAttachInfo &attach_info,
       Status status;
       ProcessSP process_sp = platform_sp->Attach(info, debugger.ref(),
                                                  target.GetSP().get(), status);
-      error.SetError(status);
+      error.SetError(std::move(status));
       return SBProcess(process_sp);
     }
 
@@ -728,7 +728,7 @@ SBError SBPlatform::SetLocateModuleCallback(
           symbol_file_spec = symbol_file_spec_sb.ref();
         }
 
-        return error.ref();
+        return error.ref().Clone();
       });
   return SBError();
 }
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index 3eed51f0245f6f..9773144723c34c 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -1450,7 +1450,7 @@ lldb::SBError SBProcess::DeallocateMemory(lldb::addr_t ptr) {
       std::lock_guard<std::recursive_mutex> guard(
           process_sp->GetTarget().GetAPIMutex());
       Status error = process_sp->DeallocateMemory(ptr);
-      sb_error.SetError(error);
+      sb_error.SetError(std::move(error));
     } else {
       sb_error = Status::FromErrorString("process is running");
     }
diff --git a/lldb/source/API/SBSaveCoreOptions.cpp b/lldb/source/API/SBSaveCoreOptions.cpp
index 2cd431611ef558..ef82b0253f1199 100644
--- a/lldb/source/API/SBSaveCoreOptions.cpp
+++ b/lldb/source/API/SBSaveCoreOptions.cpp
@@ -40,8 +40,7 @@ SBSaveCoreOptions::operator=(const SBSaveCoreOptions &rhs) {
 
 SBError SBSaveCoreOptions::SetPluginName(const char *name) {
   LLDB_INSTRUMENT_VA(this, name);
-  lldb_private::Status error = m_opaque_up->SetPluginName(name);
-  return SBError(error);
+  return SBError(m_opaque_up->SetPluginName(name));
 }
 
 void SBSaveCoreOptions::SetStyle(lldb::SaveCoreStyle style) {
diff --git a/lldb/source/API/SBStructuredData.cpp b/lldb/source/API/SBStructuredData.cpp
index 801ebf45e0e524..b891a34bd7c76a 100644
--- a/lldb/source/API/SBStructuredData.cpp
+++ b/lldb/source/API/SBStructuredData.cpp
@@ -133,7 +133,7 @@ lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
 
   Status error = m_impl_up->GetDescription(stream.ref());
   SBError sb_error;
-  sb_error.SetError(error);
+  sb_error.SetError(std::move(error));
   return sb_error;
 }
 
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 41eb77e5506bc5..1c1f7e2a03def8 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1369,7 +1369,7 @@ SBTarget::WatchpointCreateByAddress(lldb::addr_t addr, size_t size,
     CompilerType *type = nullptr;
     watchpoint_sp =
         target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
-    error.SetError(cw_error);
+    error.SetError(std::move(cw_error));
     sb_watchpoint.SetSP(watchpoint_sp);
   }
 
@@ -2326,7 +2326,8 @@ lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
           Status error;
           error = Status::FromErrorString("can't evaluate expressions when the "
                                           "process is running.");
-          expr_value_sp = ValueObjectConstResult::Create(nullptr, error);
+          expr_value_sp =
+              ValueObjectConstResult::Create(nullptr, std::move(error));
         }
       } else {
         target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index 92868130f6222c..7508eed5d6fdbd 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -958,7 +958,7 @@ SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) {
   Thread *thread = exe_ctx.GetThreadPtr();
 
   Status err = thread->JumpToLine(file_spec.ref(), line, true);
-  sb_error.SetError(err);
+  sb_error.SetError(std::move(err));
   return sb_error;
 }
 
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index df0e82b6523fbd..273aac5ad47989 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -270,7 +270,7 @@ SBError SBValue::GetError() {
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
   if (value_sp)
-    sb_error.SetError(value_sp->GetError());
+    sb_error.SetError(value_sp->GetError().Clone());
   else
     sb_error = Status::FromErrorStringWithFormat("error: %s",
                                                  locker.GetError().AsCString());
@@ -1476,7 +1476,7 @@ lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write,
     CompilerType type(value_sp->GetCompilerType());
     WatchpointSP watchpoint_sp =
         target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
-    error.SetError(rc);
+    error.SetError(std::move(rc));
 
     if (watchpoint_sp) {
       sb_watchpoint.SetSP(watchpoint_sp);
diff --git a/lldb/source/API/SBValueList.cpp b/lldb/source/API/SBValueList.cpp
index ba7e06971dc366..63b915094baf2c 100644
--- a/lldb/source/API/SBValueList.cpp
+++ b/lldb/source/API/SBValueList.cpp
@@ -22,13 +22,14 @@ class ValueListImpl {
 public:
   ValueListImpl() = default;
 
-  ValueListImpl(const ValueListImpl &rhs) = default;
+  ValueListImpl(const ValueListImpl &rhs)
+      : m_values(rhs.m_values), m_error(rhs.m_error.Clone()) {}
 
   ValueListImpl &operator=(const ValueListImpl &rhs) {
     if (this == &rhs)
       return *this;
     m_values = rhs.m_values;
-    m_error = rhs.m_error;
+    m_error = rhs.m_error.Clone();
     return *this;
   }
 
@@ -67,7 +68,7 @@ class ValueListImpl {
 
   const Status &GetError() const { return m_error; }
 
-  void SetError(const Status &error) { m_error = error; }
+  void SetError(Status &&error) { m_error = std::move(error); }
 
 private:
   std::vector<lldb::SBValue> m_values;
@@ -205,10 +206,10 @@ lldb::SBError SBValueList::GetError() {
   LLDB_INSTRUMENT_VA(this);
   SBError sb_error;
   if (m_opaque_up)
-    sb_error.SetError(m_opaque_up->GetError());
+    sb_error.SetError(m_opaque_up->GetError().Clone());
   return sb_error;
 }
 
-void SBValueList::SetError(const lldb_private::Status &status) {
-  ref().SetError(status);
+void SBValueList::SetError(lldb_private::Status &&status) {
+  ref().SetError(std::move(status));
 }
diff --git a/lldb/source/API/SBWatchpoint.cpp b/lldb/source/API/SBWatchpoint.cpp
index 9664bbe618600c..21e2dcc01968e7 100644
--- a/lldb/source/API/SBWatchpoint.cpp
+++ b/lldb/source/API/SBWatchpoint.cpp
@@ -86,7 +86,7 @@ SBError SBWatchpoint::GetError() {
   SBError sb_error;
   lldb::WatchpointSP watchpoint_sp(GetSP());
   if (watchpoint_sp) {
-    sb_error.SetError(watchpoint_sp->GetError());
+    sb_error.SetError(watchpoint_sp->GetError().Clone());
   }
   return sb_error;
 }
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index f8f2b97eb898fa..e3291640fa9352 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1874,8 +1874,8 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
 
   ~CommandObjectScriptingObjectParsed() override = default;
 
-  Status GetOptionsError() { return m_options_error; }
-  Status GetArgsError() { return m_args_error; }
+  Status GetOptionsError() { return m_options_error.Clone(); }
+  Status GetArgsError() { return m_args_error.Clone(); }
   bool WantsCompletion() override { return true; }
 
   bool IsRemovable() const override { return true; }
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 1266355578e321..9bdc5a3949751d 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -258,7 +258,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
         StreamString feedback_stream;
         if (!target_sp->LoadScriptingResources(errors, feedback_stream)) {
           Stream &s = GetErrorStream();
-          for (auto error : errors) {
+          for (auto &error : errors) {
             s.Printf("%s\n", error.AsCString());
           }
           if (feedback_stream.GetSize())
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index bba4199ce9e837..2b8ccab2406c6b 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -1046,8 +1046,8 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
     return false;
   std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
   for (auto module : m_modules) {
-    Status error;
     if (module) {
+      Status error;
       if (!module->LoadScriptingResourceInTarget(target, error,
                                                  feedback_stream)) {
         if (error.Fail() && error.AsCString()) {
@@ -1058,8 +1058,7 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
                   .GetFileNameStrippingExtension()
                   .GetCString(),
               error.AsCString());
-          errors.push_back(error);
-
+          errors.push_back(std::move(error));
           if (!continue_on_error)
             return false;
         }
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index d56bd004e63c7e..1bedd87e943dc3 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -2763,7 +2763,7 @@ ValueObjectSP ValueObject::CreateConstantValue(ConstString name) {
   if (!valobj_sp) {
     ExecutionContext exe_ctx(GetExecutionContextRef());
     valobj_sp = ValueObjectConstResult::Create(
-        exe_ctx.GetBestExecutionContextScope(), m_error);
+        exe_ctx.GetBestExecutionContextScope(), m_error.Clone());
   }
   return valobj_sp;
 }
@@ -2974,7 +2974,7 @@ ValueObjectSP ValueObject::Cast(const CompilerType &compiler_type) {
 
   return ValueObjectConstResult::Create(
       ExecutionContext(GetExecutionContextRef()).GetBestExecutionContextScope(),
-                       error);
+      std::move(error));
 }
 
 lldb::ValueObjectSP ValueObject::Clone(ConstString new_name) {
diff --git a/lldb/source/Core/ValueObjectCast.cpp b/lldb/source/Core/ValueObjectCast.cpp
index c8e31641514170..308fa161180d41 100644
--- a/lldb/source/Core/ValueObjectCast.cpp
+++ b/lldb/source/Core/ValueObjectCast.cpp
@@ -86,7 +86,7 @@ bool ValueObjectCast::UpdateValue() {
 
   // The dynamic value failed to get an error, pass the error along
   if (m_error.Success() && m_parent->GetError().Fail())
-    m_error = m_parent->GetError();
+    m_error = m_parent->GetError().Clone();
   SetValueIsValid(false);
   return false;
 }
diff --git a/lldb/source/Core/ValueObjectConstResult.cpp b/lldb/source/Core/ValueObjectConstResult.cpp
index 879d3c3f6b0372..60850c15e6a832 100644
--- a/lldb/source/Core/ValueObjectConstResult.cpp
+++ b/lldb/source/Core/ValueObjectConstResult.cpp
@@ -169,16 +169,17 @@ ValueObjectConstResult::ValueObjectConstResult(
 }
 
 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
-                                             const Status &error) {
+                                             Status &&error) {
   auto manager_sp = ValueObjectManager::Create();
-  return (new ValueObjectConstResult(exe_scope, *manager_sp, error))->GetSP();
+  return (new ValueObjectConstResult(exe_scope, *manager_sp, std::move(error)))
+      ->GetSP();
 }
 
 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
                                                ValueObjectManager &manager,
-                                               const Status &error)
+                                               Status &&error)
     : ValueObject(exe_scope, manager), m_impl(this) {
-  m_error = error;
+  m_error = std::move(error);
   SetIsConstant();
 }
 
diff --git a/lldb/source/Core/ValueObjectDynamicValue.cpp b/lldb/source/Core/ValueObjectDynamicValue.cpp
index d6c523e99f10d2..67311ea6e3be45 100644
--- a/lldb/source/Core/ValueObjectDynamicValue.cpp
+++ b/lldb/source/Core/ValueObjectDynamicValue.cpp
@@ -118,7 +118,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
   if (!m_parent->UpdateValueIfNeeded(false)) {
     // The dynamic value failed to get an error, pass the error along
     if (m_error.Success() && m_parent->GetError().Fail())
-      m_error = m_parent->GetError();
+      m_error = m_parent->GetError().Clone();
     return false;
   }
 
diff --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
index adac1b400705e2..091b8f883b6050 100644
--- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp
+++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
@@ -169,7 +169,7 @@ bool ValueObjectSynthetic::UpdateValue() {
     // our parent could not update.. as we are meaningless without a parent,
     // just stop
     if (m_parent->GetError().Fail())
-      m_error = m_parent->GetError();
+      m_error = m_parent->GetError().Clone();
     return false;
   }
 
diff --git a/lldb/source/Expression/FunctionCaller.cpp b/lldb/source/Expression/FunctionCaller.cpp
index 5ac2b0681ebbec..bf5573d35f53e0 100644
--- a/lldb/source/Expression/FunctionCaller.cpp
+++ b/lldb/source/Expression/FunctionCaller.cpp
@@ -390,8 +390,7 @@ lldb::ExpressionResults FunctionCaller::ExecuteFunction(
       LLDB_LOGF(log,
                 "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
                 "completed abnormally: %s ==",
-                m_name.c_str(),
-                Process::ExecutionResultAsCString(return_value));
+                m_name.c_str(), ExecutionResultAsCString(return_value));
     } else {
       LLDB_LOGF(log,
                 "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
diff --git a/lldb/source/Expression/LLVMUserExpression.cpp b/lldb/source/Expression/LLVMUserExpression.cpp
index b4fdfc4d1fa8ba..1f9ba1ece439ee 100644
--- a/lldb/source/Expression/LLVMUserExpression.cpp
+++ b/lldb/source/Expression/LLVMUserExpression.cpp
@@ -235,9 +235,9 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
           expr_thread_id);
       return execution_result;
     } else if (execution_result != lldb::eExpressionCompleted) {
-      diagnostic_manager.Printf(
-          lldb::eSeverityError, "Couldn't execute function; result was %s",
-          Process::ExecutionResultAsCString(execution_result));
+      diagnostic_manager.Printf(lldb::eSeverityError,
+                                "Couldn't execute function; result was %s",
+                                ExecutionResultAsCString(execution_result));
       return execution_result;
     }
   }
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index fa0edad1fa583f..8097e38919b047 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -462,7 +462,7 @@ class EntityVariableBase : public Materializer::Entity {
       return;
     }
 
-    Status valobj_error = valobj_sp->GetError();
+    Status valobj_error = valobj_sp->GetError().Clone();
 
     if (valobj_error.Fail()) {
       err = Status::FromErrorStringWithFormat(
diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp
index c2889e4c986bfe..872f6304f91baa 100644
--- a/lldb/source/Expression/UserExpression.cpp
+++ b/lldb/source/Expression/UserExpression.cpp
@@ -268,10 +268,10 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
   const bool generate_debug_info = options.GetGenerateDebugInfo();
 
   if (options.InvokeCancelCallback(lldb::eExpressionEvaluationParse)) {
-    error = Status::FromErrorString(
+    Status error = Status::FromErrorString(
         "expression interrupted by callback before parse");
     result_valobj_sp = ValueObjectConstResult::Create(
-        exe_ctx.GetBestExecutionContextScope(), error);
+        exe_ctx.GetBestExecutionContextScope(), std::move(error));
     return lldb::eExpressionInterrupted;
   }
 
@@ -364,7 +364,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
             lldb::eExpressionInterrupted,
             "expression interrupted by callback before execution");
         result_valobj_sp = ValueObjectConstResult::Create(
-            exe_ctx.GetBestExecutionContextScope(), error);
+            exe_ctx.GetBestExecutionContextScope(), std::move(error));
         return lldb::eExpressionInterrupted;
       }
 
@@ -415,7 +415,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
 
   if (result_valobj_sp.get() == nullptr) {
     result_valobj_sp = ValueObjectConstResult::Create(
-        exe_ctx.GetBestExecutionContextScope(), error);
+        exe_ctx.GetBestExecutionContextScope(), std::move(error));
   }
 
   return execution_results;
diff --git a/lldb/source/Host/common/LockFileBase.cpp b/lldb/source/Host/common/LockFileBase.cpp
index 01a8c38cef58ef..6ef684e6d622c1 100644
--- a/lldb/source/Host/common/LockFileBase.cpp
+++ b/lldb/source/Host/common/LockFileBase.cpp
@@ -50,7 +50,7 @@ Status LockFileBase::Unlock() {
   if (!IsLocked())
     return NotLocked();
 
-  const auto error = DoUnlock();
+  Status error = DoUnlock();
   if (error.Success()) {
     m_locked = false;
     m_start = 0;
@@ -69,7 +69,7 @@ Status LockFileBase::DoLock(const Locker &locker, const uint64_t start,
   if (IsLocked())
     return AlreadyLocked();
 
-  const auto error = locker(start, len);
+  Status error = locker(start, len);
   if (error.Success()) {
     m_locked = true;
     m_start = start;
diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp
index a84d8db1c8794a..e36eefaa6f4a49 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.cpp
+++ b/lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -215,17 +215,17 @@ Status NativeProcessProtocol::RemoveWatchpoint(lldb::addr_t addr) {
   for (const auto &thread : m_threads) {
     assert(thread && "thread list should not have a NULL thread!");
 
-    const Status thread_error = thread->RemoveWatchpoint(addr);
+    Status thread_error = thread->RemoveWatchpoint(addr);
     if (thread_error.Fail()) {
       // Keep track of the first thread error if any threads fail. We want to
       // try to remove the watchpoint from every thread, though, even if one or
       // more have errors.
       if (!overall_error.Fail())
-        overall_error = thread_error;
+        overall_error = std::move(thread_error);
     }
   }
-  const Status error = m_watchpoint_list.Remove(addr);
-  return overall_error.Fail() ? overall_error : error;
+  Status error = m_watchpoint_list.Remove(addr);
+  return overall_error.Fail() ? std::move(overall_error) : std::move(error);
 }
 
 const HardwareBreakpointMap &
diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
index 2a2fcf00c0adfe..d0cc68826d4bb7 100644
--- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -233,7 +233,7 @@ ConnectionStatus ConnectionFileDescriptor::Disconnect(Status *error_ptr) {
   if (error.Fail())
     status = eConnectionStatusError;
   if (error_ptr)
-    *error_ptr = error;
+    *error_ptr = std::move(error);
 
   // Close any pipes we were using for async interrupts
   m_pipe.Close();
@@ -295,7 +295,7 @@ size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
   }
 
   if (error_ptr)
-    *error_ptr = error;
+    *error_ptr = error.Clone();
 
   if (error.Fail()) {
     uint32_t error_value = error.GetError();
@@ -393,7 +393,7 @@ size_t ConnectionFileDescriptor::Write(const void *src, size_t src_len,
   }
 
   if (error_ptr)
-    *error_ptr = error;
+    *error_ptr = error.Clone();
 
   if (error.Fail()) {
     switch (error.GetError()) {
@@ -476,7 +476,7 @@ ConnectionFileDescriptor::BytesAvailable(const Timeout<std::micro> &timeout,
       Status error = select_helper.Select();
 
       if (error_ptr)
-        *error_ptr = error;
+        *error_ptr = error.Clone();
 
       if (error.Fail()) {
         switch (error.GetError()) {
@@ -557,7 +557,7 @@ lldb::ConnectionStatus ConnectionFileDescriptor::AcceptSocket(
   }
 
   if (error_ptr)
-    *error_ptr = error;
+    *error_ptr = error.Clone();
   return eConnectionStatusError;
 }
 
@@ -579,7 +579,7 @@ ConnectionFileDescriptor::ConnectSocket(Socket::SocketProtocol socket_protocol,
   }
 
   if (error_ptr)
-    *error_ptr = error;
+    *error_ptr = error.Clone();
   return eConnectionStatusError;
 }
 
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index df539d5f5bcee9..b93f47a8a8d5ec 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1861,7 +1861,7 @@ CommandInterpreter::PreprocessToken(std::string &expr_str) {
   // But if for some reason we didn't get a value object at all, then we will
   // make up some helpful errors from the expression result.
   if (expr_result_valobj_sp)
-    error = expr_result_valobj_sp->GetError();
+    error = expr_result_valobj_sp->GetError().Clone();
 
   if (error.Success()) {
     std::string result = lldb_private::toString(expr_result) +
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 079ab9044de63a..8b55221da6e761 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -96,7 +96,7 @@ lldb::ProcessLaunchInfoSP ScriptInterpreter::GetOpaqueTypeFromSBLaunchInfo(
 Status
 ScriptInterpreter::GetStatusFromSBError(const lldb::SBError &error) const {
   if (error.m_opaque_up)
-    return *error.m_opaque_up;
+    return error.m_opaque_up->Clone();
 
   return Status();
 }
diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
index 00e66f8818f077..a179260ca15f60 100644
--- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp
+++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
@@ -173,7 +173,7 @@ Status AdbClient::SetPortForwarding(const uint16_t local_port,
   snprintf(message, sizeof(message), "forward:tcp:%d;tcp:%d", local_port,
            remote_port);
 
-  const auto error = SendDeviceMessage(message);
+  Status error = SendDeviceMessage(message);
   if (error.Fail())
     return error;
 
@@ -192,7 +192,7 @@ AdbClient::SetPortForwarding(const uint16_t local_port,
   snprintf(message, sizeof(message), "forward:tcp:%d;%s:%s", local_port,
            sock_namespace_str, remote_socket_name.str().c_str());
 
-  const auto error = SendDeviceMessage(message);
+  Status error = SendDeviceMessage(message);
   if (error.Fail())
     return error;
 
@@ -203,7 +203,7 @@ Status AdbClient::DeletePortForwarding(const uint16_t local_port) {
   char message[32];
   snprintf(message, sizeof(message), "killforward:tcp:%d", local_port);
 
-  const auto error = SendDeviceMessage(message);
+  Status error = SendDeviceMessage(message);
   if (error.Fail())
     return error;
 
@@ -588,7 +588,7 @@ AdbClient::SyncService::executeCommand(const std::function<Status()> &cmd) {
   if (!m_conn)
     return Status::FromErrorString("SyncService is disconnected");
 
-  const auto error = cmd();
+  Status error = cmd();
   if (error.Fail())
     m_conn.reset();
 
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
index de7031701df4d8..d18b718d4a56cf 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -189,8 +189,8 @@ Status PlatformAndroidRemoteGDBServer::MakeConnectURL(
   Status error;
 
   auto forward = [&](const uint16_t local, const uint16_t remote) {
-    error = ForwardPortWithAdb(local, remote, remote_socket_name,
-                               m_socket_namespace, m_device_id);
+    Status error = ForwardPortWithAdb(local, remote, remote_socket_name,
+                                      m_socket_namespace, m_device_id);
     if (error.Success()) {
       m_port_forwards[pid] = local;
       std::ostringstream url_str;
diff --git a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.h b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.h
index b2956054d50bf4..57dd32f587a652 100644
--- a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.h
+++ b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.h
@@ -34,7 +34,7 @@ class Process {
 
   explicit operator bool() { return m_pid != LLDB_INVALID_PROCESS_ID; }
 
-  lldb_private::Status GetError() { return m_error; }
+  lldb_private::Status GetError() { return m_error.Clone(); }
 
 private:
   Process(lldb::pid_t p);
diff --git a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
index 303a5409c6fe4b..f3e79d3d56154e 100644
--- a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
+++ b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
@@ -61,10 +61,10 @@ - (BOOL)spawnWithPath:(NSString *)path
 CoreSimulatorSupport::Process::Process(lldb::pid_t p) : m_pid(p), m_error() {}
 
 CoreSimulatorSupport::Process::Process(Status error)
-    : m_pid(LLDB_INVALID_PROCESS_ID), m_error(error) {}
+    : m_pid(LLDB_INVALID_PROCESS_ID), m_error(std::move(error)) {}
 
 CoreSimulatorSupport::Process::Process(lldb::pid_t p, Status error)
-    : m_pid(p), m_error(error) {}
+    : m_pid(p), m_error(std::move(error)) {}
 
 CoreSimulatorSupport::DeviceType::DeviceType() : m_model_identifier() {}
 
@@ -498,19 +498,19 @@ static Status HandleFileAction(ProcessLaunchInfo &launch_info,
                            STDIN_FILENO, stdin_file);
 
   if (error.Fail())
-    return CoreSimulatorSupport::Process(error);
+    return CoreSimulatorSupport::Process(std::move(error));
 
   error = HandleFileAction(launch_info, options, kSimDeviceSpawnStdout,
                            STDOUT_FILENO, stdout_file);
 
   if (error.Fail())
-    return CoreSimulatorSupport::Process(error);
+    return CoreSimulatorSupport::Process(std::move(error));
 
   error = HandleFileAction(launch_info, options, kSimDeviceSpawnStderr,
                            STDERR_FILENO, stderr_file);
 
   if (error.Fail())
-    return CoreSimulatorSupport::Process(error);
+    return CoreSimulatorSupport::Process(std::move(error));
 
 #undef kSimDeviceSpawnEnvironment
 #undef kSimDeviceSpawnStdin
@@ -539,7 +539,7 @@ static Status HandleFileAction(ProcessLaunchInfo &launch_info,
                                                    : "unable to launch");
   }
 
-  return CoreSimulatorSupport::Process(pid, error);
+  return CoreSimulatorSupport::Process(pid, std::move(error));
 }
 
 CoreSimulatorSupport::DeviceSet
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index 70b49c0424bbbf..31315e46ca168d 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -544,7 +544,7 @@ Status PlatformPOSIX::EvaluateLibdlExpression(
     return expr_error;
 
   if (result_valobj_sp->GetError().Fail())
-    return result_valobj_sp->GetError();
+    return result_valobj_sp->GetError().Clone();
   return Status();
 }
 
@@ -976,7 +976,7 @@ Status PlatformPOSIX::UnloadImage(lldb_private::Process *process,
     return error;
 
   if (result_valobj_sp->GetError().Fail())
-    return result_valobj_sp->GetError();
+    return result_valobj_sp->GetError().Clone();
 
   Scalar scalar;
   if (result_valobj_sp->ResolveValue(scalar)) {
diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
index 8173b7c3b50035..7352d6f33f2174 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -444,7 +444,7 @@ Status PlatformWindows::UnloadImage(Process *process, uint32_t image_token) {
     return result;
 
   if (value->GetError().Fail())
-    return value->GetError();
+    return value->GetError().Clone();
 
   Scalar scalar;
   if (value->ResolveValue(scalar)) {
@@ -805,7 +805,7 @@ extern "C" {
     return error;
 
   if (value->GetError().Fail())
-    return value->GetError();
+    return value->GetError().Clone();
 
   return Status();
 }
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
index 8ba31b31e8dc1c..f5fc337a8028ef 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
@@ -111,7 +111,7 @@ bool ScriptedProcessPythonInterface::CreateBreakpoint(lldb::addr_t addr,
 
   // If there was an error on the python call, surface it to the user.
   if (py_error.Fail())
-    error = py_error;
+    error = std::move(py_error);
 
   if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
                                                     error))
@@ -128,7 +128,7 @@ lldb::DataExtractorSP ScriptedProcessPythonInterface::ReadMemoryAtAddress(
 
   // If there was an error on the python call, surface it to the user.
   if (py_error.Fail())
-    error = py_error;
+    error = std::move(py_error);
 
   return data_sp;
 }
@@ -145,7 +145,7 @@ lldb::offset_t ScriptedProcessPythonInterface::WriteMemoryAtAddress(
 
   // If there was an error on the python call, surface it to the user.
   if (py_error.Fail())
-    error = py_error;
+    error = std::move(py_error);
 
   return obj->GetUnsignedIntegerValue(LLDB_INVALID_OFFSET);
 }
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index c1dcdc7df6cee3..cb6f6ec3989260 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -309,8 +309,12 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
     return python::PythonBoolean(arg);
   }
 
-  python::PythonObject Transform(Status arg) {
-    return python::SWIGBridge::ToSWIGWrapper(arg);
+  python::PythonObject Transform(const Status &arg) {
+    return python::SWIGBridge::ToSWIGWrapper(arg.Clone());
+  }
+
+  python::PythonObject Transform(Status &&arg) {
+    return python::SWIGBridge::ToSWIGWrapper(std::move(arg));
   }
 
   python::PythonObject Transform(const StructuredDataImpl &arg) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
index 148932d67b908c..1267e20f087121 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -268,7 +268,7 @@ class DWARFUnit : public UserID {
   /// .dwo file. Things like a missing .dwo file, DWO ID mismatch, and other
   /// .dwo errors can be stored in each compile unit so the issues can be
   /// communicated to the user.
-  void SetDwoError(const Status &error) { m_dwo_error = error; }
+  void SetDwoError(Status &&error) { m_dwo_error = std::move(error); }
 
 protected:
   DWARFUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index ff44329d081caa..f721ca00fd3559 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -4480,7 +4480,7 @@ Status SymbolFileDWARF::CalculateFrameVariableError(StackFrame &frame) {
   dwarf_cu->ExtractUnitDIEIfNeeded();
   const Status &dwo_error = dwarf_cu->GetDwoError();
   if (dwo_error.Fail())
-    return dwo_error;
+    return dwo_error.Clone();
 
   // Don't return an error for assembly files as they typically don't have
   // varaible information.
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 0cd2d06cd708cc..08ea4c6d1645ad 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -1574,7 +1574,7 @@ Status SymbolFileDWARFDebugMap::CalculateFrameVariableError(StackFrame &frame) {
             // we weren't able to open the .o file. Display an appropriate
             // error
             if (comp_unit_info->oso_load_error.Fail())
-              return comp_unit_info->oso_load_error;
+              return comp_unit_info->oso_load_error.Clone();
             else
               return Status::FromErrorStringWithFormat(
                   "unable to load debug map object file \"%s\" "
diff --git a/lldb/source/Target/ModuleCache.cpp b/lldb/source/Target/ModuleCache.cpp
index ccae7ea106c974..f737836e0d9712 100644
--- a/lldb/source/Target/ModuleCache.cpp
+++ b/lldb/source/Target/ModuleCache.cpp
@@ -139,7 +139,7 @@ Status CreateHostSysRootModuleLink(const FileSpec &root_dir_spec,
     DecrementRefExistingModule(root_dir_spec, sysroot_module_path_spec);
   }
 
-  const auto error = MakeDirectory(
+  Status error = MakeDirectory(
       FileSpec(sysroot_module_path_spec.GetDirectory().AsCString()));
   if (error.Fail())
     return error;
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 7792edcc2cb582..3e7546048e5862 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -549,7 +549,7 @@ Status Platform::Install(const FileSpec &src, const FileSpec &dst) {
         RecurseCopyBaton baton = {recurse_dst, this, Status()};
         FileSystem::Instance().EnumerateDirectory(
             src_dir_path, true, true, true, RecurseCopy_Callback, &baton);
-        return baton.error;
+        return std::move(baton.error);
       }
     } break;
 
@@ -1566,7 +1566,7 @@ Status Platform::GetRemoteSharedModule(const ModuleSpec &module_spec,
   //      resolved_module_spec.
 
   // Trying to find a module by UUID on local file system.
-  const Status error = module_resolver(resolved_module_spec);
+  Status error = module_resolver(resolved_module_spec);
   if (error.Success()) {
     if (module_sp && symbol_file_spec) {
       // Set the symbol file to the module if the locate modudle callback was
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 3d7ddbe294a49c..40f3115f1ff6de 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -2147,7 +2147,6 @@ size_t Process::ReadCStringFromMemory(addr_t addr, char *dst,
     result_error.Clear();
     // NULL out everything just to be safe
     memset(dst, 0, dst_max_len);
-    Status error;
     addr_t curr_addr = addr;
     const size_t cache_line_size = m_memory_cache.GetMemoryCacheLineSize();
     size_t bytes_left = dst_max_len - 1;
@@ -2158,10 +2157,11 @@ size_t Process::ReadCStringFromMemory(addr_t addr, char *dst,
           cache_line_size - (curr_addr % cache_line_size);
       addr_t bytes_to_read =
           std::min<addr_t>(bytes_left, cache_line_bytes_left);
+      Status error;
       size_t bytes_read = ReadMemory(curr_addr, curr_dst, bytes_to_read, error);
 
       if (bytes_read == 0) {
-        result_error = error;
+        result_error = std::move(error);
         dst[total_cstr_len] = '\0';
         break;
       }
@@ -5743,43 +5743,6 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
   return return_value;
 }
 
-const char *Process::ExecutionResultAsCString(ExpressionResults result) {
-  const char *result_name = "<unknown>";
-
-  switch (result) {
-  case eExpressionCompleted:
-    result_name = "eExpressionCompleted";
-    break;
-  case eExpressionDiscarded:
-    result_name = "eExpressionDiscarded";
-    break;
-  case eExpressionInterrupted:
-    result_name = "eExpressionInterrupted";
-    break;
-  case eExpressionHitBreakpoint:
-    result_name = "eExpressionHitBreakpoint";
-    break;
-  case eExpressionSetupError:
-    result_name = "eExpressionSetupError";
-    break;
-  case eExpressionParseError:
-    result_name = "eExpressionParseError";
-    break;
-  case eExpressionResultUnavailable:
-    result_name = "eExpressionResultUnavailable";
-    break;
-  case eExpressionTimedOut:
-    result_name = "eExpressionTimedOut";
-    break;
-  case eExpressionStoppedForDebug:
-    result_name = "eExpressionStoppedForDebug";
-    break;
-  case eExpressionThreadVanished:
-    result_name = "eExpressionThreadVanished";
-  }
-  return result_name;
-}
-
 void Process::GetStatus(Stream &strm) {
   const StateType state = GetState();
   if (StateIsStoppedState(state, false)) {
diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp
index 1610971a34148b..fe0d4c93c50627 100644
--- a/lldb/source/Target/StackFrame.cpp
+++ b/lldb/source/Target/StackFrame.cpp
@@ -1117,7 +1117,7 @@ bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Status *error_ptr) {
     frame_base = m_frame_base;
 
   if (error_ptr)
-    *error_ptr = m_frame_base_error;
+    *error_ptr = m_frame_base_error.Clone();
   return m_frame_base_error.Success();
 }
 
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index fcac0a48f46e6d..f1c378b968d2ba 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1986,7 +1986,6 @@ size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
     result_error.Clear();
     // NULL out everything just to be safe
     memset(dst, 0, dst_max_len);
-    Status error;
     addr_t curr_addr = addr.GetLoadAddress(this);
     Address address(addr);
 
@@ -2003,11 +2002,12 @@ size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
           cache_line_size - (curr_addr % cache_line_size);
       addr_t bytes_to_read =
           std::min<addr_t>(bytes_left, cache_line_bytes_left);
+      Status error;
       size_t bytes_read = ReadMemory(address, curr_dst, bytes_to_read, error,
                                      force_live_memory);
 
       if (bytes_read == 0) {
-        result_error = error;
+        result_error = std::move(error);
         dst[total_cstr_len] = '\0';
         break;
       }
@@ -2401,7 +2401,7 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
     }
   }
   if (error_ptr)
-    *error_ptr = error;
+    *error_ptr = std::move(error);
   return module_sp;
 }
 
@@ -2730,7 +2730,7 @@ ExpressionResults Target::EvaluateExpression(
     // Pass up the error by wrapping it inside an error result.
     if (error.Fail() && !result_valobj_sp)
       result_valobj_sp = ValueObjectConstResult::Create(
-          exe_ctx.GetBestExecutionContextScope(), error);
+          exe_ctx.GetBestExecutionContextScope(), std::move(error));
   }
 
   if (execution_results == eExpressionCompleted)
@@ -3348,10 +3348,8 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
     else
       error = m_process_sp->Resume();
     if (!error.Success()) {
-      Status error2;
-      error2 = Status::FromErrorStringWithFormat(
+      error = Status::FromErrorStringWithFormat(
           "process resume at entry point failed: %s", error.AsCString());
-      error = error2;
     }
   } break;
   case eStateExited: {
diff --git a/lldb/source/Utility/Status.cpp b/lldb/source/Utility/Status.cpp
index 131fc662bfc0a5..e1659754f808eb 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -107,6 +107,13 @@ llvm::Error Status::ToError() const {
 
 Status::~Status() = default;
 
+const Status &Status::operator=(Status &&other) {
+  m_code = other.m_code;
+  m_type = other.m_type;
+  m_string = std::move(other.m_string);
+  return *this;
+}
+
 #ifdef _WIN32
 static std::string RetrieveWin32ErrorString(uint32_t error_code) {
   char *buffer = nullptr;
@@ -204,3 +211,29 @@ void llvm::format_provider<lldb_private::Status>::format(
   llvm::format_provider<llvm::StringRef>::format(error.AsCString(), OS,
                                                  Options);
 }
+
+const char *lldb_private::ExecutionResultAsCString(ExpressionResults result) {
+  switch (result) {
+  case eExpressionCompleted:
+    return "eExpressionCompleted";
+  case eExpressionDiscarded:
+    return "eExpressionDiscarded";
+  case eExpressionInterrupted:
+    return "eExpressionInterrupted";
+  case eExpressionHitBreakpoint:
+    return "eExpressionHitBreakpoint";
+  case eExpressionSetupError:
+    return "eExpressionSetupError";
+  case eExpressionParseError:
+    return "eExpressionParseError";
+  case eExpressionResultUnavailable:
+    return "eExpressionResultUnavailable";
+  case eExpressionTimedOut:
+    return "eExpressionTimedOut";
+  case eExpressionStoppedForDebug:
+    return "eExpressionStoppedForDebug";
+  case eExpressionThreadVanished:
+    return "eExpressionThreadVanished";
+  }
+  return "<unknown>";
+}
diff --git a/lldb/unittests/Target/RemoteAwarePlatformTest.cpp b/lldb/unittests/Target/RemoteAwarePlatformTest.cpp
index d7810b20af95d5..82c68a8ca2d5ca 100644
--- a/lldb/unittests/Target/RemoteAwarePlatformTest.cpp
+++ b/lldb/unittests/Target/RemoteAwarePlatformTest.cpp
@@ -33,8 +33,8 @@ class RemoteAwarePlatformTester : public RemoteAwarePlatform {
   MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
 
   MOCK_METHOD2(ResolveExecutable,
-               std::pair<Status, ModuleSP>(const ModuleSpec &,
-                                           const FileSpecList *));
+               std::pair<bool, ModuleSP>(const ModuleSpec &,
+                                         const FileSpecList *));
   Status
   ResolveExecutable(const ModuleSpec &module_spec,
                     lldb::ModuleSP &exe_module_sp,
@@ -42,7 +42,7 @@ class RemoteAwarePlatformTester : public RemoteAwarePlatform {
   { // NOLINT(modernize-use-override)
     auto pair = ResolveExecutable(module_spec, module_search_paths_ptr);
     exe_module_sp = pair.second;
-    return pair.first;
+    return pair.first ? Status() : Status::FromErrorString("error");
   }
 
   void SetRemotePlatform(lldb::PlatformSP platform) {
@@ -80,8 +80,9 @@ TEST_F(RemoteAwarePlatformTest, TestResolveExecutabelOnClientByPlatform) {
   static const ArchSpec process_host_arch;
   EXPECT_CALL(platform, GetSupportedArchitectures(process_host_arch))
       .WillRepeatedly(Return(std::vector<ArchSpec>()));
+  Status success;
   EXPECT_CALL(platform, ResolveExecutable(_, _))
-      .WillRepeatedly(Return(std::make_pair(Status(), expected_executable)));
+      .WillRepeatedly(Return(std::make_pair(true, expected_executable)));
 
   platform.SetRemotePlatform(std::make_shared<TargetPlatformTester>(false));
 



More information about the lldb-commits mailing list