17#include "llvm/Support/CachePruning.h"
23 static llvm::CachePruningPolicy policy;
24 static llvm::once_flag once_flag;
26 llvm::call_once(once_flag, []() {
36 policy.Interval = std::chrono::hours(1);
39 policy.MaxSizePercentageOfAvailableSpace =
49 pruneCache(path, policy);
57 auto add_buffer = [
this](
unsigned task,
const llvm::Twine &moduleName,
58 std::unique_ptr<llvm::MemoryBuffer> m) {
62 llvm::Expected<llvm::FileCache> cache_or_err =
63 llvm::localCache(
"LLDBModuleCache",
"lldb-module", path, add_buffer);
69 "failed to create lldb index cache directory: {0}");
73std::unique_ptr<llvm::MemoryBuffer>
75 std::lock_guard<std::mutex> guard(
m_mutex);
77 const unsigned task = 1;
83 llvm::Expected<llvm::AddStreamFn> add_stream_or_err =
89 if (add_stream_or_err) {
90 llvm::AddStreamFn &add_stream = *add_stream_or_err;
102 "failed to get the cache add stream callback for key: {0}");
105 return std::unique_ptr<llvm::MemoryBuffer>();
109 llvm::ArrayRef<uint8_t> data) {
110 std::lock_guard<std::mutex> guard(
m_mutex);
111 const unsigned task = 2;
115 llvm::Expected<llvm::AddStreamFn> add_stream_or_err =
120 if (add_stream_or_err) {
121 llvm::AddStreamFn &add_stream = *add_stream_or_err;
130 llvm::Expected<std::unique_ptr<llvm::CachedFileStream>> file_or_err =
131 add_stream(task,
"");
133 llvm::CachedFileStream *cfs = file_or_err->get();
134 cfs->OS->write((
const char *)data.data(), data.size());
139 "failed to get the cache file stream for key: {0}");
145 "failed to get the cache add stream callback for key: {0}");
152 std::string filename(
"llvmcache-");
153 filename += key.str();
161 if (!fs.
Exists(cache_file))
172 std::time_t mod_time = 0;
188 std::time_t mod_time = 0;
198 llvm::sys::toTimeT(objfile->
GetModule()->GetObjectModificationTime());
215 llvm::ArrayRef<uint8_t> uuid_bytes =
m_uuid->GetBytes();
217 encoder.
AppendU8(uuid_bytes.size());
235 while (uint8_t sig_encoding = data.
GetU8(offset_ptr)) {
236 switch (sig_encoding) {
238 const uint8_t length = data.
GetU8(offset_ptr);
239 const uint8_t *bytes = (
const uint8_t *)data.
GetData(offset_ptr, length);
240 if (bytes !=
nullptr && length > 0)
241 m_uuid =
UUID(llvm::ArrayRef<uint8_t>(bytes, length));
244 uint32_t mod_time = data.
GetU32(offset_ptr);
249 uint32_t mod_time = data.
GetU32(offset_ptr);
303 llvm::StringRef identifier((
const char *)data.
GetData(offset_ptr, 4), 4);
306 const uint32_t length = data.
GetU32(offset_ptr);
310 const char *bytes = (
const char *)data.
GetData(offset_ptr, length);
311 if (bytes ==
nullptr)
313 m_data = llvm::StringRef(bytes, length);
318 if (offset >=
m_data.size())
319 return llvm::StringRef();
320 return llvm::StringRef(
m_data.data() + offset);
static const llvm::StringRef kStringTableIdentifier("STAB")
@ eSignatureObjectModTime
#define LLDB_LOG_ERROR(log, error,...)
bool Encode(DataEncoder &encoder)
std::vector< ConstString > m_strings
llvm::DenseMap< ConstString, uint32_t > m_string_to_offset
uint32_t Add(ConstString s)
Add a string into the string table.
uint32_t m_next_offset
Skip one byte to start the string table off with an empty string.
A uniqued constant string class.
size_t GetLength() const
Get the length in bytes of string value.
An binary data encoding class.
void AppendCString(llvm::StringRef data)
Append a C string to the end of the owned data.
void AppendU32(uint32_t value)
size_t GetByteSize() const
Get the number of bytes contained in this object.
uint32_t PutU32(uint32_t offset, uint32_t value)
void AppendU8(uint8_t value)
Append a unsigned integer to the end of the owned data.
void AppendData(llvm::StringRef data)
Append a bytes to the end of the owned data.
FileSpec GetCacheFilePath(llvm::StringRef key)
Return the cache file that is associated with the key.
std::unique_ptr< llvm::MemoryBuffer > GetCachedData(llvm::StringRef key)
Get cached data from the cache directory for the specified key.
bool SetCachedData(llvm::StringRef key, llvm::ArrayRef< uint8_t > data)
Set cached data for the specified key.
llvm::FileCache m_cache_callback
std::unique_ptr< llvm::MemoryBuffer > m_mem_buff_up
DataFileCache(llvm::StringRef path, llvm::CachePruningPolicy policy=DataFileCache::GetLLDBIndexCachePolicy())
Create a data file cache in the directory path that is specified, using the specified policy.
static llvm::CachePruningPolicy GetLLDBIndexCachePolicy()
Gets the default LLDB index cache policy, which is controlled by the "LLDBIndexCache" family of setti...
Status RemoveCacheFile(llvm::StringRef key)
Remove the cache file associated with the key.
void AppendPathComponent(llvm::StringRef component)
void SetPath(llvm::StringRef p)
Temporary helper for FileSystem change.
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
Status RemoveFile(const FileSpec &file_spec)
Remove a single file.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
uint64_t GetLLDBIndexCacheMaxByteSize()
uint64_t GetLLDBIndexCacheMaxPercent()
uint64_t GetLLDBIndexCacheExpirationDays()
static ModuleListProperties & GetGlobalModuleListProperties()
A class that describes an executable image and its associated object and symbol files.
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
const llvm::sys::TimePoint & GetObjectModificationTime() const
const llvm::sys::TimePoint & GetModificationTime() const
A plug-in interface definition class for object file parsers.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
virtual UUID GetUUID()=0
Gets the UUID for this object file.
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
llvm::StringRef m_data
All of the strings in the string table are contained in m_data.
llvm::StringRef Get(uint32_t offset) const
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
bool Encode(DataEncoder &encoder) const
Encode this object into a data encoder object.
bool IsValid() const
Return true only if the CacheSignature is valid.
std::optional< std::time_t > m_mod_time
Modification time of file on disk.
std::optional< std::time_t > m_obj_mod_time
If this describes a .o file with a BSD archive, the BSD archive's modification time will be in m_mod_...
std::optional< UUID > m_uuid
UUID of object file or module.