mirror of
https://github.com/intel/llvm.git
synced 2026-02-06 06:31:50 +08:00
[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.
This commit is contained in:
committed by
GitHub
parent
923a1c1fc3
commit
5e7f0dcd69
@@ -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"
|
||||
@@ -71,6 +72,8 @@ public:
|
||||
|
||||
llvm::sys::TimePoint<> GetTimestamp() const { return m_mod_time; }
|
||||
|
||||
const Checksum &GetChecksum() const { return m_checksum; }
|
||||
|
||||
protected:
|
||||
/// Set file and update modification time.
|
||||
void SetSupportFile(lldb::SupportFileSP support_file_sp);
|
||||
@@ -81,6 +84,9 @@ public:
|
||||
/// 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;
|
||||
|
||||
// Keep the modification time that this file data is valid for
|
||||
llvm::sys::TimePoint<> m_mod_time;
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user