Skip to content

Commit 5e7f0dc

Browse files
authored
[lldb] Include checksum in source cache dump (#106773)
This patch updates the source cache dump command to print both the actual (on-disk) checksum and the expected (line table) checksum. To achieve that we now read and store the on-disk checksum in the cached object. The same information will be used in a future path to print a warning when the checksums differ.
1 parent 923a1c1 commit 5e7f0dc

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lldb/include/lldb/Core/SourceManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLDB_CORE_SOURCEMANAGER_H
1010
#define LLDB_CORE_SOURCEMANAGER_H
1111

12+
#include "lldb/Utility/Checksum.h"
1213
#include "lldb/Utility/FileSpec.h"
1314
#include "lldb/lldb-defines.h"
1415
#include "lldb/lldb-forward.h"
@@ -71,6 +72,8 @@ class SourceManager {
7172

7273
llvm::sys::TimePoint<> GetTimestamp() const { return m_mod_time; }
7374

75+
const Checksum &GetChecksum() const { return m_checksum; }
76+
7477
protected:
7578
/// Set file and update modification time.
7679
void SetSupportFile(lldb::SupportFileSP support_file_sp);
@@ -81,6 +84,9 @@ class SourceManager {
8184
/// different from the original support file passed to the constructor.
8285
lldb::SupportFileSP m_support_file_sp;
8386

87+
/// Keep track of the on-disk checksum.
88+
Checksum m_checksum;
89+
8490
// Keep the modification time that this file data is valid for
8591
llvm::sys::TimePoint<> m_mod_time;
8692

lldb/source/Core/SourceManager.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,14 @@ void SourceManager::FindLinesMatchingRegex(SupportFileSP support_file_sp,
447447

448448
SourceManager::File::File(SupportFileSP support_file_sp,
449449
lldb::DebuggerSP debugger_sp)
450-
: m_support_file_sp(std::make_shared<SupportFile>()), m_mod_time(),
451-
m_debugger_wp(debugger_sp), m_target_wp(TargetSP()) {
450+
: m_support_file_sp(std::make_shared<SupportFile>()), m_checksum(),
451+
m_mod_time(), m_debugger_wp(debugger_sp), m_target_wp(TargetSP()) {
452452
CommonInitializer(support_file_sp, {});
453453
}
454454

455455
SourceManager::File::File(SupportFileSP support_file_sp, TargetSP target_sp)
456-
: m_support_file_sp(std::make_shared<SupportFile>()), m_mod_time(),
456+
: m_support_file_sp(std::make_shared<SupportFile>()), m_checksum(),
457+
m_mod_time(),
457458
m_debugger_wp(target_sp ? target_sp->GetDebugger().shared_from_this()
458459
: DebuggerSP()),
459460
m_target_wp(target_sp) {
@@ -532,9 +533,11 @@ void SourceManager::File::CommonInitializer(SupportFileSP support_file_sp,
532533
}
533534

534535
// If the file exists, read in the data.
535-
if (m_mod_time != llvm::sys::TimePoint<>())
536+
if (m_mod_time != llvm::sys::TimePoint<>()) {
536537
m_data_sp = FileSystem::Instance().CreateDataBuffer(
537538
m_support_file_sp->GetSpecOnly());
539+
m_checksum = llvm::MD5::hash(m_data_sp->GetData());
540+
}
538541
}
539542

540543
void SourceManager::File::SetSupportFile(lldb::SupportFileSP support_file_sp) {
@@ -835,14 +838,24 @@ SourceManager::FileSP SourceManager::SourceFileCache::FindSourceFile(
835838
return {};
836839
}
837840

841+
static std::string toString(const Checksum &checksum) {
842+
if (!checksum)
843+
return "";
844+
return std::string(llvm::formatv("{0}", checksum.digest()));
845+
}
846+
838847
void SourceManager::SourceFileCache::Dump(Stream &stream) const {
839-
stream << "Modification time Lines Path\n";
840-
stream << "------------------- -------- --------------------------------\n";
848+
// clang-format off
849+
stream << "Modification time MD5 Checksum (on-disk) MD5 Checksum (line table) Lines Path\n";
850+
stream << "------------------- -------------------------------- -------------------------------- -------- --------------------------------\n";
851+
// clang-format on
841852
for (auto &entry : m_file_cache) {
842853
if (!entry.second)
843854
continue;
844855
FileSP file = entry.second;
845-
stream.Format("{0:%Y-%m-%d %H:%M:%S} {1,8:d} {2}\n", file->GetTimestamp(),
856+
stream.Format("{0:%Y-%m-%d %H:%M:%S} {1,32} {2,32} {3,8:d} {4}\n",
857+
file->GetTimestamp(), toString(file->GetChecksum()),
858+
toString(file->GetSupportFile()->GetChecksum()),
846859
file->GetNumLines(), entry.first.GetPath());
847860
}
848861
}

0 commit comments

Comments
 (0)