Skip to content

Commit

Permalink
Delete LLDB's MD5 code. Use LLVM instead.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D31108

llvm-svn: 298325
  • Loading branch information
Zachary Turner committed Mar 20, 2017
1 parent 7e3050c commit 076a259
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 97 deletions.
10 changes: 0 additions & 10 deletions lldb/include/lldb/Host/FileSystem.h
Expand Up @@ -39,16 +39,6 @@ class FileSystem {

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);
Expand Down
72 changes: 0 additions & 72 deletions lldb/source/Host/common/FileSystem.cpp
Expand Up @@ -10,7 +10,6 @@
#include "lldb/Host/FileSystem.h"

#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MD5.h"

#include <algorithm>
#include <fstream>
Expand All @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
Expand Down
9 changes: 6 additions & 3 deletions lldb/source/Target/Platform.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit 076a259

Please sign in to comment.