diff options
Diffstat (limited to 'lldb/source/Core/DataFileCache.cpp')
| -rw-r--r-- | lldb/source/Core/DataFileCache.cpp | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp index 3f52b925ef46..b38adfda169a 100644 --- a/lldb/source/Core/DataFileCache.cpp +++ b/lldb/source/Core/DataFileCache.cpp @@ -12,22 +12,21 @@ #include "lldb/Host/FileSystem.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Utility/DataEncoder.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" -#include "lldb/Utility/Logging.h" #include "llvm/Support/CachePruning.h" #include "llvm/Support/MemoryBuffer.h" -using namespace llvm; using namespace lldb_private; -DataFileCache::DataFileCache(StringRef path) { +DataFileCache::DataFileCache(llvm::StringRef path) { m_cache_dir.SetPath(path); // Prune the cache based off of the LLDB settings each time we create a cache // object. ModuleListProperties &properties = ModuleList::GetGlobalModuleListProperties(); - CachePruningPolicy policy; + llvm::CachePruningPolicy policy; // Only scan once an hour. If we have lots of debug sessions we don't want // to scan this directory too often. A timestamp file is written to the // directory to ensure different processes don't scan the directory too often. @@ -52,19 +51,19 @@ DataFileCache::DataFileCache(StringRef path) { if (m_take_ownership) m_mem_buff_up = std::move(m); }; - Expected<FileCache> cache_or_err = + llvm::Expected<llvm::FileCache> cache_or_err = llvm::localCache("LLDBModuleCache", "lldb-module", path, add_buffer); if (cache_or_err) m_cache_callback = std::move(*cache_or_err); else { - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES)); + Log *log = GetLog(LLDBLog::Modules); LLDB_LOG_ERROR(log, cache_or_err.takeError(), "failed to create lldb index cache directory: {0}"); } } std::unique_ptr<llvm::MemoryBuffer> -DataFileCache::GetCachedData(StringRef key) { +DataFileCache::GetCachedData(llvm::StringRef key) { std::lock_guard<std::mutex> guard(m_mutex); const unsigned task = 1; @@ -73,13 +72,14 @@ DataFileCache::GetCachedData(StringRef key) { // call the "add_buffer" lambda function from the constructor which will in // turn take ownership of the member buffer that is passed to the callback and // put it into a member variable. - Expected<AddStreamFn> add_stream_or_err = m_cache_callback(task, key); + llvm::Expected<llvm::AddStreamFn> add_stream_or_err = + m_cache_callback(task, key); m_take_ownership = false; // At this point we either already called the "add_buffer" lambda with // the data or we haven't. We can tell if we got the cached data by checking // the add_stream function pointer value below. if (add_stream_or_err) { - AddStreamFn &add_stream = *add_stream_or_err; + llvm::AddStreamFn &add_stream = *add_stream_or_err; // If the "add_stream" is nullptr, then the data was cached and we already // called the "add_buffer" lambda. If it is valid, then if we were to call // the add_stream function it would cause a cache file to get generated @@ -89,7 +89,7 @@ DataFileCache::GetCachedData(StringRef key) { if (!add_stream) return std::move(m_mem_buff_up); } else { - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES)); + Log *log = GetLog(LLDBLog::Modules); LLDB_LOG_ERROR(log, add_stream_or_err.takeError(), "failed to get the cache add stream callback for key: {0}"); } @@ -97,18 +97,20 @@ DataFileCache::GetCachedData(StringRef key) { return std::unique_ptr<llvm::MemoryBuffer>(); } -bool DataFileCache::SetCachedData(StringRef key, llvm::ArrayRef<uint8_t> data) { +bool DataFileCache::SetCachedData(llvm::StringRef key, + llvm::ArrayRef<uint8_t> data) { std::lock_guard<std::mutex> guard(m_mutex); const unsigned task = 2; // If we call this function and the data is cached, it will call the // add_buffer lambda function from the constructor which will ignore the // data. - Expected<AddStreamFn> add_stream_or_err = m_cache_callback(task, key); + llvm::Expected<llvm::AddStreamFn> add_stream_or_err = + m_cache_callback(task, key); // If we reach this code then we either already called the callback with // the data or we haven't. We can tell if we had the cached data by checking // the CacheAddStream function pointer value below. if (add_stream_or_err) { - AddStreamFn &add_stream = *add_stream_or_err; + llvm::AddStreamFn &add_stream = *add_stream_or_err; // If the "add_stream" is nullptr, then the data was cached. If it is // valid, then if we call the add_stream function with a task it will // cause the file to get generated, but we only want to check if the data @@ -117,20 +119,20 @@ bool DataFileCache::SetCachedData(StringRef key, llvm::ArrayRef<uint8_t> data) { // provided, but we won't take ownership of the memory buffer as we just // want to write the data. if (add_stream) { - Expected<std::unique_ptr<CachedFileStream>> file_or_err = + llvm::Expected<std::unique_ptr<llvm::CachedFileStream>> file_or_err = add_stream(task); if (file_or_err) { - CachedFileStream *cfs = file_or_err->get(); + llvm::CachedFileStream *cfs = file_or_err->get(); cfs->OS->write((const char *)data.data(), data.size()); return true; } else { - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES)); + Log *log = GetLog(LLDBLog::Modules); LLDB_LOG_ERROR(log, file_or_err.takeError(), "failed to get the cache file stream for key: {0}"); } } } else { - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES)); + Log *log = GetLog(LLDBLog::Modules); LLDB_LOG_ERROR(log, add_stream_or_err.takeError(), "failed to get the cache add stream callback for key: {0}"); } @@ -197,21 +199,21 @@ enum SignatureEncoding { eSignatureEnd = 255u, }; -bool CacheSignature::Encode(DataEncoder &encoder) { +bool CacheSignature::Encode(DataEncoder &encoder) const { if (!IsValid()) return false; // Invalid signature, return false! - if (m_uuid.hasValue()) { + if (m_uuid) { llvm::ArrayRef<uint8_t> uuid_bytes = m_uuid->GetBytes(); encoder.AppendU8(eSignatureUUID); encoder.AppendU8(uuid_bytes.size()); encoder.AppendData(uuid_bytes); } - if (m_mod_time.hasValue()) { + if (m_mod_time) { encoder.AppendU8(eSignatureModTime); encoder.AppendU32(*m_mod_time); } - if (m_obj_mod_time.hasValue()) { + if (m_obj_mod_time) { encoder.AppendU8(eSignatureObjectModTime); encoder.AppendU32(*m_obj_mod_time); } @@ -219,7 +221,7 @@ bool CacheSignature::Encode(DataEncoder &encoder) { return true; } -bool CacheSignature::Decode(const DataExtractor &data, +bool CacheSignature::Decode(const lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { Clear(); while (uint8_t sig_encoding = data.GetU8(offset_ptr)) { @@ -238,10 +240,14 @@ bool CacheSignature::Decode(const DataExtractor &data, case eSignatureObjectModTime: { uint32_t mod_time = data.GetU32(offset_ptr); if (mod_time > 0) - m_mod_time = mod_time; + m_obj_mod_time = mod_time; } break; case eSignatureEnd: - return true; + // The definition of is valid changed to only be valid if the UUID is + // valid so make sure that if we attempt to decode an old cache file + // that we will fail to decode the cache file if the signature isn't + // considered valid. + return IsValid(); default: break; } @@ -284,7 +290,7 @@ bool ConstStringTable::Encode(DataEncoder &encoder) { return true; } -bool StringTableReader::Decode(const DataExtractor &data, +bool StringTableReader::Decode(const lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { llvm::StringRef identifier((const char *)data.GetData(offset_ptr, 4), 4); if (identifier != kStringTableIdentifier) @@ -296,12 +302,12 @@ bool StringTableReader::Decode(const DataExtractor &data, const char *bytes = (const char *)data.GetData(offset_ptr, length); if (bytes == nullptr) return false; - m_data = StringRef(bytes, length); + m_data = llvm::StringRef(bytes, length); return true; } -StringRef StringTableReader::Get(uint32_t offset) const { +llvm::StringRef StringTableReader::Get(uint32_t offset) const { if (offset >= m_data.size()) - return StringRef(); - return StringRef(m_data.data() + offset); + return llvm::StringRef(); + return llvm::StringRef(m_data.data() + offset); } |
