aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2024-08-27 10:59:31 -0700
committerGitHub <noreply@github.com>2024-08-27 10:59:31 -0700
commit0642cd768b80665585c8500bed2933a3b99123dc (patch)
treea412a5eafff54ef9a7cb884e01907a4f521f5140 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
parentacb33a0c9bc902dc1aef703c02b8fd3a1132cb14 (diff)
downloadllvm-0642cd768b80665585c8500bed2933a3b99123dc.zip
llvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.gz
llvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.bz2
[lldb] Turn lldb_private::Status into a value type. (#106163)
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp120
1 files changed, 64 insertions, 56 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index d7a0baa..0297fe3 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -104,11 +104,12 @@ bool GDBRemoteCommunicationClient::HandshakeWithServer(Status *error_ptr) {
.count();
if (error_ptr) {
if (!IsConnected())
- error_ptr->SetErrorString("Connection shut down by remote side "
- "while waiting for reply to initial "
- "handshake packet");
+ *error_ptr =
+ Status::FromErrorString("Connection shut down by remote side "
+ "while waiting for reply to initial "
+ "handshake packet");
else
- error_ptr->SetErrorStringWithFormat(
+ *error_ptr = Status::FromErrorStringWithFormat(
"failed to get reply to handshake packet within timeout of "
"%.1f seconds",
handshake_timeout);
@@ -116,7 +117,7 @@ bool GDBRemoteCommunicationClient::HandshakeWithServer(Status *error_ptr) {
}
} else {
if (error_ptr)
- error_ptr->SetErrorString("failed to send the handshake ack");
+ *error_ptr = Status::FromErrorString("failed to send the handshake ack");
}
return false;
}
@@ -708,7 +709,7 @@ Status GDBRemoteCommunicationClient::WriteMemoryTags(
if (SendPacketAndWaitForResponse(packet.GetString(), response) !=
PacketResult::Success ||
!response.IsOKResponse()) {
- status.SetErrorString("QMemTags packet failed");
+ status = Status::FromErrorString("QMemTags packet failed");
}
return status;
}
@@ -1522,7 +1523,8 @@ Status GDBRemoteCommunicationClient::Detach(bool keep_stopped,
}
if (m_supports_detach_stay_stopped == eLazyBoolNo) {
- error.SetErrorString("Stays stopped not supported by this target.");
+ error = Status::FromErrorString(
+ "Stays stopped not supported by this target.");
return error;
} else {
packet.PutChar('1');
@@ -1537,7 +1539,8 @@ Status GDBRemoteCommunicationClient::Detach(bool keep_stopped,
packet.PutChar(';');
packet.PutHex64(pid);
} else if (pid != LLDB_INVALID_PROCESS_ID) {
- error.SetErrorString("Multiprocess extension not supported by the server.");
+ error = Status::FromErrorString(
+ "Multiprocess extension not supported by the server.");
return error;
}
@@ -1545,7 +1548,7 @@ Status GDBRemoteCommunicationClient::Detach(bool keep_stopped,
PacketResult packet_result =
SendPacketAndWaitForResponse(packet.GetString(), response);
if (packet_result != PacketResult::Success)
- error.SetErrorString("Sending isconnect packet failed.");
+ error = Status::FromErrorString("Sending isconnect packet failed.");
return error;
}
@@ -1641,7 +1644,7 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
std::string error_string;
// Now convert the HEX bytes into a string value
error_extractor.GetHexByteString(error_string);
- error.SetErrorString(error_string.c_str());
+ error = Status::FromErrorString(error_string.c_str());
} else if (name == "dirty-pages") {
std::vector<addr_t> dirty_page_list;
for (llvm::StringRef x : llvm::split(value, ',')) {
@@ -1668,7 +1671,7 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
}
} else {
// We got an invalid address range back
- error.SetErrorString("Server returned invalid range");
+ error = Status::FromErrorString("Server returned invalid range");
}
} else {
m_supports_memory_region_info = eLazyBoolNo;
@@ -1676,7 +1679,7 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
}
if (m_supports_memory_region_info == eLazyBoolNo) {
- error.SetErrorString("qMemoryRegionInfo is not supported");
+ error = Status::FromErrorString("qMemoryRegionInfo is not supported");
}
// Try qXfer:memory-map:read to get region information not included in
@@ -1716,7 +1719,7 @@ Status GDBRemoteCommunicationClient::GetQXferMemoryMapRegionInfo(
return error;
}
}
- error.SetErrorString("Region not found");
+ error = Status::FromErrorString("Region not found");
return error;
}
@@ -1729,12 +1732,12 @@ Status GDBRemoteCommunicationClient::LoadQXferMemoryMap() {
return error;
if (!XMLDocument::XMLEnabled()) {
- error.SetErrorString("XML is not supported");
+ error = Status::FromErrorString("XML is not supported");
return error;
}
if (!GetQXferMemoryMapReadSupported()) {
- error.SetErrorString("Memory map is not supported");
+ error = Status::FromErrorString("Memory map is not supported");
return error;
}
@@ -1745,13 +1748,13 @@ Status GDBRemoteCommunicationClient::LoadQXferMemoryMap() {
XMLDocument xml_document;
if (!xml_document.ParseMemory(xml->c_str(), xml->size())) {
- error.SetErrorString("Failed to parse memory map xml");
+ error = Status::FromErrorString("Failed to parse memory map xml");
return error;
}
XMLNode map_node = xml_document.GetRootElement("memory-map");
if (!map_node) {
- error.SetErrorString("Invalid root node in memory map xml");
+ error = Status::FromErrorString("Invalid root node in memory map xml");
return error;
}
@@ -2979,28 +2982,28 @@ lldb_private::Status GDBRemoteCommunicationClient::RunShellCommand(
if (SendPacketAndWaitForResponse(stream.GetString(), response) ==
PacketResult::Success) {
if (response.GetChar() != 'F')
- return Status("malformed reply");
+ return Status::FromErrorString("malformed reply");
if (response.GetChar() != ',')
- return Status("malformed reply");
+ return Status::FromErrorString("malformed reply");
uint32_t exitcode = response.GetHexMaxU32(false, UINT32_MAX);
if (exitcode == UINT32_MAX)
- return Status("unable to run remote process");
+ return Status::FromErrorString("unable to run remote process");
else if (status_ptr)
*status_ptr = exitcode;
if (response.GetChar() != ',')
- return Status("malformed reply");
+ return Status::FromErrorString("malformed reply");
uint32_t signo = response.GetHexMaxU32(false, UINT32_MAX);
if (signo_ptr)
*signo_ptr = signo;
if (response.GetChar() != ',')
- return Status("malformed reply");
+ return Status::FromErrorString("malformed reply");
std::string output;
response.GetEscapedBinaryData(output);
if (command_output)
command_output->assign(output);
return Status();
}
- return Status("unable to send packet");
+ return Status::FromErrorString("unable to send packet");
}
Status GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec,
@@ -3015,10 +3018,12 @@ Status GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec,
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse(packet, response) != PacketResult::Success)
- return Status("failed to send '%s' packet", packet.str().c_str());
+ return Status::FromErrorStringWithFormat("failed to send '%s' packet",
+ packet.str().c_str());
if (response.GetChar() != 'F')
- return Status("invalid response to '%s' packet", packet.str().c_str());
+ return Status::FromErrorStringWithFormat("invalid response to '%s' packet",
+ packet.str().c_str());
return Status(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX);
}
@@ -3036,10 +3041,12 @@ GDBRemoteCommunicationClient::SetFilePermissions(const FileSpec &file_spec,
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse(packet, response) != PacketResult::Success)
- return Status("failed to send '%s' packet", stream.GetData());
+ return Status::FromErrorStringWithFormat("failed to send '%s' packet",
+ stream.GetData());
if (response.GetChar() != 'F')
- return Status("invalid response to '%s' packet", stream.GetData());
+ return Status::FromErrorStringWithFormat("invalid response to '%s' packet",
+ stream.GetData());
return Status(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX);
}
@@ -3066,9 +3073,9 @@ static uint64_t ParseHostIOPacketResponse(StringExtractorGDBRemote &response,
if (response.GetChar() == ',') {
int result_errno = gdb_errno_to_system(response.GetS32(-1, 16));
if (result_errno != -1)
- error.SetError(result_errno, eErrorTypePOSIX);
+ error = Status(result_errno, eErrorTypePOSIX);
else
- error.SetError(-1, eErrorTypeGeneric);
+ error = Status(-1, eErrorTypeGeneric);
} else
error.Clear();
return result;
@@ -3206,25 +3213,25 @@ GDBRemoteCommunicationClient::GetFilePermissions(const FileSpec &file_spec,
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse(stream.GetString(), response) !=
PacketResult::Success) {
- error.SetErrorStringWithFormat("failed to send '%s' packet",
- stream.GetData());
+ error = Status::FromErrorStringWithFormat("failed to send '%s' packet",
+ stream.GetData());
return error;
}
if (!response.IsUnsupportedResponse()) {
if (response.GetChar() != 'F') {
- error.SetErrorStringWithFormat("invalid response to '%s' packet",
- stream.GetData());
+ error = Status::FromErrorStringWithFormat(
+ "invalid response to '%s' packet", stream.GetData());
} else {
const uint32_t mode = response.GetS32(-1, 16);
if (static_cast<int32_t>(mode) == -1) {
if (response.GetChar() == ',') {
int response_errno = gdb_errno_to_system(response.GetS32(-1, 16));
if (response_errno > 0)
- error.SetError(response_errno, lldb::eErrorTypePOSIX);
+ error = Status(response_errno, lldb::eErrorTypePOSIX);
else
- error.SetErrorToGenericError();
+ error = Status::FromErrorString("unknown error");
} else
- error.SetErrorToGenericError();
+ error = Status::FromErrorString("unknown error");
} else {
file_permissions = mode & (S_IRWXU | S_IRWXG | S_IRWXO);
}
@@ -3240,7 +3247,7 @@ GDBRemoteCommunicationClient::GetFilePermissions(const FileSpec &file_spec,
file_permissions = st->gdb_st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
return Status();
}
- return Status("fstat failed");
+ return Status::FromErrorString("fstat failed");
}
uint64_t GDBRemoteCommunicationClient::ReadFile(lldb::user_id_t fd,
@@ -3257,11 +3264,11 @@ uint64_t GDBRemoteCommunicationClient::ReadFile(lldb::user_id_t fd,
return 0;
int64_t retcode = response.GetS64(-1, 16);
if (retcode == -1) {
- error.SetErrorToGenericError();
+ error = Status::FromErrorString("unknown error");
if (response.GetChar() == ',') {
int response_errno = gdb_errno_to_system(response.GetS32(-1, 16));
if (response_errno > 0)
- error.SetError(response_errno, lldb::eErrorTypePOSIX);
+ error = Status(response_errno, lldb::eErrorTypePOSIX);
}
return -1;
}
@@ -3295,22 +3302,22 @@ uint64_t GDBRemoteCommunicationClient::WriteFile(lldb::user_id_t fd,
if (SendPacketAndWaitForResponse(stream.GetString(), response) ==
PacketResult::Success) {
if (response.GetChar() != 'F') {
- error.SetErrorStringWithFormat("write file failed");
+ error = Status::FromErrorStringWithFormat("write file failed");
return 0;
}
int64_t bytes_written = response.GetS64(-1, 16);
if (bytes_written == -1) {
- error.SetErrorToGenericError();
+ error = Status::FromErrorString("unknown error");
if (response.GetChar() == ',') {
int response_errno = gdb_errno_to_system(response.GetS32(-1, 16));
if (response_errno > 0)
- error.SetError(response_errno, lldb::eErrorTypePOSIX);
+ error = Status(response_errno, lldb::eErrorTypePOSIX);
}
return -1;
}
return bytes_written;
} else {
- error.SetErrorString("failed to send vFile:pwrite packet");
+ error = Status::FromErrorString("failed to send vFile:pwrite packet");
}
return 0;
}
@@ -3332,19 +3339,19 @@ Status GDBRemoteCommunicationClient::CreateSymlink(const FileSpec &src,
if (response.GetChar() == 'F') {
uint32_t result = response.GetHexMaxU32(false, UINT32_MAX);
if (result != 0) {
- error.SetErrorToGenericError();
+ error = Status::FromErrorString("unknown error");
if (response.GetChar() == ',') {
int response_errno = gdb_errno_to_system(response.GetS32(-1, 16));
if (response_errno > 0)
- error.SetError(response_errno, lldb::eErrorTypePOSIX);
+ error = Status(response_errno, lldb::eErrorTypePOSIX);
}
}
} else {
// Should have returned with 'F<result>[,<errno>]'
- error.SetErrorStringWithFormat("symlink failed");
+ error = Status::FromErrorStringWithFormat("symlink failed");
}
} else {
- error.SetErrorString("failed to send vFile:symlink packet");
+ error = Status::FromErrorString("failed to send vFile:symlink packet");
}
return error;
}
@@ -3363,19 +3370,19 @@ Status GDBRemoteCommunicationClient::Unlink(const FileSpec &file_spec) {
if (response.GetChar() == 'F') {
uint32_t result = response.GetHexMaxU32(false, UINT32_MAX);
if (result != 0) {
- error.SetErrorToGenericError();
+ error = Status::FromErrorString("unknown error");
if (response.GetChar() == ',') {
int response_errno = gdb_errno_to_system(response.GetS32(-1, 16));
if (response_errno > 0)
- error.SetError(response_errno, lldb::eErrorTypePOSIX);
+ error = Status(response_errno, lldb::eErrorTypePOSIX);
}
}
} else {
// Should have returned with 'F<result>[,<errno>]'
- error.SetErrorStringWithFormat("unlink failed");
+ error = Status::FromErrorStringWithFormat("unlink failed");
}
} else {
- error.SetErrorString("failed to send vFile:unlink packet");
+ error = Status::FromErrorString("failed to send vFile:unlink packet");
}
return error;
}
@@ -4255,12 +4262,13 @@ Status GDBRemoteCommunicationClient::SendSignalsToIgnore(
auto send_status = SendPacketAndWaitForResponse(packet, response);
if (send_status != GDBRemoteCommunication::PacketResult::Success)
- return Status("Sending QPassSignals packet failed");
+ return Status::FromErrorString("Sending QPassSignals packet failed");
if (response.IsOKResponse()) {
return Status();
} else {
- return Status("Unknown error happened during sending QPassSignals packet.");
+ return Status::FromErrorString(
+ "Unknown error happened during sending QPassSignals packet.");
}
}
@@ -4269,7 +4277,7 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
Status error;
if (type_name.empty()) {
- error.SetErrorString("invalid type_name argument");
+ error = Status::FromErrorString("invalid type_name argument");
return error;
}
@@ -4299,13 +4307,13 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
// Okay!
error.Clear();
} else {
- error.SetErrorStringWithFormatv(
+ error = Status::FromErrorStringWithFormatv(
"configuring StructuredData feature {0} failed with error {1}",
type_name, response.GetStringRef());
}
} else {
// Can we get more data here on the failure?
- error.SetErrorStringWithFormatv(
+ error = Status::FromErrorStringWithFormatv(
"configuring StructuredData feature {0} failed when sending packet: "
"PacketResult={1}",
type_name, (int)result);