summaryrefslogtreecommitdiff
path: root/lldb/source/Target/Platform.cpp
diff options
context:
space:
mode:
authorAnthony Ha <anthonyha96@gmail.com>2024-05-03 11:51:25 -0700
committerGitHub <noreply@github.com>2024-05-03 11:51:25 -0700
commit2f58b9aae2d6f1aeaecd98766ef31cebc0dcbb5b (patch)
tree541e0950889366ccdc301be85df99440a01691e2 /lldb/source/Target/Platform.cpp
parentf8a9973f8c1ef60281ace6f3cfeb24d9dcd5b3c3 (diff)
[lldb] Unify CalculateMD5 return types (#90921)
# 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. Co-authored-by: Anthony Ha <antha@microsoft.com>
Diffstat (limited to 'lldb/source/Target/Platform.cpp')
-rw-r--r--lldb/source/Target/Platform.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 91483ba008f4..4af4aa68ccd0 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1199,22 +1199,22 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
Status error;
bool requires_upload = true;
- uint64_t dest_md5_low, dest_md5_high;
- bool success = CalculateMD5(destination, dest_md5_low, dest_md5_high);
- if (!success) {
- LLDB_LOGF(log, "[PutFile] couldn't get md5 sum of destination");
+ llvm::ErrorOr<llvm::MD5::MD5Result> remote_md5 = CalculateMD5(destination);
+ if (std::error_code ec = remote_md5.getError()) {
+ LLDB_LOG(log, "[PutFile] couldn't get md5 sum of destination: {0}",
+ ec.message());
} else {
- auto local_md5 = llvm::sys::fs::md5_contents(source.GetPath());
- if (!local_md5) {
- LLDB_LOGF(log, "[PutFile] couldn't get md5 sum of source");
+ llvm::ErrorOr<llvm::MD5::MD5Result> local_md5 =
+ llvm::sys::fs::md5_contents(source.GetPath());
+ if (std::error_code ec = local_md5.getError()) {
+ LLDB_LOG(log, "[PutFile] couldn't get md5 sum of source: {0}",
+ ec.message());
} else {
- const auto [local_md5_high, local_md5_low] = local_md5->words();
LLDB_LOGF(log, "[PutFile] destination md5: %016" PRIx64 "%016" PRIx64,
- dest_md5_high, dest_md5_low);
+ remote_md5->high(), remote_md5->low());
LLDB_LOGF(log, "[PutFile] local md5: %016" PRIx64 "%016" PRIx64,
- local_md5_high, local_md5_low);
- requires_upload =
- local_md5_high != dest_md5_high || local_md5_low != dest_md5_low;
+ local_md5->high(), local_md5->low());
+ requires_upload = *remote_md5 != *local_md5;
}
}
@@ -1339,15 +1339,11 @@ lldb_private::Status Platform::RunShellCommand(
return Status("unable to run a remote command without a platform");
}
-bool Platform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
- uint64_t &high) {
+llvm::ErrorOr<llvm::MD5::MD5Result>
+Platform::CalculateMD5(const FileSpec &file_spec) {
if (!IsHost())
- return false;
- auto Result = llvm::sys::fs::md5_contents(file_spec.GetPath());
- if (!Result)
- return false;
- std::tie(high, low) = Result->words();
- return true;
+ return std::make_error_code(std::errc::not_supported);
+ return llvm::sys::fs::md5_contents(file_spec.GetPath());
}
void Platform::SetLocalCacheDirectory(const char *local) {