aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
diff options
context:
space:
mode:
authorAnthony Ha <anthonyha96@gmail.com>2024-05-09 15:57:46 -0700
committerGitHub <noreply@github.com>2024-05-09 15:57:46 -0700
commit95f208f97e709139c3ecbce552bcf1e34b9fcf12 (patch)
treef39d0f3cccfb24b119e142f44832c37936d69e87 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
parent1e97d114b5b2b522de7e0aa9c950199de0798d53 (diff)
downloadllvm-95f208f97e709139c3ecbce552bcf1e34b9fcf12.zip
llvm-95f208f97e709139c3ecbce552bcf1e34b9fcf12.tar.gz
llvm-95f208f97e709139c3ecbce552bcf1e34b9fcf12.tar.bz2
[lldb] Unify CalculateMD5 return types (#91029)
This is a retake of https://github.com/llvm/llvm-project/pull/90921 which got reverted because I forgot to modify the CalculateMD5 unit test I had added in https://github.com/llvm/llvm-project/pull/88812 The prior failing build is here: https://lab.llvm.org/buildbot/#/builders/68/builds/73622 To make sure this error doesn't happen, I ran `ninja ProcessGdbRemoteTests` and then executed the resulting test binary and observed the `CalculateMD5` test passed. # Overview In my previous PR: https://github.com/llvm/llvm-project/pull/88812, @JDevlieghere suggested to match return types of the various calculate md5 functions. This PR achieves that by changing the various calculate md5 functions to return `llvm::ErrorOr<llvm::MD5::MD5Result>`.   The suggestion was to go for `std::optional<>` but I opted for `llvm::ErrorOr<>` because local calculate md5 was already possibly returning `ErrorOr`. To make sure I didn't break the md5 calculation functionality, I ran some tests for the gdb remote client, and things seem to work. # Testing 1. Remote file doesn't exist ![image](https://github.com/llvm/llvm-project/assets/1326275/b26859e2-18c3-4685-be8f-c6b6a5a4bc77) 1. Remote file differs ![image](https://github.com/llvm/llvm-project/assets/1326275/cbdb3c58-555a-401b-9444-c5ff4c04c491) 1. Remote file matches ![image](https://github.com/llvm/llvm-project/assets/1326275/07561572-22d1-4e0a-988f-bc91b5c2ffce) ## Test gaps Unfortunately, I had to modify `lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp` and I can't test the changes there. Hopefully, the existing test suite / code review from whomever is reading this will catch any issues.
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 7498a070c..db9fb37 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -3418,8 +3418,8 @@ bool GDBRemoteCommunicationClient::GetFileExists(
return true;
}
-bool GDBRemoteCommunicationClient::CalculateMD5(
- const lldb_private::FileSpec &file_spec, uint64_t &low, uint64_t &high) {
+llvm::ErrorOr<llvm::MD5::MD5Result> GDBRemoteCommunicationClient::CalculateMD5(
+ const lldb_private::FileSpec &file_spec) {
std::string path(file_spec.GetPath(false));
lldb_private::StreamString stream;
stream.PutCString("vFile:MD5:");
@@ -3428,11 +3428,11 @@ bool GDBRemoteCommunicationClient::CalculateMD5(
if (SendPacketAndWaitForResponse(stream.GetString(), response) ==
PacketResult::Success) {
if (response.GetChar() != 'F')
- return false;
+ return std::make_error_code(std::errc::illegal_byte_sequence);
if (response.GetChar() != ',')
- return false;
+ return std::make_error_code(std::errc::illegal_byte_sequence);
if (response.Peek() && *response.Peek() == 'x')
- return false;
+ return std::make_error_code(std::errc::no_such_file_or_directory);
// GDBRemoteCommunicationServerCommon::Handle_vFile_MD5 concatenates low and
// high hex strings. We can't use response.GetHexMaxU64 because that can't
@@ -3455,25 +3455,33 @@ bool GDBRemoteCommunicationClient::CalculateMD5(
auto part =
response.GetStringRef().substr(response.GetFilePos(), MD5_HALF_LENGTH);
if (part.size() != MD5_HALF_LENGTH)
- return false;
+ return std::make_error_code(std::errc::illegal_byte_sequence);
response.SetFilePos(response.GetFilePos() + part.size());
+ uint64_t low;
if (part.getAsInteger(/*radix=*/16, low))
- return false;
+ return std::make_error_code(std::errc::illegal_byte_sequence);
// Get high part
part =
response.GetStringRef().substr(response.GetFilePos(), MD5_HALF_LENGTH);
if (part.size() != MD5_HALF_LENGTH)
- return false;
+ return std::make_error_code(std::errc::illegal_byte_sequence);
response.SetFilePos(response.GetFilePos() + part.size());
+ uint64_t high;
if (part.getAsInteger(/*radix=*/16, high))
- return false;
+ return std::make_error_code(std::errc::illegal_byte_sequence);
- return true;
+ llvm::MD5::MD5Result result;
+ llvm::support::endian::write<uint64_t, llvm::endianness::little>(
+ result.data(), low);
+ llvm::support::endian::write<uint64_t, llvm::endianness::little>(
+ result.data() + 8, high);
+
+ return result;
}
- return false;
+ return std::make_error_code(std::errc::operation_canceled);
}
bool GDBRemoteCommunicationClient::AvoidGPackets(ProcessGDBRemote *process) {