diff options
Diffstat (limited to 'llvm/lib/Debuginfod')
| -rw-r--r-- | llvm/lib/Debuginfod/Debuginfod.cpp | 51 | ||||
| -rw-r--r-- | llvm/lib/Debuginfod/HTTPServer.cpp | 23 |
2 files changed, 46 insertions, 28 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)); diff --git a/llvm/lib/Debuginfod/HTTPServer.cpp b/llvm/lib/Debuginfod/HTTPServer.cpp index 2ea923d5a734..a5e992254ead 100644 --- a/llvm/lib/Debuginfod/HTTPServer.cpp +++ b/llvm/lib/Debuginfod/HTTPServer.cpp @@ -28,6 +28,12 @@ using namespace llvm; +char HTTPServerError::ID = 0; + +HTTPServerError::HTTPServerError(const Twine &Msg) : Msg(Msg.str()) {} + +void HTTPServerError::log(raw_ostream &OS) const { OS << Msg; } + bool llvm::streamFile(HTTPServerRequest &Request, StringRef FilePath) { Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(FilePath); if (Error Err = FDOrErr.takeError()) { @@ -159,31 +165,34 @@ HTTPServer::HTTPServer() = default; HTTPServer::~HTTPServer() = default; void HTTPServerRequest::setResponse(HTTPResponse Response) { - llvm_unreachable("No HTTP server implementation available"); + llvm_unreachable("no httplib"); } void HTTPServerRequest::setResponse(StreamingHTTPResponse Response) { - llvm_unreachable("No HTTP server implementation available"); + llvm_unreachable("no httplib"); } Error HTTPServer::get(StringRef UrlPathPattern, HTTPRequestHandler Handler) { - llvm_unreachable("No HTTP server implementation available"); + // TODO(https://github.com/llvm/llvm-project/issues/63873) We would ideally + // return an error as well but that's going to require refactoring of error + // handling in DebuginfodServer. + return Error::success(); } Error HTTPServer::bind(unsigned ListenPort, const char *HostInterface) { - llvm_unreachable("No HTTP server implementation available"); + return make_error<HTTPServerError>("no httplib"); } Expected<unsigned> HTTPServer::bind(const char *HostInterface) { - llvm_unreachable("No HTTP server implementation available"); + return make_error<HTTPServerError>("no httplib"); } Error HTTPServer::listen() { - llvm_unreachable("No HTTP server implementation available"); + return make_error<HTTPServerError>("no httplib"); } void HTTPServer::stop() { - llvm_unreachable("No HTTP server implementation available"); + llvm_unreachable("no httplib"); } #endif // LLVM_ENABLE_HTTPLIB |
