https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/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. >From a73b63a4b3e74b92b9ef5f913c75b4710859bca6 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Fri, 30 Aug 2024 11:07:50 -0700 Subject: [PATCH] [lldb] Include checksum in source cache dump 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. --- lldb/include/lldb/Core/SourceManager.h | 12 ++++++++++++ lldb/source/Core/SourceManager.cpp | 27 +++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lldb/include/lldb/Core/SourceManager.h b/lldb/include/lldb/Core/SourceManager.h index ae7bd3d2311f96..70325f134f2a68 100644 --- a/lldb/include/lldb/Core/SourceManager.h +++ b/lldb/include/lldb/Core/SourceManager.h @@ -9,6 +9,7 @@ #ifndef LLDB_CORE_SOURCEMANAGER_H #define LLDB_CORE_SOURCEMANAGER_H +#include "lldb/Utility/Checksum.h" #include "lldb/Utility/FileSpec.h" #include "lldb/lldb-defines.h" #include "lldb/lldb-forward.h" @@ -42,6 +43,7 @@ class SourceManager { bool ModificationTimeIsStale() const; bool PathRemappingIsStale() const; + bool ChecksumIsStale() const; size_t DisplaySourceLines(uint32_t line, std::optional<size_t> column, uint32_t context_before, uint32_t context_after, @@ -71,6 +73,10 @@ class SourceManager { llvm::sys::TimePoint<> GetTimestamp() const { return m_mod_time; } + const Checksum &GetChecksum() const { return m_checksum; } + + llvm::once_flag &GetChecksumOnceFlag() { return m_checksum_once_flag; } + protected: /// Set file and update modification time. void SetSupportFile(lldb::SupportFileSP support_file_sp); @@ -81,6 +87,12 @@ class SourceManager { /// different from the original support file passed to the constructor. lldb::SupportFileSP m_support_file_sp; + /// Keep track of the on-disk checksum. + Checksum m_checksum; + + /// Only warn once of checksum mismatch. + llvm::once_flag m_checksum_once_flag; + // Keep the modification time that this file data is valid for llvm::sys::TimePoint<> m_mod_time; diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp index c427bb91f4643a..f6e59ce731a573 100644 --- a/lldb/source/Core/SourceManager.cpp +++ b/lldb/source/Core/SourceManager.cpp @@ -447,13 +447,14 @@ void SourceManager::FindLinesMatchingRegex(SupportFileSP support_file_sp, SourceManager::File::File(SupportFileSP support_file_sp, lldb::DebuggerSP debugger_sp) - : m_support_file_sp(std::make_shared<SupportFile>()), m_mod_time(), - m_debugger_wp(debugger_sp), m_target_wp(TargetSP()) { + : m_support_file_sp(std::make_shared<SupportFile>()), m_checksum(), + m_mod_time(), m_debugger_wp(debugger_sp), m_target_wp(TargetSP()) { CommonInitializer(support_file_sp, {}); } SourceManager::File::File(SupportFileSP support_file_sp, TargetSP target_sp) - : m_support_file_sp(std::make_shared<SupportFile>()), m_mod_time(), + : m_support_file_sp(std::make_shared<SupportFile>()), m_checksum(), + m_mod_time(), m_debugger_wp(target_sp ? target_sp->GetDebugger().shared_from_this() : DebuggerSP()), m_target_wp(target_sp) { @@ -532,9 +533,11 @@ void SourceManager::File::CommonInitializer(SupportFileSP support_file_sp, } // If the file exists, read in the data. - if (m_mod_time != llvm::sys::TimePoint<>()) + if (m_mod_time != llvm::sys::TimePoint<>()) { m_data_sp = FileSystem::Instance().CreateDataBuffer( m_support_file_sp->GetSpecOnly()); + m_checksum = llvm::MD5::hash(m_data_sp->GetData()); + } } void SourceManager::File::SetSupportFile(lldb::SupportFileSP support_file_sp) { @@ -835,14 +838,24 @@ SourceManager::FileSP SourceManager::SourceFileCache::FindSourceFile( return {}; } +static std::string toString(const Checksum &checksum) { + if (!checksum) + return ""; + return std::string(llvm::formatv("{0}", checksum.digest())); +} + void SourceManager::SourceFileCache::Dump(Stream &stream) const { - stream << "Modification time Lines Path\n"; - stream << "------------------- -------- --------------------------------\n"; + // clang-format off + stream << "Modification time MD5 Checksum (on-disk) MD5 Checksum (line table) Lines Path\n"; + stream << "------------------- -------------------------------- -------------------------------- -------- --------------------------------\n"; + // clang-format on for (auto &entry : m_file_cache) { if (!entry.second) continue; FileSP file = entry.second; - stream.Format("{0:%Y-%m-%d %H:%M:%S} {1,8:d} {2}\n", file->GetTimestamp(), + stream.Format("{0:%Y-%m-%d %H:%M:%S} {1,32} {2,32} {3,8:d} {4}\n", + file->GetTimestamp(), toString(file->GetChecksum()), + toString(file->GetSupportFile()->GetChecksum()), file->GetNumLines(), entry.first.GetPath()); } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits