Skip to content

Commit

Permalink
Revert "[lldb] Unify CalculateMD5 return types" (#90998)
Browse files Browse the repository at this point in the history
Reverts #90921
  • Loading branch information
JDevlieghere committed May 3, 2024
1 parent f561daf commit ca8b064
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 60 deletions.
4 changes: 2 additions & 2 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ class Platform : public PluginInterface {

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

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

virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
return 1;
Expand Down
4 changes: 2 additions & 2 deletions lldb/include/lldb/Target/RemoteAwarePlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class RemoteAwarePlatform : public Platform {
Status SetFilePermissions(const FileSpec &file_spec,
uint32_t file_permissions) override;

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

Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
FileSpec &local_file) override;
Expand Down
16 changes: 6 additions & 10 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,21 +405,17 @@ lldb_private::Status PlatformDarwinDevice::GetSharedModuleWithLocalCache(
// when going over the *slow* GDB remote transfer mechanism we first
// check the hashes of the files - and only do the actual transfer if
// they differ
uint64_t high_local, high_remote, low_local, low_remote;
auto MD5 = llvm::sys::fs::md5_contents(module_cache_spec.GetPath());
if (!MD5)
return Status(MD5.getError());
std::tie(high_local, low_local) = MD5->words();

Log *log = GetLog(LLDBLog::Platform);
bool requires_transfer = true;
llvm::ErrorOr<llvm::MD5::MD5Result> remote_md5 =
m_remote_platform_sp->CalculateMD5(module_spec.GetFileSpec());
if (std::error_code ec = remote_md5.getError())
LLDB_LOG(log, "couldn't get md5 sum from remote: {0}",
ec.message());
else
requires_transfer = *MD5 != *remote_md5;
if (requires_transfer) {
m_remote_platform_sp->CalculateMD5(module_spec.GetFileSpec(),
low_remote, high_remote);
if (low_local != low_remote || high_local != high_remote) {
// bring in the remote file
Log *log = GetLog(LLDBLog::Platform);
LLDB_LOGF(log,
"[%s] module %s/%s needs to be replaced from remote copy",
(IsHost() ? "host" : "remote"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,12 @@ Status PlatformRemoteGDBServer::RunShellCommand(
signo_ptr, command_output, timeout);
}

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

return m_gdb_client_up->CalculateMD5(file_spec);
return m_gdb_client_up->CalculateMD5(file_spec, low, high);
}

void PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {

void CalculateTrapHandlerSymbolNames() override;

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

const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3418,8 +3418,8 @@ bool GDBRemoteCommunicationClient::GetFileExists(
return true;
}

llvm::ErrorOr<llvm::MD5::MD5Result> GDBRemoteCommunicationClient::CalculateMD5(
const lldb_private::FileSpec &file_spec) {
bool GDBRemoteCommunicationClient::CalculateMD5(
const lldb_private::FileSpec &file_spec, uint64_t &low, uint64_t &high) {
std::string path(file_spec.GetPath(false));
lldb_private::StreamString stream;
stream.PutCString("vFile:MD5:");
Expand All @@ -3428,11 +3428,11 @@ llvm::ErrorOr<llvm::MD5::MD5Result> GDBRemoteCommunicationClient::CalculateMD5(
if (SendPacketAndWaitForResponse(stream.GetString(), response) ==
PacketResult::Success) {
if (response.GetChar() != 'F')
return std::make_error_code(std::errc::illegal_byte_sequence);
return false;
if (response.GetChar() != ',')
return std::make_error_code(std::errc::illegal_byte_sequence);
return false;
if (response.Peek() && *response.Peek() == 'x')
return std::make_error_code(std::errc::no_such_file_or_directory);
return false;

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

uint64_t low;
if (part.getAsInteger(/*radix=*/16, low))
return std::make_error_code(std::errc::illegal_byte_sequence);
return false;

// Get high part
part =
response.GetStringRef().substr(response.GetFilePos(), MD5_HALF_LENGTH);
if (part.size() != MD5_HALF_LENGTH)
return std::make_error_code(std::errc::illegal_byte_sequence);
return false;
response.SetFilePos(response.GetFilePos() + part.size());

uint64_t high;
if (part.getAsInteger(/*radix=*/16, high))
return std::make_error_code(std::errc::illegal_byte_sequence);

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 false;

return result;
return true;
}
return std::make_error_code(std::errc::operation_canceled);
return false;
}

bool GDBRemoteCommunicationClient::AvoidGPackets(ProcessGDBRemote *process) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase {
*command_output, // Pass nullptr if you don't want the command output
const Timeout<std::micro> &timeout);

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

lldb::DataBufferSP ReadRegister(
lldb::tid_t tid,
Expand Down
36 changes: 20 additions & 16 deletions lldb/source/Target/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,22 +1199,22 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
Status error;

bool requires_upload = true;
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());
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");
} else {
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());
auto local_md5 = llvm::sys::fs::md5_contents(source.GetPath());
if (!local_md5) {
LLDB_LOGF(log, "[PutFile] couldn't get md5 sum of source");
} else {
const auto [local_md5_high, local_md5_low] = local_md5->words();
LLDB_LOGF(log, "[PutFile] destination md5: %016" PRIx64 "%016" PRIx64,
remote_md5->high(), remote_md5->low());
dest_md5_high, dest_md5_low);
LLDB_LOGF(log, "[PutFile] local md5: %016" PRIx64 "%016" PRIx64,
local_md5->high(), local_md5->low());
requires_upload = *remote_md5 != *local_md5;
local_md5_high, local_md5_low);
requires_upload =
local_md5_high != dest_md5_high || local_md5_low != dest_md5_low;
}
}

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

llvm::ErrorOr<llvm::MD5::MD5Result>
Platform::CalculateMD5(const FileSpec &file_spec) {
bool Platform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
uint64_t &high) {
if (!IsHost())
return std::make_error_code(std::errc::not_supported);
return llvm::sys::fs::md5_contents(file_spec.GetPath());
return false;
auto Result = llvm::sys::fs::md5_contents(file_spec.GetPath());
if (!Result)
return false;
std::tie(high, low) = Result->words();
return true;
}

void Platform::SetLocalCacheDirectory(const char *local) {
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Target/RemoteAwarePlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ Status RemoteAwarePlatform::Unlink(const FileSpec &file_spec) {
return Platform::Unlink(file_spec);
}

llvm::ErrorOr<llvm::MD5::MD5Result>
RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec) {
bool RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
uint64_t &high) {
if (m_remote_platform_sp)
return m_remote_platform_sp->CalculateMD5(file_spec);
return Platform::CalculateMD5(file_spec);
return m_remote_platform_sp->CalculateMD5(file_spec, low, high);
return Platform::CalculateMD5(file_spec, low, high);
}

FileSpec RemoteAwarePlatform::GetRemoteWorkingDirectory() {
Expand Down

0 comments on commit ca8b064

Please sign in to comment.