Skip to content

Commit 076a259

Browse files
author
Zachary Turner
committed
Delete LLDB's MD5 code. Use LLVM instead.
Differential Revision: https://reviews.llvm.org/D31108 llvm-svn: 298325
1 parent 7e3050c commit 076a259

File tree

5 files changed

+20
-97
lines changed

5 files changed

+20
-97
lines changed

lldb/include/lldb/Host/FileSystem.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ class FileSystem {
3939

4040
static Error ResolveSymbolicLink(const FileSpec &src, FileSpec &dst);
4141

42-
static bool CalculateMD5(const FileSpec &file_spec, uint64_t &low,
43-
uint64_t &high);
44-
static bool CalculateMD5(const FileSpec &file_spec, uint64_t offset,
45-
uint64_t length, uint64_t &low, uint64_t &high);
46-
47-
static bool CalculateMD5AsString(const FileSpec &file_spec,
48-
std::string &digest_str);
49-
static bool CalculateMD5AsString(const FileSpec &file_spec, uint64_t offset,
50-
uint64_t length, std::string &digest_str);
51-
5242
/// Return \b true if \a spec is on a locally mounted file system, \b false
5343
/// otherwise.
5444
static bool IsLocal(const FileSpec &spec);

lldb/source/Host/common/FileSystem.cpp

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "lldb/Host/FileSystem.h"
1111

1212
#include "llvm/Support/FileSystem.h"
13-
#include "llvm/Support/MD5.h"
1413

1514
#include <algorithm>
1615
#include <fstream>
@@ -19,77 +18,6 @@
1918
using namespace lldb;
2019
using namespace lldb_private;
2120

22-
namespace {
23-
24-
bool CalcMD5(const FileSpec &file_spec, uint64_t offset, uint64_t length,
25-
llvm::MD5::MD5Result &md5_result) {
26-
llvm::MD5 md5_hash;
27-
std::ifstream file(file_spec.GetPath(), std::ios::binary);
28-
if (!file.is_open())
29-
return false;
30-
31-
if (offset > 0)
32-
file.seekg(offset, file.beg);
33-
34-
std::vector<char> read_buf(4096);
35-
uint64_t total_read_bytes = 0;
36-
while (!file.eof()) {
37-
const uint64_t to_read =
38-
(length > 0) ? std::min(static_cast<uint64_t>(read_buf.size()),
39-
length - total_read_bytes)
40-
: read_buf.size();
41-
if (to_read == 0)
42-
break;
43-
44-
file.read(&read_buf[0], to_read);
45-
const auto read_bytes = file.gcount();
46-
if (read_bytes == 0)
47-
break;
48-
49-
md5_hash.update(llvm::StringRef(&read_buf[0], read_bytes));
50-
total_read_bytes += read_bytes;
51-
}
52-
53-
md5_hash.final(md5_result);
54-
return true;
55-
}
56-
57-
} // namespace
58-
59-
bool FileSystem::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
60-
uint64_t &high) {
61-
return CalculateMD5(file_spec, 0, 0, low, high);
62-
}
63-
64-
bool FileSystem::CalculateMD5(const FileSpec &file_spec, uint64_t offset,
65-
uint64_t length, uint64_t &low, uint64_t &high) {
66-
llvm::MD5::MD5Result md5_result;
67-
if (!CalcMD5(file_spec, offset, length, md5_result))
68-
return false;
69-
70-
std::tie(high, low) = md5_result.words();
71-
72-
return true;
73-
}
74-
75-
bool FileSystem::CalculateMD5AsString(const FileSpec &file_spec,
76-
std::string &digest_str) {
77-
return CalculateMD5AsString(file_spec, 0, 0, digest_str);
78-
}
79-
80-
bool FileSystem::CalculateMD5AsString(const FileSpec &file_spec,
81-
uint64_t offset, uint64_t length,
82-
std::string &digest_str) {
83-
llvm::MD5::MD5Result md5_result;
84-
if (!CalcMD5(file_spec, offset, length, md5_result))
85-
return false;
86-
87-
llvm::SmallString<32> result_str;
88-
llvm::MD5::stringifyResult(md5_result, result_str);
89-
digest_str = result_str.c_str();
90-
return true;
91-
}
92-
9321
llvm::sys::TimePoint<>
9422
FileSystem::GetModificationTime(const FileSpec &file_spec) {
9523
llvm::sys::fs::file_status status;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "lldb/Core/Module.h"
2626
#include "lldb/Core/ModuleSpec.h"
2727
#include "lldb/Core/Timer.h"
28-
#include "lldb/Host/FileSystem.h"
2928
#include "lldb/Host/Host.h"
3029
#include "lldb/Host/HostInfo.h"
3130
#include "lldb/Host/StringConvert.h"
@@ -297,11 +296,14 @@ lldb_private::Error PlatformDarwin::GetSharedModuleWithLocalCache(
297296
// get the local and remote MD5 and compare
298297
if (m_remote_platform_sp) {
299298
// when going over the *slow* GDB remote transfer mechanism we first
300-
// check
301-
// the hashes of the files - and only do the actual transfer if they
302-
// differ
299+
// check the hashes of the files - and only do the actual transfer if
300+
// they differ
303301
uint64_t high_local, high_remote, low_local, low_remote;
304-
FileSystem::CalculateMD5(module_cache_spec, low_local, high_local);
302+
auto MD5 = llvm::sys::fs::md5_contents(module_cache_spec.GetPath());
303+
if (!MD5)
304+
return Error(MD5.getError());
305+
std::tie(high_local, low_local) = MD5->words();
306+
305307
m_remote_platform_sp->CalculateMD5(module_spec.GetFileSpec(),
306308
low_remote, high_remote);
307309
if (low_local != low_remote || high_local != high_remote) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,14 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_MD5(
773773
if (!path.empty()) {
774774
uint64_t a, b;
775775
StreamGDBRemote response;
776-
if (!FileSystem::CalculateMD5(FileSpec(path, false), a, b)) {
776+
auto Result = llvm::sys::fs::md5_contents(path);
777+
if (!Result) {
777778
response.PutCString("F,");
778779
response.PutCString("x");
779780
} else {
780781
response.PutCString("F,");
781-
response.PutHex64(a);
782-
response.PutHex64(b);
782+
response.PutHex64(Result->low());
783+
response.PutHex64(Result->high());
783784
}
784785
return SendPacketNoLock(response.GetString());
785786
}
@@ -1092,12 +1093,11 @@ GDBRemoteCommunicationServerCommon::Handle_qModuleInfo(
10921093
StreamGDBRemote response;
10931094

10941095
if (uuid_str.empty()) {
1095-
std::string md5_hash;
1096-
if (!FileSystem::CalculateMD5AsString(matched_module_spec.GetFileSpec(),
1097-
file_offset, file_size, md5_hash))
1096+
auto Result = llvm::sys::fs::md5_contents(matched_module_spec.GetFileSpec().GetPath());
1097+
if (!Result)
10981098
return SendErrorResponse(5);
10991099
response.PutCString("md5:");
1100-
response.PutCStringAsRawHex8(md5_hash.c_str());
1100+
response.PutCStringAsRawHex8(Result->digest().c_str());
11011101
} else {
11021102
response.PutCString("uuid:");
11031103
response.PutCStringAsRawHex8(uuid_str.c_str());

lldb/source/Target/Platform.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,10 +1346,13 @@ lldb_private::Error Platform::RunShellCommand(
13461346

13471347
bool Platform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
13481348
uint64_t &high) {
1349-
if (IsHost())
1350-
return FileSystem::CalculateMD5(file_spec, low, high);
1351-
else
1349+
if (!IsHost())
13521350
return false;
1351+
auto Result = llvm::sys::fs::md5_contents(file_spec.GetPath());
1352+
if (!Result)
1353+
return false;
1354+
std::tie(high, low) = Result->words();
1355+
return true;
13531356
}
13541357

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

0 commit comments

Comments
 (0)