[Lldb-commits] [lldb] r298325 - Delete LLDB's MD5 code. Use LLVM instead.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 20 16:54:54 PDT 2017
Author: zturner
Date: Mon Mar 20 18:54:54 2017
New Revision: 298325
URL: http://llvm.org/viewvc/llvm-project?rev=298325&view=rev
Log:
Delete LLDB's MD5 code. Use LLVM instead.
Differential Revision: https://reviews.llvm.org/D31108
Modified:
lldb/trunk/include/lldb/Host/FileSystem.h
lldb/trunk/source/Host/common/FileSystem.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/trunk/source/Target/Platform.cpp
Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=298325&r1=298324&r2=298325&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Mon Mar 20 18:54:54 2017
@@ -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);
Modified: lldb/trunk/source/Host/common/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSystem.cpp?rev=298325&r1=298324&r2=298325&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/common/FileSystem.cpp Mon Mar 20 18:54:54 2017
@@ -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;
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=298325&r1=298324&r2=298325&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Mon Mar 20 18:54:54 2017
@@ -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::GetS
// 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) {
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=298325&r1=298324&r2=298325&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Mon Mar 20 18:54:54 2017
@@ -773,13 +773,14 @@ GDBRemoteCommunicationServerCommon::Hand
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::Hand
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());
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=298325&r1=298324&r2=298325&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Mon Mar 20 18:54:54 2017
@@ -1346,10 +1346,13 @@ lldb_private::Error Platform::RunShellCo
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) {
More information about the lldb-commits
mailing list