[Lldb-commits] [lldb] [lldb] Make conversions from llvm::Error explicit with Status::FromEr… (PR #107163)

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 3 15:47:27 PDT 2024


https://github.com/adrian-prantl created https://github.com/llvm/llvm-project/pull/107163

…ror() [NFC]

Broken out from https://github.com/llvm/llvm-project/pull/106774 for easier review.

>From 012b0a7d135a4d4816c78988d6145595c7852b0e Mon Sep 17 00:00:00 2001
From: Adrian Prantl <aprantl at apple.com>
Date: Tue, 3 Sep 2024 15:29:25 -0700
Subject: [PATCH] [lldb] Make conversions from llvm::Error explicit with
 Status::FromError() [NFC]

---
 lldb/include/lldb/Utility/Status.h            |   6 +-
 lldb/source/API/SBDebugger.cpp                |   2 +-
 lldb/source/API/SBTarget.cpp                  |   2 +-
 .../Commands/CommandObjectBreakpoint.cpp      | 103 ++++++++++--------
 .../Commands/CommandObjectMemoryTag.cpp       |  10 +-
 lldb/source/Commands/CommandObjectStats.cpp   |   6 +-
 lldb/source/Commands/CommandObjectTrace.cpp   |   2 +-
 lldb/source/Core/PluginManager.cpp            |   2 +-
 lldb/source/Core/ThreadedCommunication.cpp    |   2 +-
 lldb/source/Core/ValueObjectVTable.cpp        |   2 +-
 lldb/source/Core/ValueObjectVariable.cpp      |   2 +-
 lldb/source/DataFormatters/VectorType.cpp     |   2 +-
 lldb/source/Host/common/FileCache.cpp         |   2 +-
 .../Host/common/NativeProcessProtocol.cpp     |   2 +-
 lldb/source/Host/common/TCPSocket.cpp         |   6 +-
 lldb/source/Host/macosx/objcxx/Host.mm        |   2 +-
 .../posix/ConnectionFileDescriptorPosix.cpp   |   6 +-
 lldb/source/Interpreter/CommandObject.cpp     |   2 +-
 lldb/source/Interpreter/OptionValueRegex.cpp  |   2 +-
 .../Language/CPlusPlus/BlockPointer.cpp       |   2 +-
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp     |   2 +-
 .../Minidump/ObjectFileMinidump.cpp           |   2 +-
 ...latformiOSSimulatorCoreSimulatorSupport.mm |   2 +-
 .../NativeRegisterContextDBReg_arm64.cpp      |  10 +-
 .../Process/elf-core/ProcessElfCore.cpp       |   2 +-
 .../gdb-remote/GDBRemoteCommunication.cpp     |   2 +-
 .../GDBRemoteCommunicationClient.cpp          |   2 +-
 .../GDBRemoteCommunicationServer.cpp          |   2 +-
 .../GDBRemoteCommunicationServerLLGS.cpp      |   8 +-
 .../GDBRemoteCommunicationServerPlatform.cpp  |   2 +-
 .../Process/minidump/ProcessMinidump.cpp      |   2 +-
 .../Interfaces/ScriptedPythonInterface.h      |   2 +-
 .../Python/PythonDataObjects.cpp              |  22 ++--
 .../Python/ScriptInterpreterPython.cpp        |  10 +-
 .../DarwinLog/StructuredDataDarwinLog.cpp     |   2 +-
 lldb/source/Target/ModuleCache.cpp            |   2 +-
 lldb/source/Target/Platform.cpp               |   2 +-
 lldb/source/Target/Process.cpp                |   4 +-
 lldb/source/Target/StackFrame.cpp             |   2 +-
 lldb/source/Target/Thread.cpp                 |   3 +-
 lldb/source/Utility/Scalar.cpp                |   2 +-
 lldb/source/Utility/Status.cpp                |  10 +-
 lldb/source/Utility/StructuredData.cpp        |   2 +-
 .../Host/NativeProcessTestUtils.h             |   4 +-
 lldb/unittests/Utility/StatusTest.cpp         |  14 ++-
 45 files changed, 150 insertions(+), 132 deletions(-)

diff --git a/lldb/include/lldb/Utility/Status.h b/lldb/include/lldb/Utility/Status.h
index b304291ffae00e..aaf082648c0889 100644
--- a/lldb/include/lldb/Utility/Status.h
+++ b/lldb/include/lldb/Utility/Status.h
@@ -91,9 +91,8 @@ class Status {
 
   ~Status();
 
-  // llvm::Error support
-  explicit Status(llvm::Error error) { *this = std::move(error); }
-  const Status &operator=(llvm::Error error);
+  /// Avoid using this in new code. Migrate APIs to llvm::Expected instead.
+  static Status FromError(llvm::Error &&error);
   llvm::Error ToError() const;
 
   /// Get the error string associated with the current error.
@@ -145,6 +144,7 @@ class Status {
   bool Success() const;
 
 protected:
+  Status(llvm::Error &&);
   /// Status code as an integer value.
   ValueType m_code = 0;
   /// The type of the above error code.
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 72501570320d57..c226acc15018ef 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -220,7 +220,7 @@ lldb::SBError SBDebugger::InitializeWithErrorHandling() {
   SBError error;
   if (auto e = g_debugger_lifetime->Initialize(
           std::make_unique<SystemInitializerFull>(), LoadPlugin)) {
-    error.SetError(Status(std::move(e)));
+    error.SetError(Status::FromError(std::move(e)));
   }
   return error;
 }
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index e927cb854cd88c..41eb77e5506bc5 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1658,7 +1658,7 @@ SBError SBTarget::SetLabel(const char *label) {
   if (!target_sp)
     return Status::FromErrorString("Couldn't get internal target object.");
 
-  return Status(target_sp->SetLabel(label));
+  return Status::FromError(target_sp->SetLabel(label));
 }
 
 uint32_t SBTarget::GetDataByteSize() {
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index ede3dd2f2a864c..494d6c50e94ac3 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -89,14 +89,16 @@ class lldb_private::BreakpointOptionGroup : public OptionGroup {
       if (success)
         m_bp_opts.SetAutoContinue(value);
       else
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_bool_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_bool_parsing_error_message));
     } break;
     case 'i': {
       uint32_t ignore_count;
       if (option_arg.getAsInteger(0, ignore_count))
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_int_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_int_parsing_error_message));
       else
         m_bp_opts.SetIgnoreCount(ignore_count);
     } break;
@@ -106,29 +108,31 @@ class lldb_private::BreakpointOptionGroup : public OptionGroup {
       if (success) {
         m_bp_opts.SetOneShot(value);
       } else
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_bool_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_bool_parsing_error_message));
     } break;
     case 't': {
       lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID;
       if (option_arg == "current") {
         if (!execution_context) {
-          error = CreateOptionParsingError(
+          error = Status::FromError(CreateOptionParsingError(
               option_arg, short_option, long_option,
-              "No context to determine current thread");
+              "No context to determine current thread"));
         } else {
           ThreadSP ctx_thread_sp = execution_context->GetThreadSP();
           if (!ctx_thread_sp || !ctx_thread_sp->IsValid()) {
-            error =
+            error = Status::FromError(
                 CreateOptionParsingError(option_arg, short_option, long_option,
-                                         "No currently selected thread");
+                                         "No currently selected thread"));
           } else {
             thread_id = ctx_thread_sp->GetID();
           }
         }
       } else if (option_arg.getAsInteger(0, thread_id)) {
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_int_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_int_parsing_error_message));
       }
       if (thread_id != LLDB_INVALID_THREAD_ID)
         m_bp_opts.SetThreadID(thread_id);
@@ -142,8 +146,9 @@ class lldb_private::BreakpointOptionGroup : public OptionGroup {
     case 'x': {
       uint32_t thread_index = UINT32_MAX;
       if (option_arg.getAsInteger(0, thread_index)) {
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_int_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_int_parsing_error_message));
       } else {
         m_bp_opts.GetThreadSpec()->SetIndex(thread_index);
       }
@@ -286,9 +291,9 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
 
       case 'u':
         if (option_arg.getAsInteger(0, m_column))
-          error =
+          error = Status::FromError(
               CreateOptionParsingError(option_arg, short_option, long_option,
-                                       g_int_parsing_error_message);
+                                       g_int_parsing_error_message));
         break;
 
       case 'E': {
@@ -326,8 +331,8 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
           error_context = "Unsupported language type for exception breakpoint";
         }
         if (!error_context.empty())
-          error = CreateOptionParsingError(option_arg, short_option,
-                                           long_option, error_context);
+          error = Status::FromError(CreateOptionParsingError(
+              option_arg, short_option, long_option, error_context));
       } break;
 
       case 'f':
@@ -343,9 +348,9 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
         bool success;
         m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
         if (!success)
-          error =
+          error = Status::FromError(
               CreateOptionParsingError(option_arg, short_option, long_option,
-                                       g_bool_parsing_error_message);
+                                       g_bool_parsing_error_message));
       } break;
 
       case 'H':
@@ -362,24 +367,24 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
           m_skip_prologue = eLazyBoolNo;
 
         if (!success)
-          error =
+          error = Status::FromError(
               CreateOptionParsingError(option_arg, short_option, long_option,
-                                       g_bool_parsing_error_message);
+                                       g_bool_parsing_error_message));
       } break;
 
       case 'l':
         if (option_arg.getAsInteger(0, m_line_num))
-          error =
+          error = Status::FromError(
               CreateOptionParsingError(option_arg, short_option, long_option,
-                                       g_int_parsing_error_message);
+                                       g_int_parsing_error_message));
         break;
 
       case 'L':
         m_language = Language::GetLanguageTypeFromString(option_arg);
         if (m_language == eLanguageTypeUnknown)
-          error =
+          error = Status::FromError(
               CreateOptionParsingError(option_arg, short_option, long_option,
-                                       g_language_parsing_error_message);
+                                       g_language_parsing_error_message));
         break;
 
       case 'm': {
@@ -392,9 +397,9 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
           m_move_to_nearest_code = eLazyBoolNo;
 
         if (!success)
-          error =
+          error = Status::FromError(
               CreateOptionParsingError(option_arg, short_option, long_option,
-                                       g_bool_parsing_error_message);
+                                       g_bool_parsing_error_message));
         break;
       }
 
@@ -412,8 +417,9 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
         if (BreakpointID::StringIsBreakpointName(option_arg, error))
           m_breakpoint_names.push_back(std::string(option_arg));
         else
-          error = CreateOptionParsingError(
-              option_arg, short_option, long_option, "Invalid breakpoint name");
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       "Invalid breakpoint name"));
         break;
       }
 
@@ -451,9 +457,9 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
         bool success;
         m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
         if (!success)
-          error =
+          error = Status::FromError(
               CreateOptionParsingError(option_arg, short_option, long_option,
-                                       g_bool_parsing_error_message);
+                                       g_bool_parsing_error_message));
       } break;
 
       case 'X':
@@ -465,8 +471,8 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
         OptionValueFileColonLine value;
         Status fcl_err = value.SetValueFromString(option_arg);
         if (!fcl_err.Success()) {
-          error = CreateOptionParsingError(option_arg, short_option,
-                                           long_option, fcl_err.AsCString());
+          error = Status::FromError(CreateOptionParsingError(
+              option_arg, short_option, long_option, fcl_err.AsCString()));
         } else {
           m_filenames.AppendIfUnique(value.GetFileSpec());
           m_line_num = value.GetLineNumber();
@@ -1551,13 +1557,15 @@ class BreakpointNameOptionGroup : public OptionGroup {
       break;
     case 'B':
       if (m_breakpoint.SetValueFromString(option_arg).Fail())
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_int_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_int_parsing_error_message));
       break;
     case 'D':
       if (m_use_dummy.SetValueFromString(option_arg).Fail())
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_bool_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_bool_parsing_error_message));
       break;
     case 'H':
       m_help_string.SetValueFromString(option_arg);
@@ -1610,8 +1618,9 @@ class BreakpointAccessOptionGroup : public OptionGroup {
       if (success) {
         m_permissions.SetAllowList(value);
       } else
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_bool_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_bool_parsing_error_message));
     } break;
     case 'A': {
       bool value, success;
@@ -1619,8 +1628,9 @@ class BreakpointAccessOptionGroup : public OptionGroup {
       if (success) {
         m_permissions.SetAllowDisable(value);
       } else
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_bool_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_bool_parsing_error_message));
     } break;
     case 'D': {
       bool value, success;
@@ -1628,8 +1638,9 @@ class BreakpointAccessOptionGroup : public OptionGroup {
       if (success) {
         m_permissions.SetAllowDelete(value);
       } else
-        error = CreateOptionParsingError(option_arg, short_option, long_option,
-                                         g_bool_parsing_error_message);
+        error = Status::FromError(
+            CreateOptionParsingError(option_arg, short_option, long_option,
+                                     g_bool_parsing_error_message));
     } break;
     default:
       llvm_unreachable("Unimplemented option");
@@ -2113,8 +2124,8 @@ class CommandObjectBreakpointRead : public CommandObjectParsed {
         Status name_error;
         if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg),
                                                   name_error)) {
-          error = CreateOptionParsingError(option_arg, short_option,
-                                           long_option, name_error.AsCString());
+          error = Status::FromError(CreateOptionParsingError(
+              option_arg, short_option, long_option, name_error.AsCString()));
         }
         m_names.push_back(std::string(option_arg));
         break;
diff --git a/lldb/source/Commands/CommandObjectMemoryTag.cpp b/lldb/source/Commands/CommandObjectMemoryTag.cpp
index f45d6eacab3d0e..bc76319018da96 100644
--- a/lldb/source/Commands/CommandObjectMemoryTag.cpp
+++ b/lldb/source/Commands/CommandObjectMemoryTag.cpp
@@ -77,7 +77,7 @@ class CommandObjectMemoryTagRead : public CommandObjectParsed {
         process->GetMemoryTagManager();
 
     if (!tag_manager_or_err) {
-      result.SetError(Status(tag_manager_or_err.takeError()));
+      result.SetError(Status::FromError(tag_manager_or_err.takeError()));
       return;
     }
 
@@ -102,7 +102,7 @@ class CommandObjectMemoryTagRead : public CommandObjectParsed {
         tag_manager->MakeTaggedRange(start_addr, end_addr, memory_regions);
 
     if (!tagged_range) {
-      result.SetError(Status(tagged_range.takeError()));
+      result.SetError(Status::FromError(tagged_range.takeError()));
       return;
     }
 
@@ -110,7 +110,7 @@ class CommandObjectMemoryTagRead : public CommandObjectParsed {
         tagged_range->GetRangeBase(), tagged_range->GetByteSize());
 
     if (!tags) {
-      result.SetError(Status(tags.takeError()));
+      result.SetError(Status::FromError(tags.takeError()));
       return;
     }
 
@@ -230,7 +230,7 @@ class CommandObjectMemoryTagWrite : public CommandObjectParsed {
         process->GetMemoryTagManager();
 
     if (!tag_manager_or_err) {
-      result.SetError(Status(tag_manager_or_err.takeError()));
+      result.SetError(Status::FromError(tag_manager_or_err.takeError()));
       return;
     }
 
@@ -282,7 +282,7 @@ class CommandObjectMemoryTagWrite : public CommandObjectParsed {
                                      memory_regions);
 
     if (!tagged_range) {
-      result.SetError(Status(tagged_range.takeError()));
+      result.SetError(Status::FromError(tagged_range.takeError()));
       return;
     }
 
diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp
index 53855e7d03165c..7d333afc231ba1 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -87,21 +87,21 @@ class CommandObjectStatsDump : public CommandObjectParsed {
                 OptionArgParser::ToBoolean("--targets", option_arg))
           m_stats_options.SetIncludeTargets(*bool_or_error);
         else
-          error = bool_or_error.takeError();
+          error = Status::FromError(bool_or_error.takeError());
         break;
       case 'm':
         if (llvm::Expected<bool> bool_or_error =
                 OptionArgParser::ToBoolean("--modules", option_arg))
           m_stats_options.SetIncludeModules(*bool_or_error);
         else
-          error = bool_or_error.takeError();
+          error = Status::FromError(bool_or_error.takeError());
         break;
       case 't':
         if (llvm::Expected<bool> bool_or_error =
                 OptionArgParser::ToBoolean("--transcript", option_arg))
           m_stats_options.SetIncludeTranscript(*bool_or_error);
         else
-          error = bool_or_error.takeError();
+          error = Status::FromError(bool_or_error.takeError());
         break;
       default:
         llvm_unreachable("Unimplemented option");
diff --git a/lldb/source/Commands/CommandObjectTrace.cpp b/lldb/source/Commands/CommandObjectTrace.cpp
index 5bcbc236301cc1..5e212e05461a61 100644
--- a/lldb/source/Commands/CommandObjectTrace.cpp
+++ b/lldb/source/Commands/CommandObjectTrace.cpp
@@ -361,7 +361,7 @@ class CommandObjectTraceSchema : public CommandObjectParsed {
               Trace::FindPluginSchema(plugin_name))
         result.AppendMessage(*schemaOrErr);
       else
-        error = schemaOrErr.takeError();
+        error = Status::FromError(schemaOrErr.takeError());
     }
 
     if (error.Success()) {
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index fd5cb792c101a4..a5219025495a91 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -723,7 +723,7 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
     llvm::Expected<bool> ret =
         process_sp->SaveCore(options.GetOutputFile()->GetPath());
     if (!ret)
-      return Status(ret.takeError());
+      return Status::FromError(ret.takeError());
     if (ret.get())
       return Status();
   }
diff --git a/lldb/source/Core/ThreadedCommunication.cpp b/lldb/source/Core/ThreadedCommunication.cpp
index d8b567c9bd0de6..649ce71c293740 100644
--- a/lldb/source/Core/ThreadedCommunication.cpp
+++ b/lldb/source/Core/ThreadedCommunication.cpp
@@ -178,7 +178,7 @@ bool ThreadedCommunication::StartReadThread(Status *error_ptr) {
     m_read_thread = *maybe_thread;
   } else {
     if (error_ptr)
-      *error_ptr = Status(maybe_thread.takeError());
+      *error_ptr = Status::FromError(maybe_thread.takeError());
     else {
       LLDB_LOG_ERROR(GetLog(LLDBLog::Host), maybe_thread.takeError(),
                      "failed to launch host thread: {0}");
diff --git a/lldb/source/Core/ValueObjectVTable.cpp b/lldb/source/Core/ValueObjectVTable.cpp
index 66e0750b63f8f9..e38f0a83df9940 100644
--- a/lldb/source/Core/ValueObjectVTable.cpp
+++ b/lldb/source/Core/ValueObjectVTable.cpp
@@ -220,7 +220,7 @@ bool ValueObjectVTable::UpdateValue() {
   llvm::Expected<LanguageRuntime::VTableInfo> vtable_info_or_err =
       language_runtime->GetVTableInfo(*parent, /*check_type=*/true);
   if (!vtable_info_or_err) {
-    m_error = vtable_info_or_err.takeError();
+    m_error = Status::FromError(vtable_info_or_err.takeError());
     return false;
   }
 
diff --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp
index 01f871a6f8bc49..29aefb270c92c8 100644
--- a/lldb/source/Core/ValueObjectVariable.cpp
+++ b/lldb/source/Core/ValueObjectVariable.cpp
@@ -249,7 +249,7 @@ bool ValueObjectVariable::UpdateValue() {
 
       SetValueIsValid(m_error.Success());
     } else {
-      m_error = maybe_value.takeError();
+      m_error = Status::FromError(maybe_value.takeError());
       // could not find location, won't allow editing
       m_resolved_value.SetContext(Value::ContextType::Invalid, nullptr);
     }
diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp
index 19de204c24353a..f6c38f76fea31f 100644
--- a/lldb/source/DataFormatters/VectorType.cpp
+++ b/lldb/source/DataFormatters/VectorType.cpp
@@ -233,7 +233,7 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
     auto num_children_or_err = CalculateNumChildren();
     if (!num_children_or_err)
       return ValueObjectConstResult::Create(
-          nullptr, Status(num_children_or_err.takeError()));
+          nullptr, Status::FromError(num_children_or_err.takeError()));
     if (idx >= *num_children_or_err)
       return {};
     std::optional<uint64_t> size = m_child_type.GetByteSize(nullptr);
diff --git a/lldb/source/Host/common/FileCache.cpp b/lldb/source/Host/common/FileCache.cpp
index 4ac198171f96c5..87c90a03fd98d6 100644
--- a/lldb/source/Host/common/FileCache.cpp
+++ b/lldb/source/Host/common/FileCache.cpp
@@ -32,7 +32,7 @@ lldb::user_id_t FileCache::OpenFile(const FileSpec &file_spec,
   }
   auto file = FileSystem::Instance().Open(file_spec, flags, mode);
   if (!file) {
-    error = file.takeError();
+    error = Status::FromError(file.takeError());
     return UINT64_MAX;
   }
   lldb::user_id_t fd = file.get()->GetDescriptor();
diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp
index d3b9dde368db09..a84d8db1c8794a 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.cpp
+++ b/lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -350,7 +350,7 @@ Status NativeProcessProtocol::SetSoftwareBreakpoint(lldb::addr_t addr,
   }
   auto expected_bkpt = EnableSoftwareBreakpoint(addr, size_hint);
   if (!expected_bkpt)
-    return Status(expected_bkpt.takeError());
+    return Status::FromError(expected_bkpt.takeError());
 
   m_software_breakpoints.emplace(addr, std::move(*expected_bkpt));
   return Status();
diff --git a/lldb/source/Host/common/TCPSocket.cpp b/lldb/source/Host/common/TCPSocket.cpp
index fc005814308d90..1f31190b02f974 100644
--- a/lldb/source/Host/common/TCPSocket.cpp
+++ b/lldb/source/Host/common/TCPSocket.cpp
@@ -156,7 +156,7 @@ Status TCPSocket::Connect(llvm::StringRef name) {
   Status error;
   llvm::Expected<HostAndPort> host_port = DecodeHostAndPort(name);
   if (!host_port)
-    return Status(host_port.takeError());
+    return Status::FromError(host_port.takeError());
 
   std::vector<SocketAddress> addresses =
       SocketAddress::GetAddressInfo(host_port->hostname.c_str(), nullptr,
@@ -195,7 +195,7 @@ Status TCPSocket::Listen(llvm::StringRef name, int backlog) {
   Status error;
   llvm::Expected<HostAndPort> host_port = DecodeHostAndPort(name);
   if (!host_port)
-    return Status(host_port.takeError());
+    return Status::FromError(host_port.takeError());
 
   if (host_port->hostname == "*")
     host_port->hostname = "0.0.0.0";
@@ -310,7 +310,7 @@ Status TCPSocket::Accept(Socket *&conn_socket) {
                accept_loop.RequestTermination();
              });
   if (!expected_handles)
-    return Status(expected_handles.takeError());
+    return Status::FromError(expected_handles.takeError());
   return accept_loop.Run();
 }
 
diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm
index 94a2b916574c64..fe63cc16c64990 100644
--- a/lldb/source/Host/macosx/objcxx/Host.mm
+++ b/lldb/source/Host/macosx/objcxx/Host.mm
@@ -316,7 +316,7 @@ repeat with the_window in (get windows)\n\
       unix_socket_name, [&] { return AcceptPIDFromInferior(connect_url); });
 
   if (!accept_thread)
-    return Status(accept_thread.takeError());
+    return Status::FromError(accept_thread.takeError());
 
   [applescript executeAndReturnError:nil];
 
diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
index 6a40f66be39b18..2a2fcf00c0adfe 100644
--- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -652,7 +652,7 @@ ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s,
       Socket::UdpConnect(s, m_child_processes_inherit);
   if (!socket) {
     if (error_ptr)
-      *error_ptr = socket.takeError();
+      *error_ptr = Status::FromError(socket.takeError());
     else
       LLDB_LOG_ERROR(GetLog(LLDBLog::Connection), socket.takeError(),
                      "tcp connect failed: {0}");
@@ -769,7 +769,7 @@ ConnectionStatus ConnectionFileDescriptor::ConnectSerialPort(
       SerialPort::OptionsFromURL(qs);
   if (!serial_options) {
     if (error_ptr)
-      *error_ptr = serial_options.takeError();
+      *error_ptr = Status::FromError(serial_options.takeError());
     else
       llvm::consumeError(serial_options.takeError());
     return eConnectionStatusError;
@@ -786,7 +786,7 @@ ConnectionStatus ConnectionFileDescriptor::ConnectSerialPort(
       fd, File::eOpenOptionReadWrite, serial_options.get(), true);
   if (!serial_sp) {
     if (error_ptr)
-      *error_ptr = serial_sp.takeError();
+      *error_ptr = Status::FromError(serial_sp.takeError());
     else
       llvm::consumeError(serial_sp.takeError());
     return eConnectionStatusError;
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index c819024ccf0183..cf2682cd26faa0 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -121,7 +121,7 @@ bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) {
       args = std::move(*args_or);
       error = options->NotifyOptionParsingFinished(&exe_ctx);
     } else
-      error = args_or.takeError();
+      error = Status::FromError(args_or.takeError());
 
     if (error.Success()) {
       if (options->VerifyOptions(result))
diff --git a/lldb/source/Interpreter/OptionValueRegex.cpp b/lldb/source/Interpreter/OptionValueRegex.cpp
index d810df503f589f..91ec41df6ee507 100644
--- a/lldb/source/Interpreter/OptionValueRegex.cpp
+++ b/lldb/source/Interpreter/OptionValueRegex.cpp
@@ -51,7 +51,7 @@ Status OptionValueRegex::SetValueFromString(llvm::StringRef value,
       m_value_was_set = true;
       NotifyValueChanged();
     } else if (llvm::Error err = m_regex.GetError()) {
-      return Status(std::move(err));
+      return Status::FromError(std::move(err));
     } else {
       return Status::FromErrorString("regex error");
     }
diff --git a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
index 2c9b3c425397a0..f3c137d99703bf 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -114,7 +114,7 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
     if (!child_type_or_err)
       return ValueObjectConstResult::Create(
           exe_ctx.GetBestExecutionContextScope(),
-          Status(child_type_or_err.takeError()));
+          Status::FromError(child_type_or_err.takeError()));
     CompilerType child_type = *child_type_or_err;
 
     ValueObjectSP struct_pointer_sp =
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 2004622e547be9..b28beab117cca4 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6822,7 +6822,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
             outfile, File::eOpenOptionWriteOnly | File::eOpenOptionTruncate |
                          File::eOpenOptionCanCreate);
         if (!core_file) {
-          error = core_file.takeError();
+          error = Status::FromError(core_file.takeError());
         } else {
           // Read 1 page at a time
           uint8_t bytes[0x1000];
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
index 0897895e6bc25d..5da69dd4f2ce79 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
@@ -70,7 +70,7 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP &process_sp,
       options.GetOutputFile().value(),
       File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate);
   if (!maybe_core_file) {
-    error = maybe_core_file.takeError();
+    error = Status::FromError(maybe_core_file.takeError());
     return false;
   }
   MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp,
diff --git a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
index 2825db6e3a6b55..303a5409c6fe4b 100644
--- a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
+++ b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
@@ -408,7 +408,7 @@ static Status HandleFileAction(ProcessLaunchInfo &launch_info,
                 launch_info.GetPTY().GetSecondaryFileDescriptor();
             if (secondary_fd == PseudoTerminal::invalid_fd) {
               if (llvm::Error Err = launch_info.GetPTY().OpenSecondary(O_RDWR))
-                return Status(std::move(Err));
+                return Status::FromError(std::move(Err));
             }
             secondary_fd = launch_info.GetPTY().GetSecondaryFileDescriptor();
             assert(secondary_fd != PseudoTerminal::invalid_fd);
diff --git a/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_arm64.cpp b/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_arm64.cpp
index 4bec3de586685e..f1d0756b3ed9c5 100644
--- a/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_arm64.cpp
@@ -172,7 +172,7 @@ Status NativeRegisterContextDBReg_arm64::ClearAllHardwareBreakpoints() {
   // Read hardware breakpoint and watchpoint information.
   llvm::Error error = ReadHardwareDebugInfo();
   if (error)
-    return Status(std::move(error));
+    return Status::FromError(std::move(error));
 
   for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
     if (BreakpointIsEnabled(i)) {
@@ -191,7 +191,7 @@ Status NativeRegisterContextDBReg_arm64::ClearAllHardwareBreakpoints() {
         m_hbp_regs[i].control = tempControl;
         m_hbp_regs[i].address = tempAddr;
 
-        return Status(std::move(error));
+        return Status::FromError(std::move(error));
       }
     }
   }
@@ -356,7 +356,7 @@ Status NativeRegisterContextDBReg_arm64::ClearAllHardwareWatchpoints() {
   // Read hardware breakpoint and watchpoint information.
   llvm::Error error = ReadHardwareDebugInfo();
   if (error)
-    return Status(std::move(error));
+    return Status::FromError(std::move(error));
 
   for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
     if (WatchpointIsEnabled(i)) {
@@ -375,7 +375,7 @@ Status NativeRegisterContextDBReg_arm64::ClearAllHardwareWatchpoints() {
         m_hwp_regs[i].control = tempControl;
         m_hwp_regs[i].address = tempAddr;
 
-        return Status(std::move(error));
+        return Status::FromError(std::move(error));
       }
     }
   }
@@ -420,7 +420,7 @@ Status NativeRegisterContextDBReg_arm64::GetWatchpointHitIndex(
   // Read hardware breakpoint and watchpoint information.
   llvm::Error error = ReadHardwareDebugInfo();
   if (error)
-    return Status(std::move(error));
+    return Status::FromError(std::move(error));
 
   // Mask off ignored bits from watchpoint trap address.
   trap_addr = FixWatchpointHitAddress(trap_addr);
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 0e8407fc46edf6..7955594bf5d94c 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -194,7 +194,7 @@ Status ProcessElfCore::DoLoadCore() {
     // Parse thread contexts and auxv structure
     if (H.p_type == llvm::ELF::PT_NOTE) {
       if (llvm::Error error = ParseThreadContextsFromNoteSegment(H, data))
-        return Status(std::move(error));
+        return Status::FromError(std::move(error));
     }
     // PT_LOAD segments contains address map
     if (H.p_type == llvm::ELF::PT_LOAD) {
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 50fa11e916c5f5..1f1e5113468798 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -847,7 +847,7 @@ Status GDBRemoteCommunication::StartListenThread(const char *hostname,
   llvm::Expected<HostThread> listen_thread = ThreadLauncher::LaunchThread(
       listen_url, [this] { return GDBRemoteCommunication::ListenThread(); });
   if (!listen_thread)
-    return Status(listen_thread.takeError());
+    return Status::FromError(listen_thread.takeError());
   m_listen_thread = *listen_thread;
 
   return Status();
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 0297fe363f69e1..5c8e0cc5feda13 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1743,7 +1743,7 @@ Status GDBRemoteCommunicationClient::LoadQXferMemoryMap() {
 
   llvm::Expected<std::string> xml = ReadExtFeature("memory-map", "");
   if (!xml)
-    return Status(xml.takeError());
+    return Status::FromError(xml.takeError());
 
   XMLDocument xml_document;
 
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 9d08a5d3411f14..9b72cb00352821 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -123,7 +123,7 @@ GDBRemoteCommunicationServer::SendErrorResponse(llvm::Error error) {
       [&](std::unique_ptr<llvm::ErrorInfoBase> E) { EIB = std::move(E); });
 
   if (EIB)
-    return SendErrorResponse(Status(llvm::Error(std::move(EIB))));
+    return SendErrorResponse(Status::FromError(llvm::Error(std::move(EIB))));
   return SendUnimplementedResponse("");
 }
 
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 504c994f980cff..35fa93e53bc66f 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -277,7 +277,7 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
     // lldb-server on Windows.
 #if !defined(_WIN32)
     if (llvm::Error Err = m_process_launch_info.SetUpPtyRedirection())
-      return Status(std::move(Err));
+      return Status::FromError(std::move(Err));
 #endif
   }
 
@@ -287,7 +287,7 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
                                            "process but one already exists");
     auto process_or = m_process_manager.Launch(m_process_launch_info, *this);
     if (!process_or)
-      return Status(process_or.takeError());
+      return Status::FromError(process_or.takeError());
     m_continue_process = m_current_process = process_or->get();
     m_debugged_processes.emplace(
         m_current_process->GetID(),
@@ -356,7 +356,7 @@ Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
   // Try to attach.
   auto process_or = m_process_manager.Attach(pid, *this);
   if (!process_or) {
-    Status status(process_or.takeError());
+    Status status = Status::FromError(process_or.takeError());
     llvm::errs() << llvm::formatv("failed to attach to process {0}: {1}\n", pid,
                                   status);
     return status;
@@ -1367,7 +1367,7 @@ GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceGetBinaryData(
       llvm::json::parse<TraceGetBinaryDataRequest>(packet.Peek(),
                                                    "TraceGetBinaryDataRequest");
   if (!request)
-    return SendErrorResponse(Status(request.takeError()));
+    return SendErrorResponse(Status::FromError(request.takeError()));
 
   if (Expected<std::vector<uint8_t>> bytes =
           m_current_process->TraceGetBinaryData(*request)) {
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 30e782e3be1846..2f2750ec2b9209 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -167,7 +167,7 @@ Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
     if (available_port)
       port = *available_port;
     else
-      return Status(available_port.takeError());
+      return Status::FromError(available_port.takeError());
   }
 
   // Spawn a new thread to accept the port that gets bound after binding to
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 7a326a557547df..ac1ecbfc0e2e70 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -186,7 +186,7 @@ void ProcessMinidump::Terminate() {
 Status ProcessMinidump::DoLoadCore() {
   auto expected_parser = MinidumpParser::Create(m_core_data);
   if (!expected_parser)
-    return Status(expected_parser.takeError());
+    return Status::FromError(expected_parser.takeError());
   m_minidump_parser = std::move(*expected_parser);
 
   Status error;
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index cbb6cd41aa867e..c1dcdc7df6cee3 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -269,7 +269,7 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
         transformed_args);
 
     if (llvm::Error e = expected_return_object.takeError()) {
-      error = Status(std::move(e));
+      error = Status::FromError(std::move(e));
       return ErrorWithMessage<T>(caller_signature,
                                  "Python method could not be called.", error);
     }
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index ce14b531ea29c3..24cf3430006329 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -1105,7 +1105,7 @@ template <typename Base> class OwnedPythonFile : public Base {
     if (!m_borrowed) {
       auto r = m_py_obj.CallMethod("close");
       if (!r)
-        py_error = Status(r.takeError());
+        py_error = Status::FromError(r.takeError());
     }
     base_error = Base::Close();
     if (py_error.Fail())
@@ -1196,7 +1196,7 @@ class PythonIOFile : public OwnedPythonFile<File> {
       return Flush();
     auto r = m_py_obj.CallMethod("close");
     if (!r)
-      return Status(r.takeError());
+      return Status::FromError(r.takeError());
     return Status();
   }
 
@@ -1204,7 +1204,7 @@ class PythonIOFile : public OwnedPythonFile<File> {
     GIL takeGIL;
     auto r = m_py_obj.CallMethod("flush");
     if (!r)
-      return Status(r.takeError());
+      return Status::FromError(r.takeError());
     return Status();
   }
 
@@ -1240,12 +1240,12 @@ class BinaryPythonFile : public PythonIOFile {
     PyObject *pybuffer_p = PyMemoryView_FromMemory(
         const_cast<char *>((const char *)buf), num_bytes, PyBUF_READ);
     if (!pybuffer_p)
-      return Status(llvm::make_error<PythonException>());
+      return Status::FromError(llvm::make_error<PythonException>());
     auto pybuffer = Take<PythonObject>(pybuffer_p);
     num_bytes = 0;
     auto bytes_written = As<long long>(m_py_obj.CallMethod("write", pybuffer));
     if (!bytes_written)
-      return Status(bytes_written.takeError());
+      return Status::FromError(bytes_written.takeError());
     if (bytes_written.get() < 0)
       return Status::FromErrorString(
           ".write() method returned a negative number!");
@@ -1260,7 +1260,7 @@ class BinaryPythonFile : public PythonIOFile {
     auto pybuffer_obj =
         m_py_obj.CallMethod("read", (unsigned long long)num_bytes);
     if (!pybuffer_obj)
-      return Status(pybuffer_obj.takeError());
+      return Status::FromError(pybuffer_obj.takeError());
     num_bytes = 0;
     if (pybuffer_obj.get().IsNone()) {
       // EOF
@@ -1269,7 +1269,7 @@ class BinaryPythonFile : public PythonIOFile {
     }
     auto pybuffer = PythonBuffer::Create(pybuffer_obj.get());
     if (!pybuffer)
-      return Status(pybuffer.takeError());
+      return Status::FromError(pybuffer.takeError());
     memcpy(buf, pybuffer.get().get().buf, pybuffer.get().get().len);
     num_bytes = pybuffer.get().get().len;
     return Status();
@@ -1295,12 +1295,12 @@ class TextPythonFile : public PythonIOFile {
     auto pystring =
         PythonString::FromUTF8(llvm::StringRef((const char *)buf, num_bytes));
     if (!pystring)
-      return Status(pystring.takeError());
+      return Status::FromError(pystring.takeError());
     num_bytes = 0;
     auto bytes_written =
         As<long long>(m_py_obj.CallMethod("write", pystring.get()));
     if (!bytes_written)
-      return Status(bytes_written.takeError());
+      return Status::FromError(bytes_written.takeError());
     if (bytes_written.get() < 0)
       return Status::FromErrorString(
           ".write() method returned a negative number!");
@@ -1321,14 +1321,14 @@ class TextPythonFile : public PythonIOFile {
     auto pystring = As<PythonString>(
         m_py_obj.CallMethod("read", (unsigned long long)num_chars));
     if (!pystring)
-      return Status(pystring.takeError());
+      return Status::FromError(pystring.takeError());
     if (pystring.get().IsNone()) {
       // EOF
       return Status();
     }
     auto stringref = pystring.get().AsUTF8();
     if (!stringref)
-      return Status(stringref.takeError());
+      return Status::FromError(stringref.takeError());
     num_bytes = stringref.get().size();
     memcpy(buf, stringref.get().begin(), num_bytes);
     return Status();
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 76f2640a3ea692..63691d24f0dadb 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -1110,7 +1110,7 @@ Status ScriptInterpreterPythonImpl::ExecuteMultipleLines(
           options.GetEnableIO(), m_debugger, /*result=*/nullptr);
 
   if (!io_redirect_or_error)
-    return Status(io_redirect_or_error.takeError());
+    return Status::FromError(io_redirect_or_error.takeError());
 
   ScriptInterpreterIORedirect &io_redirect = **io_redirect_or_error;
 
@@ -1144,7 +1144,7 @@ Status ScriptInterpreterPythonImpl::ExecuteMultipleLines(
             E.Restore();
           return error;
         });
-    return Status(std::move(error));
+    return Status::FromError(std::move(error));
   }
 
   return Status();
@@ -2393,7 +2393,7 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
           exc_options.GetEnableIO(), m_debugger, /*result=*/nullptr);
 
   if (!io_redirect_or_error) {
-    error = io_redirect_or_error.takeError();
+    error = Status::FromError(io_redirect_or_error.takeError());
     return false;
   }
 
@@ -2435,7 +2435,7 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
 
   if (extra_search_dir) {
     if (llvm::Error e = ExtendSysPath(extra_search_dir.GetPath())) {
-      error = std::move(e);
+      error = Status::FromError(std::move(e));
       return false;
     }
   } else {
@@ -2465,7 +2465,7 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
       }
       if (llvm::Error e =
               ExtendSysPath(module_file.GetDirectory().GetCString())) {
-        error = std::move(e);
+        error = Status::FromError(std::move(e));
         return false;
       }
       module_name = module_file.GetFilename().GetCString();
diff --git a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
index 1137f24451d28b..4ca8bd2f9085df 100644
--- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
+++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
@@ -289,7 +289,7 @@ class RegexFilterRule : public FilterRule {
     // Instantiate the regex so we can report any errors.
     auto regex = RegularExpression(op_arg);
     if (llvm::Error err = regex.GetError()) {
-      error = Status(std::move(err));
+      error = Status::FromError(std::move(err));
       return FilterRuleSP();
     }
 
diff --git a/lldb/source/Target/ModuleCache.cpp b/lldb/source/Target/ModuleCache.cpp
index ce009f9b2fafe4..ccae7ea106c974 100644
--- a/lldb/source/Target/ModuleCache.cpp
+++ b/lldb/source/Target/ModuleCache.cpp
@@ -166,7 +166,7 @@ ModuleLock::ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid,
     m_file_up = std::move(file.get());
   else {
     m_file_up.reset();
-    error = Status(file.takeError());
+    error = Status::FromError(file.takeError());
     return;
   }
 
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index b65a27dedc0814..7792edcc2cb582 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1131,7 +1131,7 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
   auto source_file = FileSystem::Instance().Open(source, source_open_options,
                                                  lldb::eFilePermissionsUserRW);
   if (!source_file)
-    return Status(source_file.takeError());
+    return Status::FromError(source_file.takeError());
   Status error;
 
   bool requires_upload = true;
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index ae64f6f261bad7..b911e9da8cac84 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6484,13 +6484,13 @@ Status Process::WriteMemoryTags(lldb::addr_t addr, size_t len,
   llvm::Expected<const MemoryTagManager *> tag_manager_or_err =
       GetMemoryTagManager();
   if (!tag_manager_or_err)
-    return Status(tag_manager_or_err.takeError());
+    return Status::FromError(tag_manager_or_err.takeError());
 
   const MemoryTagManager *tag_manager = *tag_manager_or_err;
   llvm::Expected<std::vector<uint8_t>> packed_tags =
       tag_manager->PackTags(tags);
   if (!packed_tags) {
-    return Status(packed_tags.takeError());
+    return Status::FromError(packed_tags.takeError());
   }
 
   return DoWriteMemoryTags(addr, len, tag_manager->GetAllocationTagType(),
diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp
index e35a4c318d358f..1610971a34148b 100644
--- a/lldb/source/Target/StackFrame.cpp
+++ b/lldb/source/Target/StackFrame.cpp
@@ -1104,7 +1104,7 @@ bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Status *error_ptr) {
           m_sc.function->GetFrameBaseExpression().Evaluate(
               &exe_ctx, nullptr, loclist_base_addr, nullptr, nullptr);
       if (!expr_value)
-        m_frame_base_error = expr_value.takeError();
+        m_frame_base_error = Status::FromError(expr_value.takeError());
       else
         m_frame_base = expr_value->ResolveValue(&exe_ctx);
     } else {
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index 899e822851d81d..902fbb2b519ef7 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -2078,7 +2078,8 @@ lldb::ValueObjectSP Thread::GetSiginfoValue() {
   llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> data =
       GetSiginfo(*type_size);
   if (!data)
-    return ValueObjectConstResult::Create(&target, Status(data.takeError()));
+    return ValueObjectConstResult::Create(&target,
+                                          Status::FromError(data.takeError()));
 
   DataExtractor data_extractor{data.get()->getBufferStart(), data.get()->getBufferSize(),
     process_sp->GetByteOrder(), arch.GetAddressByteSize()};
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 098128b1a50e50..329f5b6e4b9a5b 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -684,7 +684,7 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding,
       m_type = e_float;
       m_float = std::move(f);
     } else
-      error = op.takeError();
+      error = Status::FromError(op.takeError());
     break;
   }
 
diff --git a/lldb/source/Utility/Status.cpp b/lldb/source/Utility/Status.cpp
index 7260b7b3e0a03e..b567069507f149 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -55,10 +55,10 @@ Status::Status(std::string err_str)
     : m_code(LLDB_GENERIC_ERROR), m_type(eErrorTypeGeneric),
       m_string(std::move(err_str)) {}
 
-const Status &Status::operator=(llvm::Error error) {
+Status::Status(llvm::Error &&error) {
   if (!error) {
     Clear();
-    return *this;
+    return;
   }
 
   // if the error happens to be a errno error, preserve the error code
@@ -79,8 +79,6 @@ const Status &Status::operator=(llvm::Error error) {
     m_type = eErrorTypeGeneric;
     m_string = llvm::toString(std::move(error));
   }
-
-  return *this;
 }
 
 Status Status::FromErrorStringWithFormat(const char *format, ...) {
@@ -96,6 +94,10 @@ Status Status::FromErrorStringWithFormat(const char *format, ...) {
   return Status(string);
 }
 
+Status Status::FromError(llvm::Error &&error) {
+  return Status(std::move(error));
+}
+
 llvm::Error Status::ToError() const {
   if (Success())
     return llvm::Error::success();
diff --git a/lldb/source/Utility/StructuredData.cpp b/lldb/source/Utility/StructuredData.cpp
index 5f9821b979c079..fb4f6920d62eb8 100644
--- a/lldb/source/Utility/StructuredData.cpp
+++ b/lldb/source/Utility/StructuredData.cpp
@@ -46,7 +46,7 @@ StructuredData::ParseJSONFromFile(const FileSpec &input_spec, Status &error) {
       json::parse(buffer_or_error.get()->getBuffer().str());
   if (value)
     return ParseJSONValue(*value);
-  error = Status(value.takeError());
+  error = Status::FromError(value.takeError());
   return StructuredData::ObjectSP();
 }
 
diff --git a/lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h b/lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h
index a610b37a6b38e3..1a017122411a83 100644
--- a/lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h
+++ b/lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h
@@ -75,7 +75,7 @@ template <typename T> class MockProcess : public T {
     auto ExpectedMemory = this->ReadMemory(Addr, Size);
     if (!ExpectedMemory) {
       BytesRead = 0;
-      return Status(ExpectedMemory.takeError());
+      return Status::FromError(ExpectedMemory.takeError());
     }
     BytesRead = ExpectedMemory->size();
     assert(BytesRead <= Size);
@@ -89,7 +89,7 @@ template <typename T> class MockProcess : public T {
         Addr, llvm::ArrayRef(static_cast<const uint8_t *>(Buf), Size));
     if (!ExpectedBytes) {
       BytesWritten = 0;
-      return Status(ExpectedBytes.takeError());
+      return Status::FromError(ExpectedBytes.takeError());
     }
     BytesWritten = *ExpectedBytes;
     return Status();
diff --git a/lldb/unittests/Utility/StatusTest.cpp b/lldb/unittests/Utility/StatusTest.cpp
index d33909ea897275..be4f2beebcdb52 100644
--- a/lldb/unittests/Utility/StatusTest.cpp
+++ b/lldb/unittests/Utility/StatusTest.cpp
@@ -27,21 +27,20 @@ TEST(StatusTest, Formatv) {
 }
 
 TEST(StatusTest, ErrorConstructor) {
-  EXPECT_TRUE(Status(llvm::Error::success()).Success());
+  EXPECT_TRUE(Status::FromError(llvm::Error::success()).Success());
 
-  Status eagain(
+  Status eagain = Status::FromError(
       llvm::errorCodeToError(std::error_code(EAGAIN, std::generic_category())));
   EXPECT_TRUE(eagain.Fail());
   EXPECT_EQ(eErrorTypePOSIX, eagain.GetType());
   EXPECT_EQ(Status::ValueType(EAGAIN), eagain.GetError());
 
-  Status foo(llvm::make_error<llvm::StringError>(
-      "foo", llvm::inconvertibleErrorCode()));
+  Status foo = Status::FromError(llvm::createStringError("foo"));
   EXPECT_TRUE(foo.Fail());
   EXPECT_EQ(eErrorTypeGeneric, foo.GetType());
   EXPECT_STREQ("foo", foo.AsCString());
 
-  foo = llvm::Error::success();
+  foo = Status::FromError(llvm::Error::success());
   EXPECT_TRUE(foo.Success());
 }
 
@@ -52,6 +51,11 @@ TEST(StatusTest, ErrorCodeConstructor) {
   EXPECT_TRUE(eagain.Fail());
   EXPECT_EQ(eErrorTypePOSIX, eagain.GetType());
   EXPECT_EQ(Status::ValueType(EAGAIN), eagain.GetError());
+
+  llvm::Error list = llvm::joinErrors(llvm::createStringError("foo"),
+                                      llvm::createStringError("bar"));
+  Status foobar = Status::FromError(std::move(list));
+  EXPECT_EQ(std::string("foo\nbar"), std::string(foobar.AsCString()));
 }
 
 TEST(StatusTest, ErrorConversion) {



More information about the lldb-commits mailing list