Go to the documentation of this file.
40 const char *DebuginfodUrlsEnv = std::getenv(
"DEBUGINFOD_URLS");
41 if (DebuginfodUrlsEnv ==
nullptr)
46 return DebuginfodUrls;
50 if (
const char *CacheDirectoryEnv = std::getenv(
"DEBUGINFOD_CACHE_PATH"))
51 return CacheDirectoryEnv;
56 errc::io_error,
"Unable to determine appropriate cache directory.");
58 return std::string(CacheDirectory);
63 const char *DebuginfodTimeoutEnv = std::getenv(
"DEBUGINFOD_TIMEOUT");
64 if (DebuginfodTimeoutEnv &&
65 to_integer(
StringRef(DebuginfodTimeoutEnv).trim(), Timeout, 10))
66 return std::chrono::milliseconds(Timeout * 1000);
68 return std::chrono::milliseconds(90 * 1000);
106 CacheDir = *CacheDirOrErr;
110 if (!DebuginfodUrlsOrErr)
122 class StreamedHTTPResponseHandler :
public HTTPResponseHandler {
123 using CreateStreamFn =
124 std::function<Expected<std::unique_ptr<CachedFileStream>>()>;
125 CreateStreamFn CreateStream;
127 std::unique_ptr<CachedFileStream> FileStream;
130 StreamedHTTPResponseHandler(CreateStreamFn CreateStream, HTTPClient &Client)
131 : CreateStream(CreateStream), Client(Client) {}
132 virtual ~StreamedHTTPResponseHandler() =
default;
134 Error handleBodyChunk(StringRef BodyChunk)
override;
139 Error StreamedHTTPResponseHandler::handleBodyChunk(StringRef BodyChunk) {
141 if (Client.responseCode() != 200)
143 Expected<std::unique_ptr<CachedFileStream>> FileStreamOrError =
145 if (!FileStreamOrError)
146 return FileStreamOrError.takeError();
147 FileStream =
std::move(*FileStreamOrError);
149 *FileStream->OS << BodyChunk;
158 "llvmcache-" + UniqueKey);
161 localCache(
"Debuginfod-client",
".debuginfod-client", CacheDirectoryPath);
169 if (!CacheAddStreamOrErr)
171 AddStreamFn &CacheAddStream = *CacheAddStreamOrErr;
173 return std::string(AbsCachedArtifactPath);
178 "No working HTTP client is available.");
183 "A working HTTP client is available, but it is not initialized. To "
184 "allow Debuginfod to make HTTP requests, call HTTPClient::initialize() "
185 "at the beginning of main.");
189 for (
StringRef ServerUrl : DebuginfodUrls) {
195 StreamedHTTPResponseHandler Handler([&]() {
return CacheAddStream(Task); },
206 return std::string(AbsCachedArtifactPath);
std::function< Expected< AddStreamFn >(unsigned Task, StringRef Key)> FileCache
This is the type of a file cache.
A reusable client that can perform HTTPRequests through a network socket.
This is an optimization pass for GlobalISel generic memory operations.
static std::string buildIDToString(BuildIDRef ID)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static bool IsInitialized
std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
std::function< Expected< std::unique_ptr< CachedFileStream > >(unsigned Task)> AddStreamFn
This type defines the callback to add a file that is generated on the fly.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
std::chrono::milliseconds getDefaultDebuginfodTimeout()
Finds a default timeout for debuginfod HTTP requests.
bool cache_directory(SmallVectorImpl< char > &result)
Get the directory where installed packages should put their machine-local cache, e....
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
static std::string uniqueKey(llvm::StringRef S)
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Expected< std::string > getCachedOrDownloadArtifact(StringRef UniqueKey, StringRef UrlPath)
Fetches any debuginfod artifact using the default local cache directory and server URLs.
Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler)
Performs the Request, passing response data to the Handler.
Expected< FileCache > localCache(Twine CacheNameRef, Twine TempFilePrefixRef, Twine CacheDirectoryPathRef, AddBufferFn AddBuffer=[](size_t Task, std::unique_ptr< MemoryBuffer > MB) { })
Create a local file system cache which uses the given cache name, temporary file prefix,...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
unsigned responseCode()
Returns the last received response code or zero if none.
static std::string toHex(uint64_t V)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
static bool isAvailable()
Returns true only if LLVM has been compiled with a working HTTPClient.
void setTimeout(std::chrono::milliseconds Timeout)
Sets the timeout for the entire request, in milliseconds.
Expected< std::string > getDefaultDebuginfodCacheDirectory()
Finds a default local file caching directory for the debuginfod client, first checking DEBUGINFOD_CAC...
Expected< std::string > getCachedOrDownloadExecutable(BuildIDRef ID)
Fetches an executable by searching the default local cache directory and server URLs.
StringRef - Represent a constant reference to a string, i.e.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
A stateless description of an outbound HTTP request.
Lightweight error class with error context and mandatory checking.
Expected< SmallVector< StringRef > > getDefaultDebuginfodUrls()
Finds default array of Debuginfod server URLs by checking DEBUGINFOD_URLS environment variable.
Error takeError()
Take ownership of the stored error.
Expected< std::string > getCachedOrDownloadSource(BuildIDRef ID, StringRef SourceFilePath)
Fetches a specified source file by searching the default local cache directory and server URLs.
Expected< std::string > getCachedOrDownloadDebuginfo(BuildIDRef ID)
Fetches a debug binary by searching the default local cache directory and server URLs.
uint64_t xxHash64(llvm::StringRef Data)