Go to the documentation of this file.
17 #include "llvm/Support/CachePruning.h"
18 #include "llvm/Support/MemoryBuffer.h"
29 llvm::CachePruningPolicy policy;
35 policy.Interval = std::chrono::hours(1);
38 policy.MaxSizePercentageOfAvailableSpace =
42 pruneCache(path, policy);
50 auto add_buffer = [
this](
unsigned task, std::unique_ptr<llvm::MemoryBuffer> m) {
54 llvm::Expected<llvm::FileCache> cache_or_err =
55 llvm::localCache(
"LLDBModuleCache",
"lldb-module", path, add_buffer);
61 "failed to create lldb index cache directory: {0}");
65 std::unique_ptr<llvm::MemoryBuffer>
67 std::lock_guard<std::mutex> guard(
m_mutex);
69 const unsigned task = 1;
75 llvm::Expected<llvm::AddStreamFn> add_stream_or_err =
81 if (add_stream_or_err) {
82 llvm::AddStreamFn &add_stream = *add_stream_or_err;
94 "failed to get the cache add stream callback for key: {0}");
97 return std::unique_ptr<llvm::MemoryBuffer>();
101 llvm::ArrayRef<uint8_t> data) {
102 std::lock_guard<std::mutex> guard(
m_mutex);
103 const unsigned task = 2;
107 llvm::Expected<llvm::AddStreamFn> add_stream_or_err =
112 if (add_stream_or_err) {
113 llvm::AddStreamFn &add_stream = *add_stream_or_err;
122 llvm::Expected<std::unique_ptr<llvm::CachedFileStream>> file_or_err =
125 llvm::CachedFileStream *cfs = file_or_err->get();
126 cfs->OS->write((
const char *)data.data(), data.size());
131 "failed to get the cache file stream for key: {0}");
137 "failed to get the cache add stream callback for key: {0}");
145 filename += key.str();
153 if (!fs.
Exists(cache_file))
164 std::time_t mod_time = 0;
180 std::time_t mod_time = 0;
190 llvm::sys::toTimeT(objfile->
GetModule()->GetObjectModificationTime());
207 llvm::ArrayRef<uint8_t> uuid_bytes =
m_uuid->GetBytes();
209 encoder.AppendU8(uuid_bytes.size());
210 encoder.AppendData(uuid_bytes);
227 while (uint8_t sig_encoding = data.
GetU8(offset_ptr)) {
228 switch (sig_encoding) {
230 const uint8_t length = data.
GetU8(offset_ptr);
231 const uint8_t *bytes = (
const uint8_t *)data.
GetData(offset_ptr, length);
232 if (bytes !=
nullptr && length > 0)
277 size_t length_offset = encoder.GetByteSize();
278 encoder.AppendU32(0);
279 size_t strtab_offset = encoder.GetByteSize();
284 encoder.GetByteSize() - strtab_offset);
286 encoder.AppendCString(s.GetStringRef());
289 encoder.PutU32(length_offset, encoder.GetByteSize() - strtab_offset);
295 llvm::StringRef identifier((
const char *)data.
GetData(offset_ptr, 4), 4);
302 const char *bytes = (
const char *)data.
GetData(offset_ptr, length);
303 if (bytes ==
nullptr)
305 m_data = llvm::StringRef(bytes, length);
310 if (offset >=
m_data.size())
311 return llvm::StringRef();
312 return llvm::StringRef(
m_data.data() + offset);
static UUID fromData(const void *bytes, uint32_t num_bytes)
Creates a UUID from the data pointed to by the bytes argument.
bool Encode(DataEncoder &encoder)
static ModuleListProperties & GetGlobalModuleListProperties()
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
DataFileCache(llvm::StringRef path)
Create a data file cache in the directory path that is specified.
std::unique_ptr< llvm::MemoryBuffer > GetCachedData(llvm::StringRef key)
Get cached data from the cache directory for the specified key.
bool IsValid() const
Return true only if the CacheSignature is valid.
llvm::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_...
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
void SetPath(llvm::StringRef p)
Temporary helper for FileSystem change.
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.
uint32_t Add(ConstString s)
Add a string into the string table.
bool SetCachedData(llvm::StringRef key, llvm::ArrayRef< uint8_t > data)
Set cached data for the specified key.
Status RemoveCacheFile(llvm::StringRef key)
Remove the cache file associated with the key.
@ eSignatureObjectModTime
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
virtual UUID GetUUID()=0
Gets the UUID for this object file.
std::unique_ptr< llvm::MemoryBuffer > m_mem_buff_up
uint64_t GetLLDBIndexCacheMaxPercent()
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
std::vector< ConstString > m_strings
string(SUBSTRING ${p} 10 -1 pStripped) if($
size_t GetLength() const
Get the length in bytes of string value.
llvm::FileCache m_cache_callback
llvm::StringRef m_data
All of the strings in the string table are contained in m_data.
Status RemoveFile(const FileSpec &file_spec)
Remove a single file.
llvm::Optional< std::time_t > m_mod_time
Modification time of file on disk.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
FileSpec GetCacheFilePath(llvm::StringRef key)
Return the cache file that is associated with the key.
llvm::DenseMap< ConstString, uint32_t > m_string_to_offset
static FileSystem & Instance()
void AppendPathComponent(llvm::StringRef component)
A class that represents a running process on the host machine.
uint64_t GetLLDBIndexCacheMaxByteSize()
llvm::Optional< UUID > m_uuid
UUID of object file or module.
const llvm::sys::TimePoint & GetObjectModificationTime() const
static const llvm::StringRef kStringTableIdentifier("STAB")
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
uint64_t GetLLDBIndexCacheExpirationDays()
uint32_t m_next_offset
Skip one byte to start the string table off with an empty string.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
#define LLDB_LOG_ERROR(log, error,...)
const llvm::sys::TimePoint & GetModificationTime() const
llvm::StringRef Get(uint32_t offset) const