Skip to content

Commit 7b808e7

Browse files
author
George Hu
committed
[lldb] Switch debuginfod cache to use lldb index cache settings
1 parent 6923737 commit 7b808e7

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "SymbolLocatorDebuginfod.h"
1010

11+
#include "lldb/Core/DataFileCache.h"
1112
#include "lldb/Core/PluginManager.h"
1213
#include "lldb/Interpreter/OptionValueString.h"
1314
#include "lldb/Utility/Args.h"
@@ -173,11 +174,14 @@ GetFileForModule(const ModuleSpec &module_spec,
173174
// Grab LLDB's Debuginfod overrides from the
174175
// plugin.symbol-locator.debuginfod.* settings.
175176
PluginProperties &plugin_props = GetGlobalPluginProperties();
176-
llvm::Expected<std::string> cache_path_or_err = plugin_props.GetCachePath();
177-
// A cache location is *required*.
178-
if (!cache_path_or_err)
179-
return {};
180-
std::string cache_path = *cache_path_or_err;
177+
// Grab the lldb index cache settings from the global module list properties.
178+
ModuleListProperties &properties =
179+
ModuleList::GetGlobalModuleListProperties();
180+
std::string cache_path = properties.GetLLDBIndexCachePath().GetPath();
181+
182+
llvm::CachePruningPolicy pruning_policy =
183+
DataFileCache::GetLLDBIndexCachePolicy();
184+
181185
llvm::SmallVector<llvm::StringRef> debuginfod_urls =
182186
llvm::getDefaultDebuginfodUrls();
183187
std::chrono::milliseconds timeout = plugin_props.GetTimeout();
@@ -191,7 +195,8 @@ GetFileForModule(const ModuleSpec &module_spec,
191195
cache_file_name += "-" + file_name.str();
192196
}
193197
llvm::Expected<std::string> result = llvm::getCachedOrDownloadArtifact(
194-
cache_file_name, url_path, cache_path, debuginfod_urls, timeout);
198+
cache_file_name, url_path, cache_path, debuginfod_urls, timeout,
199+
pruning_policy);
195200
if (result)
196201
return FileSpec(*result);
197202

llvm/include/llvm/Debuginfod/Debuginfod.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/StringMap.h"
2626
#include "llvm/ADT/StringRef.h"
2727
#include "llvm/Object/BuildID.h"
28+
#include "llvm/Support/CachePruning.h"
2829
#include "llvm/Support/Error.h"
2930
#include "llvm/Support/MemoryBuffer.h"
3031
#include "llvm/Support/Mutex.h"
@@ -95,7 +96,8 @@ Expected<std::string> getCachedOrDownloadArtifact(StringRef UniqueKey,
9596
/// found, uses the UniqueKey for the local cache file.
9697
Expected<std::string> getCachedOrDownloadArtifact(
9798
StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
98-
ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout);
99+
ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout,
100+
llvm::CachePruningPolicy policy);
99101

100102
class ThreadPoolInterface;
101103

llvm/lib/Debuginfod/Debuginfod.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ Expected<std::string> getDefaultDebuginfodCacheDirectory() {
106106
return std::string(CacheDirectory);
107107
}
108108

109+
Expected<llvm::CachePruningPolicy> getDefaultDebuginfodCachePruningPolicy() {
110+
Expected<CachePruningPolicy> PruningPolicyOrErr =
111+
parseCachePruningPolicy(std::getenv("DEBUGINFOD_CACHE_POLICY"));
112+
if (!PruningPolicyOrErr)
113+
return PruningPolicyOrErr.takeError();
114+
return *PruningPolicyOrErr;
115+
}
116+
109117
std::chrono::milliseconds getDefaultDebuginfodTimeout() {
110118
long Timeout;
111119
const char *DebuginfodTimeoutEnv = std::getenv("DEBUGINFOD_TIMEOUT");
@@ -169,9 +177,15 @@ Expected<std::string> getCachedOrDownloadArtifact(StringRef UniqueKey,
169177
return CacheDirOrErr.takeError();
170178
CacheDir = *CacheDirOrErr;
171179

172-
return getCachedOrDownloadArtifact(UniqueKey, UrlPath, CacheDir,
173-
getDefaultDebuginfodUrls(),
174-
getDefaultDebuginfodTimeout());
180+
Expected<llvm::CachePruningPolicy> PruningPolicyOrErr =
181+
getDefaultDebuginfodCachePruningPolicy();
182+
if (!PruningPolicyOrErr)
183+
return PruningPolicyOrErr.takeError();
184+
llvm::CachePruningPolicy PruningPolicy = *PruningPolicyOrErr;
185+
186+
return getCachedOrDownloadArtifact(
187+
UniqueKey, UrlPath, CacheDir, getDefaultDebuginfodUrls(),
188+
getDefaultDebuginfodTimeout(), PruningPolicy);
175189
}
176190

177191
namespace {
@@ -250,7 +264,8 @@ static SmallVector<std::string, 0> getHeaders() {
250264

251265
Expected<std::string> getCachedOrDownloadArtifact(
252266
StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
253-
ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout) {
267+
ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout,
268+
llvm::CachePruningPolicy policy) {
254269
SmallString<64> AbsCachedArtifactPath;
255270
sys::path::append(AbsCachedArtifactPath, CacheDirectoryPath,
256271
"llvmcache-" + UniqueKey);
@@ -304,11 +319,7 @@ Expected<std::string> getCachedOrDownloadArtifact(
304319
continue;
305320
}
306321

307-
Expected<CachePruningPolicy> PruningPolicyOrErr =
308-
parseCachePruningPolicy(std::getenv("DEBUGINFOD_CACHE_POLICY"));
309-
if (!PruningPolicyOrErr)
310-
return PruningPolicyOrErr.takeError();
311-
pruneCache(CacheDirectoryPath, *PruningPolicyOrErr);
322+
pruneCache(CacheDirectoryPath, policy);
312323

313324
// Return the path to the artifact on disk.
314325
return std::string(AbsCachedArtifactPath);

llvm/unittests/Debuginfod/DebuginfodTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ TEST(DebuginfodClient, CacheHit) {
3737
sys::fs::createTemporaryFile("llvmcache-key", "temp", FD, CachedFilePath);
3838
StringRef CacheDir = sys::path::parent_path(CachedFilePath);
3939
StringRef UniqueKey = sys::path::filename(CachedFilePath);
40+
llvm::CachePruningPolicy policy;
4041
EXPECT_TRUE(UniqueKey.consume_front("llvmcache-"));
4142
raw_fd_ostream OF(FD, true, /*unbuffered=*/true);
4243
OF << "contents\n";
4344
OF << CacheDir << "\n";
4445
OF.close();
4546
Expected<std::string> PathOrErr = getCachedOrDownloadArtifact(
4647
UniqueKey, /*UrlPath=*/"/null", CacheDir,
47-
/*DebuginfodUrls=*/{}, /*Timeout=*/std::chrono::milliseconds(1));
48+
/*DebuginfodUrls=*/{}, /*Timeout=*/std::chrono::milliseconds(1), policy);
4849
EXPECT_THAT_EXPECTED(PathOrErr, HasValue(CachedFilePath));
4950
}
5051

0 commit comments

Comments
 (0)