aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Debuginfod/Debuginfod.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-07-26 19:03:47 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-07-26 19:04:23 +0000
commit7fa27ce4a07f19b07799a767fc29416f3b625afb (patch)
tree27825c83636c4de341eb09a74f49f5d38a15d165 /llvm/lib/Debuginfod/Debuginfod.cpp
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'llvm/lib/Debuginfod/Debuginfod.cpp')
-rw-r--r--llvm/lib/Debuginfod/Debuginfod.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index 026f118bbf5b..394f2b29aee6 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -55,7 +55,11 @@ static std::string buildIDToString(BuildIDRef ID) {
return llvm::toHex(ID, /*LowerCase=*/true);
}
-Expected<SmallVector<StringRef>> getDefaultDebuginfodUrls() {
+bool canUseDebuginfod() {
+ return HTTPClient::isAvailable() && !getDefaultDebuginfodUrls().empty();
+}
+
+SmallVector<StringRef> getDefaultDebuginfodUrls() {
const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS");
if (DebuginfodUrlsEnv == nullptr)
return SmallVector<StringRef>();
@@ -126,13 +130,8 @@ Expected<std::string> getCachedOrDownloadArtifact(StringRef UniqueKey,
return CacheDirOrErr.takeError();
CacheDir = *CacheDirOrErr;
- Expected<SmallVector<StringRef>> DebuginfodUrlsOrErr =
- getDefaultDebuginfodUrls();
- if (!DebuginfodUrlsOrErr)
- return DebuginfodUrlsOrErr.takeError();
- SmallVector<StringRef> &DebuginfodUrls = *DebuginfodUrlsOrErr;
return getCachedOrDownloadArtifact(UniqueKey, UrlPath, CacheDir,
- DebuginfodUrls,
+ getDefaultDebuginfodUrls(),
getDefaultDebuginfodTimeout());
}
@@ -159,7 +158,8 @@ public:
Error StreamedHTTPResponseHandler::handleBodyChunk(StringRef BodyChunk) {
if (!FileStream) {
- if (Client.responseCode() != 200)
+ unsigned Code = Client.responseCode();
+ if (Code && Code != 200)
return Error::success();
Expected<std::unique_ptr<CachedFileStream>> FileStreamOrError =
CreateStream();
@@ -251,16 +251,25 @@ Expected<std::string> getCachedOrDownloadArtifact(
// Perform the HTTP request and if successful, write the response body to
// the cache.
- StreamedHTTPResponseHandler Handler(
- [&]() { return CacheAddStream(Task, ""); }, Client);
- HTTPRequest Request(ArtifactUrl);
- Request.Headers = getHeaders();
- Error Err = Client.perform(Request, Handler);
- if (Err)
- return std::move(Err);
-
- if (Client.responseCode() != 200)
- continue;
+ {
+ StreamedHTTPResponseHandler Handler(
+ [&]() { return CacheAddStream(Task, ""); }, Client);
+ HTTPRequest Request(ArtifactUrl);
+ Request.Headers = getHeaders();
+ Error Err = Client.perform(Request, Handler);
+ if (Err)
+ return std::move(Err);
+
+ unsigned Code = Client.responseCode();
+ if (Code && Code != 200)
+ continue;
+ }
+
+ Expected<CachePruningPolicy> PruningPolicyOrErr =
+ parseCachePruningPolicy(std::getenv("DEBUGINFOD_CACHE_POLICY"));
+ if (!PruningPolicyOrErr)
+ return PruningPolicyOrErr.takeError();
+ pruneCache(CacheDirectoryPath, *PruningPolicyOrErr);
// Return the path to the artifact on disk.
return std::string(AbsCachedArtifactPath);
@@ -403,11 +412,11 @@ Error DebuginfodCollection::findBinaries(StringRef Path) {
if (!Object)
continue;
- std::optional<BuildIDRef> ID = getBuildID(Object);
- if (!ID)
+ BuildIDRef ID = getBuildID(Object);
+ if (ID.empty())
continue;
- std::string IDString = buildIDToString(*ID);
+ std::string IDString = buildIDToString(ID);
if (Object->hasDebugInfo()) {
std::lock_guard<sys::RWMutex> DebugBinariesGuard(DebugBinariesMutex);
(void)DebugBinaries.try_emplace(IDString, std::move(FilePath));