Skip to content

Commit ca8b064

Browse files
authored
Revert "[lldb] Unify CalculateMD5 return types" (#90998)
Reverts #90921
1 parent f561daf commit ca8b064

File tree

9 files changed

+52
-60
lines changed

9 files changed

+52
-60
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,8 @@ class Platform : public PluginInterface {
649649

650650
virtual std::string GetPlatformSpecificConnectionInformation() { return ""; }
651651

652-
virtual llvm::ErrorOr<llvm::MD5::MD5Result>
653-
CalculateMD5(const FileSpec &file_spec);
652+
virtual bool CalculateMD5(const FileSpec &file_spec, uint64_t &low,
653+
uint64_t &high);
654654

655655
virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
656656
return 1;

lldb/include/lldb/Target/RemoteAwarePlatform.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class RemoteAwarePlatform : public Platform {
5858
Status SetFilePermissions(const FileSpec &file_spec,
5959
uint32_t file_permissions) override;
6060

61-
llvm::ErrorOr<llvm::MD5::MD5Result>
62-
CalculateMD5(const FileSpec &file_spec) override;
61+
bool CalculateMD5(const FileSpec &file_spec, uint64_t &low,
62+
uint64_t &high) override;
6363

6464
Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
6565
FileSpec &local_file) override;

lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,21 +405,17 @@ lldb_private::Status PlatformDarwinDevice::GetSharedModuleWithLocalCache(
405405
// when going over the *slow* GDB remote transfer mechanism we first
406406
// check the hashes of the files - and only do the actual transfer if
407407
// they differ
408+
uint64_t high_local, high_remote, low_local, low_remote;
408409
auto MD5 = llvm::sys::fs::md5_contents(module_cache_spec.GetPath());
409410
if (!MD5)
410411
return Status(MD5.getError());
412+
std::tie(high_local, low_local) = MD5->words();
411413

412-
Log *log = GetLog(LLDBLog::Platform);
413-
bool requires_transfer = true;
414-
llvm::ErrorOr<llvm::MD5::MD5Result> remote_md5 =
415-
m_remote_platform_sp->CalculateMD5(module_spec.GetFileSpec());
416-
if (std::error_code ec = remote_md5.getError())
417-
LLDB_LOG(log, "couldn't get md5 sum from remote: {0}",
418-
ec.message());
419-
else
420-
requires_transfer = *MD5 != *remote_md5;
421-
if (requires_transfer) {
414+
m_remote_platform_sp->CalculateMD5(module_spec.GetFileSpec(),
415+
low_remote, high_remote);
416+
if (low_local != low_remote || high_local != high_remote) {
422417
// bring in the remote file
418+
Log *log = GetLog(LLDBLog::Platform);
423419
LLDB_LOGF(log,
424420
"[%s] module %s/%s needs to be replaced from remote copy",
425421
(IsHost() ? "host" : "remote"),

lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,12 @@ Status PlatformRemoteGDBServer::RunShellCommand(
684684
signo_ptr, command_output, timeout);
685685
}
686686

687-
llvm::ErrorOr<llvm::MD5::MD5Result>
688-
PlatformRemoteGDBServer::CalculateMD5(const FileSpec &file_spec) {
687+
bool PlatformRemoteGDBServer::CalculateMD5(const FileSpec &file_spec,
688+
uint64_t &low, uint64_t &high) {
689689
if (!IsConnected())
690-
return std::make_error_code(std::errc::not_connected);
690+
return false;
691691

692-
return m_gdb_client_up->CalculateMD5(file_spec);
692+
return m_gdb_client_up->CalculateMD5(file_spec, low, high);
693693
}
694694

695695
void PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames() {

lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {
146146

147147
void CalculateTrapHandlerSymbolNames() override;
148148

149-
llvm::ErrorOr<llvm::MD5::MD5Result>
150-
CalculateMD5(const FileSpec &file_spec) override;
149+
bool CalculateMD5(const FileSpec &file_spec, uint64_t &low,
150+
uint64_t &high) override;
151151

152152
const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
153153

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,8 +3418,8 @@ bool GDBRemoteCommunicationClient::GetFileExists(
34183418
return true;
34193419
}
34203420

3421-
llvm::ErrorOr<llvm::MD5::MD5Result> GDBRemoteCommunicationClient::CalculateMD5(
3422-
const lldb_private::FileSpec &file_spec) {
3421+
bool GDBRemoteCommunicationClient::CalculateMD5(
3422+
const lldb_private::FileSpec &file_spec, uint64_t &low, uint64_t &high) {
34233423
std::string path(file_spec.GetPath(false));
34243424
lldb_private::StreamString stream;
34253425
stream.PutCString("vFile:MD5:");
@@ -3428,11 +3428,11 @@ llvm::ErrorOr<llvm::MD5::MD5Result> GDBRemoteCommunicationClient::CalculateMD5(
34283428
if (SendPacketAndWaitForResponse(stream.GetString(), response) ==
34293429
PacketResult::Success) {
34303430
if (response.GetChar() != 'F')
3431-
return std::make_error_code(std::errc::illegal_byte_sequence);
3431+
return false;
34323432
if (response.GetChar() != ',')
3433-
return std::make_error_code(std::errc::illegal_byte_sequence);
3433+
return false;
34343434
if (response.Peek() && *response.Peek() == 'x')
3435-
return std::make_error_code(std::errc::no_such_file_or_directory);
3435+
return false;
34363436

34373437
// GDBRemoteCommunicationServerCommon::Handle_vFile_MD5 concatenates low and
34383438
// high hex strings. We can't use response.GetHexMaxU64 because that can't
@@ -3455,33 +3455,25 @@ llvm::ErrorOr<llvm::MD5::MD5Result> GDBRemoteCommunicationClient::CalculateMD5(
34553455
auto part =
34563456
response.GetStringRef().substr(response.GetFilePos(), MD5_HALF_LENGTH);
34573457
if (part.size() != MD5_HALF_LENGTH)
3458-
return std::make_error_code(std::errc::illegal_byte_sequence);
3458+
return false;
34593459
response.SetFilePos(response.GetFilePos() + part.size());
34603460

3461-
uint64_t low;
34623461
if (part.getAsInteger(/*radix=*/16, low))
3463-
return std::make_error_code(std::errc::illegal_byte_sequence);
3462+
return false;
34643463

34653464
// Get high part
34663465
part =
34673466
response.GetStringRef().substr(response.GetFilePos(), MD5_HALF_LENGTH);
34683467
if (part.size() != MD5_HALF_LENGTH)
3469-
return std::make_error_code(std::errc::illegal_byte_sequence);
3468+
return false;
34703469
response.SetFilePos(response.GetFilePos() + part.size());
34713470

3472-
uint64_t high;
34733471
if (part.getAsInteger(/*radix=*/16, high))
3474-
return std::make_error_code(std::errc::illegal_byte_sequence);
3475-
3476-
llvm::MD5::MD5Result result;
3477-
llvm::support::endian::write<uint64_t, llvm::endianness::little>(
3478-
result.data(), low);
3479-
llvm::support::endian::write<uint64_t, llvm::endianness::little>(
3480-
result.data() + 8, high);
3472+
return false;
34813473

3482-
return result;
3474+
return true;
34833475
}
3484-
return std::make_error_code(std::errc::operation_canceled);
3476+
return false;
34853477
}
34863478

34873479
bool GDBRemoteCommunicationClient::AvoidGPackets(ProcessGDBRemote *process) {

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase {
392392
*command_output, // Pass nullptr if you don't want the command output
393393
const Timeout<std::micro> &timeout);
394394

395-
llvm::ErrorOr<llvm::MD5::MD5Result> CalculateMD5(const FileSpec &file_spec);
395+
bool CalculateMD5(const FileSpec &file_spec, uint64_t &low, uint64_t &high);
396396

397397
lldb::DataBufferSP ReadRegister(
398398
lldb::tid_t tid,

lldb/source/Target/Platform.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,22 +1199,22 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
11991199
Status error;
12001200

12011201
bool requires_upload = true;
1202-
llvm::ErrorOr<llvm::MD5::MD5Result> remote_md5 = CalculateMD5(destination);
1203-
if (std::error_code ec = remote_md5.getError()) {
1204-
LLDB_LOG(log, "[PutFile] couldn't get md5 sum of destination: {0}",
1205-
ec.message());
1202+
uint64_t dest_md5_low, dest_md5_high;
1203+
bool success = CalculateMD5(destination, dest_md5_low, dest_md5_high);
1204+
if (!success) {
1205+
LLDB_LOGF(log, "[PutFile] couldn't get md5 sum of destination");
12061206
} else {
1207-
llvm::ErrorOr<llvm::MD5::MD5Result> local_md5 =
1208-
llvm::sys::fs::md5_contents(source.GetPath());
1209-
if (std::error_code ec = local_md5.getError()) {
1210-
LLDB_LOG(log, "[PutFile] couldn't get md5 sum of source: {0}",
1211-
ec.message());
1207+
auto local_md5 = llvm::sys::fs::md5_contents(source.GetPath());
1208+
if (!local_md5) {
1209+
LLDB_LOGF(log, "[PutFile] couldn't get md5 sum of source");
12121210
} else {
1211+
const auto [local_md5_high, local_md5_low] = local_md5->words();
12131212
LLDB_LOGF(log, "[PutFile] destination md5: %016" PRIx64 "%016" PRIx64,
1214-
remote_md5->high(), remote_md5->low());
1213+
dest_md5_high, dest_md5_low);
12151214
LLDB_LOGF(log, "[PutFile] local md5: %016" PRIx64 "%016" PRIx64,
1216-
local_md5->high(), local_md5->low());
1217-
requires_upload = *remote_md5 != *local_md5;
1215+
local_md5_high, local_md5_low);
1216+
requires_upload =
1217+
local_md5_high != dest_md5_high || local_md5_low != dest_md5_low;
12181218
}
12191219
}
12201220

@@ -1339,11 +1339,15 @@ lldb_private::Status Platform::RunShellCommand(
13391339
return Status("unable to run a remote command without a platform");
13401340
}
13411341

1342-
llvm::ErrorOr<llvm::MD5::MD5Result>
1343-
Platform::CalculateMD5(const FileSpec &file_spec) {
1342+
bool Platform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
1343+
uint64_t &high) {
13441344
if (!IsHost())
1345-
return std::make_error_code(std::errc::not_supported);
1346-
return llvm::sys::fs::md5_contents(file_spec.GetPath());
1345+
return false;
1346+
auto Result = llvm::sys::fs::md5_contents(file_spec.GetPath());
1347+
if (!Result)
1348+
return false;
1349+
std::tie(high, low) = Result->words();
1350+
return true;
13471351
}
13481352

13491353
void Platform::SetLocalCacheDirectory(const char *local) {

lldb/source/Target/RemoteAwarePlatform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ Status RemoteAwarePlatform::Unlink(const FileSpec &file_spec) {
266266
return Platform::Unlink(file_spec);
267267
}
268268

269-
llvm::ErrorOr<llvm::MD5::MD5Result>
270-
RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec) {
269+
bool RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
270+
uint64_t &high) {
271271
if (m_remote_platform_sp)
272-
return m_remote_platform_sp->CalculateMD5(file_spec);
273-
return Platform::CalculateMD5(file_spec);
272+
return m_remote_platform_sp->CalculateMD5(file_spec, low, high);
273+
return Platform::CalculateMD5(file_spec, low, high);
274274
}
275275

276276
FileSpec RemoteAwarePlatform::GetRemoteWorkingDirectory() {

0 commit comments

Comments
 (0)