Delete LLDB's MD5 code. Use LLVM instead.

Differential Revision: https://reviews.llvm.org/D31108

llvm-svn: 298325
This commit is contained in:
Zachary Turner 2017-03-20 23:54:54 +00:00
parent 7e3050ca1a
commit 076a259938
5 changed files with 20 additions and 97 deletions

View File

@ -39,16 +39,6 @@ public:
static Error ResolveSymbolicLink(const FileSpec &src, FileSpec &dst);
static bool CalculateMD5(const FileSpec &file_spec, uint64_t &low,
uint64_t &high);
static bool CalculateMD5(const FileSpec &file_spec, uint64_t offset,
uint64_t length, uint64_t &low, uint64_t &high);
static bool CalculateMD5AsString(const FileSpec &file_spec,
std::string &digest_str);
static bool CalculateMD5AsString(const FileSpec &file_spec, uint64_t offset,
uint64_t length, std::string &digest_str);
/// Return \b true if \a spec is on a locally mounted file system, \b false
/// otherwise.
static bool IsLocal(const FileSpec &spec);

View File

@ -10,7 +10,6 @@
#include "lldb/Host/FileSystem.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MD5.h"
#include <algorithm>
#include <fstream>
@ -19,77 +18,6 @@
using namespace lldb;
using namespace lldb_private;
namespace {
bool CalcMD5(const FileSpec &file_spec, uint64_t offset, uint64_t length,
llvm::MD5::MD5Result &md5_result) {
llvm::MD5 md5_hash;
std::ifstream file(file_spec.GetPath(), std::ios::binary);
if (!file.is_open())
return false;
if (offset > 0)
file.seekg(offset, file.beg);
std::vector<char> read_buf(4096);
uint64_t total_read_bytes = 0;
while (!file.eof()) {
const uint64_t to_read =
(length > 0) ? std::min(static_cast<uint64_t>(read_buf.size()),
length - total_read_bytes)
: read_buf.size();
if (to_read == 0)
break;
file.read(&read_buf[0], to_read);
const auto read_bytes = file.gcount();
if (read_bytes == 0)
break;
md5_hash.update(llvm::StringRef(&read_buf[0], read_bytes));
total_read_bytes += read_bytes;
}
md5_hash.final(md5_result);
return true;
}
} // namespace
bool FileSystem::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
uint64_t &high) {
return CalculateMD5(file_spec, 0, 0, low, high);
}
bool FileSystem::CalculateMD5(const FileSpec &file_spec, uint64_t offset,
uint64_t length, uint64_t &low, uint64_t &high) {
llvm::MD5::MD5Result md5_result;
if (!CalcMD5(file_spec, offset, length, md5_result))
return false;
std::tie(high, low) = md5_result.words();
return true;
}
bool FileSystem::CalculateMD5AsString(const FileSpec &file_spec,
std::string &digest_str) {
return CalculateMD5AsString(file_spec, 0, 0, digest_str);
}
bool FileSystem::CalculateMD5AsString(const FileSpec &file_spec,
uint64_t offset, uint64_t length,
std::string &digest_str) {
llvm::MD5::MD5Result md5_result;
if (!CalcMD5(file_spec, offset, length, md5_result))
return false;
llvm::SmallString<32> result_str;
llvm::MD5::stringifyResult(md5_result, result_str);
digest_str = result_str.c_str();
return true;
}
llvm::sys::TimePoint<>
FileSystem::GetModificationTime(const FileSpec &file_spec) {
llvm::sys::fs::file_status status;

View File

@ -25,7 +25,6 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Timer.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/StringConvert.h"
@ -297,11 +296,14 @@ lldb_private::Error PlatformDarwin::GetSharedModuleWithLocalCache(
// get the local and remote MD5 and compare
if (m_remote_platform_sp) {
// 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
// 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;
FileSystem::CalculateMD5(module_cache_spec, low_local, high_local);
auto MD5 = llvm::sys::fs::md5_contents(module_cache_spec.GetPath());
if (!MD5)
return Error(MD5.getError());
std::tie(high_local, low_local) = MD5->words();
m_remote_platform_sp->CalculateMD5(module_spec.GetFileSpec(),
low_remote, high_remote);
if (low_local != low_remote || high_local != high_remote) {

View File

@ -773,13 +773,14 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_MD5(
if (!path.empty()) {
uint64_t a, b;
StreamGDBRemote response;
if (!FileSystem::CalculateMD5(FileSpec(path, false), a, b)) {
auto Result = llvm::sys::fs::md5_contents(path);
if (!Result) {
response.PutCString("F,");
response.PutCString("x");
} else {
response.PutCString("F,");
response.PutHex64(a);
response.PutHex64(b);
response.PutHex64(Result->low());
response.PutHex64(Result->high());
}
return SendPacketNoLock(response.GetString());
}
@ -1092,12 +1093,11 @@ GDBRemoteCommunicationServerCommon::Handle_qModuleInfo(
StreamGDBRemote response;
if (uuid_str.empty()) {
std::string md5_hash;
if (!FileSystem::CalculateMD5AsString(matched_module_spec.GetFileSpec(),
file_offset, file_size, md5_hash))
auto Result = llvm::sys::fs::md5_contents(matched_module_spec.GetFileSpec().GetPath());
if (!Result)
return SendErrorResponse(5);
response.PutCString("md5:");
response.PutCStringAsRawHex8(md5_hash.c_str());
response.PutCStringAsRawHex8(Result->digest().c_str());
} else {
response.PutCString("uuid:");
response.PutCStringAsRawHex8(uuid_str.c_str());

View File

@ -1346,10 +1346,13 @@ lldb_private::Error Platform::RunShellCommand(
bool Platform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
uint64_t &high) {
if (IsHost())
return FileSystem::CalculateMD5(file_spec, low, high);
else
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;
}
void Platform::SetLocalCacheDirectory(const char *local) {