[Lldb-commits] [lldb] [lldb] Make deep copies of Status explicit (NFC) (PR #107170)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 4 12:40:19 PDT 2024
https://github.com/adrian-prantl updated https://github.com/llvm/llvm-project/pull/107170
>From 3a133869fd7defac30329ef4c81bbbbeb082883e 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 1/2] [lldb] Make conversions from llvm::Error explicit with
Status::FromError() [NFC]
---
lldb/include/lldb/Utility/Status.h | 7 +-
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, 151 insertions(+), 132 deletions(-)
diff --git a/lldb/include/lldb/Utility/Status.h b/lldb/include/lldb/Utility/Status.h
index b304291ffae00e..3813a3c1604700 100644
--- a/lldb/include/lldb/Utility/Status.h
+++ b/lldb/include/lldb/Utility/Status.h
@@ -91,9 +91,9 @@ 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);
+ /// FIXME: Replace this with a takeError method.
llvm::Error ToError() const;
/// Get the error string associated with the current error.
@@ -145,6 +145,7 @@ class Status {
bool Success() const;
protected:
+ Status(llvm::Error 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..cdc2013fb4a212 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) {
>From 47e2879bf9f49ece471d9e0d47d16c175d012703 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 2/2] [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 b911e9da8cac84..2c4edd92def47c 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -2174,7 +2174,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;
@@ -2185,10 +2184,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;
}
@@ -5741,43 +5741,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 cdc2013fb4a212..54b26ad5a5ec36 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -109,6 +109,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 = other.m_string;
+ return *this;
+}
+
#ifdef _WIN32
static std::string RetrieveWin32ErrorString(uint32_t error_code) {
char *buffer = nullptr;
@@ -206,3 +213,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