LLVM 24.0.0git
Debuginfod.cpp
Go to the documentation of this file.
1//===-- llvm/Debuginfod/Debuginfod.cpp - Debuginfod client library --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10///
11/// This file contains several definitions for the debuginfod client and server.
12/// For the client, this file defines the fetchInfo function. For the server,
13/// this file defines the DebuginfodLogEntry and DebuginfodServer structs, as
14/// well as the DebuginfodLog, DebuginfodCollection classes. The fetchInfo
15/// function retrieves any of the three supported artifact types: (executable,
16/// debuginfo, source file) associated with a build-id from debuginfod servers.
17/// If a source file is to be fetched, its absolute path must be specified in
18/// the Description argument to fetchInfo. The DebuginfodLogEntry,
19/// DebuginfodLog, and DebuginfodCollection are used by the DebuginfodServer to
20/// scan the local filesystem for binaries and serve the debuginfod protocol.
21///
22//===----------------------------------------------------------------------===//
23
26#include "llvm/ADT/StringRef.h"
32#include "llvm/Object/BuildID.h"
36#include "llvm/Support/Errc.h"
37#include "llvm/Support/Error.h"
40#include "llvm/Support/Path.h"
42
43#include <optional>
44#include <thread>
45
46namespace llvm {
47
49
50namespace {
51std::optional<SmallVector<StringRef>> DebuginfodUrls;
52// Many Readers/Single Writer lock protecting the global debuginfod URL list.
53llvm::sys::RWMutex UrlsMutex;
54} // namespace
55
57 return utostr(xxh3_64bits(S));
58}
59
60// Returns a binary BuildID as a normalized hex string.
61// Uses lowercase for compatibility with common debuginfod servers.
62static std::string buildIDToString(BuildIDRef ID) {
63 return llvm::toHex(ID, /*LowerCase=*/true);
64}
65
69
71 std::shared_lock<llvm::sys::RWMutex> ReadGuard(UrlsMutex);
72 if (!DebuginfodUrls) {
73 // Only read from the environment variable if the user hasn't already
74 // set the value.
75 ReadGuard.unlock();
76 std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
77 DebuginfodUrls = SmallVector<StringRef>();
78 if (const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS")) {
79 StringRef(DebuginfodUrlsEnv)
80 .split(DebuginfodUrls.value(), " ", -1, false);
81 }
82 WriteGuard.unlock();
83 ReadGuard.lock();
84 }
85 return DebuginfodUrls.value();
86}
87
88// Set the default debuginfod URL list, override the environment variable.
90 std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
91 DebuginfodUrls = URLs;
92}
93
94/// Finds a default local file caching directory for the debuginfod client,
95/// first checking DEBUGINFOD_CACHE_PATH.
97 if (const char *CacheDirectoryEnv = std::getenv("DEBUGINFOD_CACHE_PATH"))
98 return CacheDirectoryEnv;
99
100 SmallString<64> CacheDirectory;
101 if (!sys::path::cache_directory(CacheDirectory))
102 return createStringError(
103 errc::io_error, "Unable to determine appropriate cache directory.");
104 sys::path::append(CacheDirectory, "llvm-debuginfod", "client");
105 return std::string(CacheDirectory);
106}
107
108std::chrono::milliseconds getDefaultDebuginfodTimeout() {
109 long Timeout;
110 const char *DebuginfodTimeoutEnv = std::getenv("DEBUGINFOD_TIMEOUT");
111 if (DebuginfodTimeoutEnv &&
112 to_integer(StringRef(DebuginfodTimeoutEnv).trim(), Timeout, 10))
113 return std::chrono::milliseconds(Timeout * 1000);
114
115 return std::chrono::milliseconds(90 * 1000);
116}
117
118/// The following functions fetch a debuginfod artifact to a file in a local
119/// cache and return the cached file path. They first search the local cache,
120/// followed by the debuginfod servers.
121
123 StringRef SourceFilePath) {
124 SmallString<64> UrlPath;
125 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
126 buildIDToString(ID), "source",
127 sys::path::convert_to_slash(SourceFilePath));
128 return std::string(UrlPath);
129}
130
132 StringRef SourceFilePath) {
133 std::string UrlPath = getDebuginfodSourceUrlPath(ID, SourceFilePath);
134 return getCachedOrDownloadArtifact(getDebuginfodCacheKey(UrlPath), UrlPath);
135}
136
138 SmallString<64> UrlPath;
139 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
140 buildIDToString(ID), "executable");
141 return std::string(UrlPath);
142}
143
148
150 SmallString<64> UrlPath;
151 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
152 buildIDToString(ID), "debuginfo");
153 return std::string(UrlPath);
154}
155
160
161// General fetching function.
163 StringRef UrlPath) {
164 SmallString<10> CacheDir;
165
167 if (!CacheDirOrErr)
168 return CacheDirOrErr.takeError();
169 CacheDir = *CacheDirOrErr;
170
171 return getCachedOrDownloadArtifact(UniqueKey, UrlPath, CacheDir,
174}
175
176// An over-accepting simplification of the HTTP RFC 7230 spec.
177static bool isHeader(StringRef S) {
178 StringRef Name;
180 std::tie(Name, Value) = S.split(':');
181 if (Name.empty() || Value.empty())
182 return false;
183 return all_of(Name, [](char C) { return llvm::isPrint(C) && C != ' '; }) &&
184 all_of(Value, [](char C) { return llvm::isPrint(C) || C == '\t'; });
185}
186
188 const char *Filename = getenv("DEBUGINFOD_HEADERS_FILE");
189 if (!Filename)
190 return {};
192 MemoryBuffer::getFile(Filename, /*IsText=*/true);
193 if (!HeadersFile)
194 return {};
195
197 uint64_t LineNumber = 0;
198 for (StringRef Line : llvm::split((*HeadersFile)->getBuffer(), '\n')) {
199 LineNumber++;
200 Line.consume_back("\r");
201 if (!isHeader(Line)) {
202 if (!all_of(Line, llvm::isSpace))
204 << "could not parse debuginfod header: " << Filename << ':'
205 << LineNumber << '\n';
206 continue;
207 }
208 Headers.emplace_back(Line);
209 }
210 return Headers;
211}
212
214 StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
215 ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout) {
216 SmallString<64> AbsCachedArtifactPath;
217 sys::path::append(AbsCachedArtifactPath, CacheDirectoryPath,
218 "llvmcache-" + UniqueKey);
219
220 Expected<FileCache> CacheOrErr =
221 localCache("Debuginfod-client", ".debuginfod-client", CacheDirectoryPath);
222 if (!CacheOrErr)
223 return CacheOrErr.takeError();
224
225 FileCache Cache = *CacheOrErr;
226 // We choose an arbitrary Task parameter as we do not make use of it.
227 unsigned Task = 0;
228 Expected<AddStreamFn> CacheAddStreamOrErr = Cache(Task, UniqueKey, "");
229 if (!CacheAddStreamOrErr)
230 return CacheAddStreamOrErr.takeError();
231 AddStreamFn &CacheAddStream = *CacheAddStreamOrErr;
232 if (!CacheAddStream)
233 return std::string(AbsCachedArtifactPath);
234 // The artifact was not found in the local cache, query the debuginfod
235 // servers.
238 "No working HTTP client is available.");
239
241 return createStringError(
243 "A working HTTP client is available, but it is not initialized. To "
244 "allow Debuginfod to make HTTP requests, call HTTPClient::initialize() "
245 "at the beginning of main.");
246
247 HTTPClient Client;
248 Client.setTimeout(Timeout);
249 for (StringRef ServerUrl : DebuginfodUrls) {
250 SmallString<64> ArtifactUrl;
251 sys::path::append(ArtifactUrl, sys::path::Style::posix, ServerUrl, UrlPath);
252
253 // Perform the HTTP request and if successful, write the response body to
254 // the cache.
255 {
257 [&]() { return CacheAddStream(Task, ""); }, Client);
258 HTTPRequest Request(ArtifactUrl);
259 Request.Headers = getHeaders();
260 Error Err = Client.perform(Request, Handler);
261 if (Err)
262 return std::move(Err);
263 if ((Err = Handler.commit()))
264 return std::move(Err);
265
266 unsigned Code = Client.responseCode();
267 if (Code && Code != 200)
268 continue;
269 }
270
271 Expected<CachePruningPolicy> PruningPolicyOrErr =
272 parseCachePruningPolicy(std::getenv("DEBUGINFOD_CACHE_POLICY"));
273 if (!PruningPolicyOrErr)
274 return PruningPolicyOrErr.takeError();
275
276 Expected<bool> PrunedOrErr =
277 pruneCache(CacheDirectoryPath, *PruningPolicyOrErr);
278 // Log the error but continue execution: failure to prune the cache is not
279 // fatal.
280 if (!PrunedOrErr)
282
283 // Return the path to the artifact on disk.
284 return std::string(AbsCachedArtifactPath);
285 }
286
287 return createStringError(errc::argument_out_of_domain, "build id not found");
288}
289
292
293void DebuginfodLog::push(const Twine &Message) {
294 push(DebuginfodLogEntry(Message));
295}
296
298 {
299 std::lock_guard<std::mutex> Guard(QueueMutex);
300 LogEntryQueue.push(Entry);
301 }
302 QueueCondition.notify_one();
303}
304
306 {
307 std::unique_lock<std::mutex> Guard(QueueMutex);
308 // Wait for messages to be pushed into the queue.
309 QueueCondition.wait(Guard, [&] { return !LogEntryQueue.empty(); });
310 }
311 std::lock_guard<std::mutex> Guard(QueueMutex);
312 if (!LogEntryQueue.size())
313 llvm_unreachable("Expected message in the queue.");
314
315 DebuginfodLogEntry Entry = LogEntryQueue.front();
316 LogEntryQueue.pop();
317 return Entry;
318}
319
321 DebuginfodLog &Log,
323 double MinInterval)
324 : Log(Log), Pool(Pool), MinInterval(MinInterval) {
325 for (StringRef Path : PathsRef)
326 Paths.push_back(Path.str());
327}
328
330 std::lock_guard<sys::Mutex> Guard(UpdateMutex);
331 if (UpdateTimer.isRunning())
332 UpdateTimer.stopTimer();
333 UpdateTimer.clear();
334 for (const std::string &Path : Paths) {
335 Log.push("Updating binaries at path " + Path);
336 if (Error Err = findBinaries(Path))
337 return Err;
338 }
339 Log.push("Updated collection");
340 UpdateTimer.startTimer();
341 return Error::success();
342}
343
344Expected<bool> DebuginfodCollection::updateIfStale() {
345 if (!UpdateTimer.isRunning())
346 return false;
347 UpdateTimer.stopTimer();
348 double Time = UpdateTimer.getTotalTime().getWallTime();
349 UpdateTimer.startTimer();
350 if (Time < MinInterval)
351 return false;
352 if (Error Err = update())
353 return std::move(Err);
354 return true;
355}
356
358 while (true) {
359 if (Error Err = update())
360 return Err;
361 std::this_thread::sleep_for(Interval);
362 }
363 llvm_unreachable("updateForever loop should never end");
364}
365
366static bool hasELFMagic(StringRef FilePath) {
368 std::error_code EC = identify_magic(FilePath, Type);
369 if (EC)
370 return false;
371 switch (Type) {
372 case file_magic::elf:
377 return true;
378 default:
379 return false;
380 }
381}
382
383Error DebuginfodCollection::findBinaries(StringRef Path) {
384 std::error_code EC;
385 sys::fs::recursive_directory_iterator I(Twine(Path), EC), E;
386 std::mutex IteratorMutex;
387 ThreadPoolTaskGroup IteratorGroup(Pool);
388 for (unsigned WorkerIndex = 0; WorkerIndex < Pool.getMaxConcurrency();
389 WorkerIndex++) {
390 IteratorGroup.async([&, this]() -> void {
391 std::string FilePath;
392 while (true) {
393 {
394 // Check if iteration is over or there is an error during iteration
395 std::lock_guard<std::mutex> Guard(IteratorMutex);
396 if (I == E || EC)
397 return;
398 // Grab a file path from the directory iterator and advance the
399 // iterator.
400 FilePath = I->path();
401 I.increment(EC);
402 }
403
404 // Inspect the file at this path to determine if it is debuginfo.
405 if (!hasELFMagic(FilePath))
406 continue;
407
408 Expected<object::OwningBinary<object::Binary>> BinOrErr =
409 object::createBinary(FilePath);
410
411 if (!BinOrErr) {
412 consumeError(BinOrErr.takeError());
413 continue;
414 }
415 object::Binary *Bin = std::move(BinOrErr.get().getBinary());
416 if (!Bin->isObject())
417 continue;
418
419 // TODO: Support non-ELF binaries
420 object::ELFObjectFileBase *Object =
422 if (!Object)
423 continue;
424
425 BuildIDRef ID = getBuildID(Object);
426 if (ID.empty())
427 continue;
428
429 std::string IDString = buildIDToString(ID);
430 if (Object->hasDebugInfo()) {
431 std::lock_guard<sys::RWMutex> DebugBinariesGuard(DebugBinariesMutex);
432 (void)DebugBinaries.try_emplace(IDString, std::move(FilePath));
433 } else {
434 std::lock_guard<sys::RWMutex> BinariesGuard(BinariesMutex);
435 (void)Binaries.try_emplace(IDString, std::move(FilePath));
436 }
437 }
438 });
439 }
440 IteratorGroup.wait();
441 std::unique_lock<std::mutex> Guard(IteratorMutex);
442 if (EC)
443 return errorCodeToError(EC);
444 return Error::success();
445}
446
448DebuginfodCollection::getBinaryPath(BuildIDRef ID) {
449 Log.push("getting binary path of ID " + buildIDToString(ID));
450 std::shared_lock<sys::RWMutex> Guard(BinariesMutex);
451 auto Loc = Binaries.find(buildIDToString(ID));
452 if (Loc != Binaries.end()) {
453 std::string Path = Loc->getValue();
454 return Path;
455 }
456 return std::nullopt;
457}
458
460DebuginfodCollection::getDebugBinaryPath(BuildIDRef ID) {
461 Log.push("getting debug binary path of ID " + buildIDToString(ID));
462 std::shared_lock<sys::RWMutex> Guard(DebugBinariesMutex);
463 auto Loc = DebugBinaries.find(buildIDToString(ID));
464 if (Loc != DebugBinaries.end()) {
465 std::string Path = Loc->getValue();
466 return Path;
467 }
468 return std::nullopt;
469}
470
472 {
473 // Check collection; perform on-demand update if stale.
474 Expected<std::optional<std::string>> PathOrErr = getBinaryPath(ID);
475 if (!PathOrErr)
476 return PathOrErr.takeError();
477 std::optional<std::string> Path = *PathOrErr;
478 if (!Path) {
479 Expected<bool> UpdatedOrErr = updateIfStale();
480 if (!UpdatedOrErr)
481 return UpdatedOrErr.takeError();
482 if (*UpdatedOrErr) {
483 // Try once more.
484 PathOrErr = getBinaryPath(ID);
485 if (!PathOrErr)
486 return PathOrErr.takeError();
487 Path = *PathOrErr;
488 }
489 }
490 if (Path)
491 return *Path;
492 }
493
494 // Try federation.
496 if (!PathOrErr)
497 consumeError(PathOrErr.takeError());
498
499 // Fall back to debug binary.
500 return findDebugBinaryPath(ID);
501}
502
504 // Check collection; perform on-demand update if stale.
505 Expected<std::optional<std::string>> PathOrErr = getDebugBinaryPath(ID);
506 if (!PathOrErr)
507 return PathOrErr.takeError();
508 std::optional<std::string> Path = *PathOrErr;
509 if (!Path) {
510 Expected<bool> UpdatedOrErr = updateIfStale();
511 if (!UpdatedOrErr)
512 return UpdatedOrErr.takeError();
513 if (*UpdatedOrErr) {
514 // Try once more.
515 PathOrErr = getBinaryPath(ID);
516 if (!PathOrErr)
517 return PathOrErr.takeError();
518 Path = *PathOrErr;
519 }
520 }
521 if (Path)
522 return *Path;
523
524 // Try federation.
526}
527
531 cantFail(
532 Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
533 Log.push("GET " + Request.UrlPath);
534 std::string IDString;
535 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
536 Request.setResponse(
537 {404, "text/plain", "Build ID is not a hex string\n"});
538 return;
539 }
540 object::BuildID ID(IDString.begin(), IDString.end());
541 Expected<std::string> PathOrErr = Collection.findDebugBinaryPath(ID);
542 if (Error Err = PathOrErr.takeError()) {
543 consumeError(std::move(Err));
544 Request.setResponse({404, "text/plain", "Build ID not found\n"});
545 return;
546 }
547 streamFile(Request, *PathOrErr);
548 }));
549 cantFail(
550 Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
551 Log.push("GET " + Request.UrlPath);
552 std::string IDString;
553 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
554 Request.setResponse(
555 {404, "text/plain", "Build ID is not a hex string\n"});
556 return;
557 }
558 object::BuildID ID(IDString.begin(), IDString.end());
559 Expected<std::string> PathOrErr = Collection.findBinaryPath(ID);
560 if (Error Err = PathOrErr.takeError()) {
561 consumeError(std::move(Err));
562 Request.setResponse({404, "text/plain", "Build ID not found\n"});
563 return;
564 }
565 streamFile(Request, *PathOrErr);
566 }));
567}
568
569} // namespace llvm
unsigned uint64_t
This file declares a library for handling Build IDs and using them to find debug info.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains several declarations for the debuginfod client and server.
This file contains the declarations of the HTTPClient library for issuing HTTP requests and handling ...
#define I(x, y, z)
Definition MD5.cpp:57
std::pair< uint64_t, uint64_t > Interval
static constexpr StringLiteral Filename
if(PassOpts->AAPipeline)
An HTTPResponseHandler that streams the response body to a CachedFileStream.
This file contains some functions that are useful when dealing with strings.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Tracks a collection of debuginfod artifacts on the local filesystem.
Definition Debuginfod.h:123
DebuginfodCollection(ArrayRef< StringRef > Paths, DebuginfodLog &Log, ThreadPoolInterface &Pool, double MinInterval)
Expected< std::string > findBinaryPath(object::BuildIDRef)
Error updateForever(std::chrono::milliseconds Interval)
Expected< std::string > findDebugBinaryPath(object::BuildIDRef)
DebuginfodLogEntry pop()
void push(DebuginfodLogEntry Entry)
Represents either an error or a value T.
Definition ErrorOr.h:56
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
A reusable client that can perform HTTPRequests through a network socket.
Definition HTTPClient.h:57
static bool isAvailable()
Returns true only if LLVM has been compiled with a working HTTPClient.
static bool IsInitialized
Definition HTTPClient.h:66
unsigned responseCode()
Returns the last received response code or zero if none.
Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler)
Performs the Request, passing response data to the Handler.
void setTimeout(std::chrono::milliseconds Timeout)
Sets the timeout for the entire request, in milliseconds.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A handler which streams the returned data to a CachedFileStream.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
This defines the abstract base interface for a ThreadPool allowing asynchronous parallel execution on...
Definition ThreadPool.h:51
virtual unsigned getMaxConcurrency() const =0
Returns the maximum number of worker this pool can eventually grow to.
double getWallTime() const
Definition Timer.h:45
bool isRunning() const
Check if the timer is currently running.
Definition Timer.h:125
LLVM_ABI void stopTimer()
Stop the timer.
Definition Timer.cpp:159
LLVM_ABI void startTimer()
Start the timer running.
Definition Timer.cpp:150
TimeRecord getTotalTime() const
Return the duration for which this timer has been running.
Definition Timer.h:145
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
static LLVM_ABI raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition WithColor.cpp:86
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
SmallVector< uint8_t, 10 > BuildID
A build ID in binary form.
Definition BuildID.h:27
LLVM_ABI BuildIDRef getBuildID(const ObjectFile *Obj)
Returns the build ID, if any, contained in the given object file.
Definition BuildID.cpp:71
ArrayRef< uint8_t > BuildIDRef
A reference to a BuildID in binary form.
Definition BuildID.h:30
LLVM_ABI Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
Definition Binary.cpp:45
LLVM_ABI bool cache_directory(SmallVectorImpl< char > &result)
Get the directory where installed packages should put their machine-local cache, e....
LLVM_ABI std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
Definition Path.cpp:585
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition Path.cpp:467
SmartRWMutex< false > RWMutex
Definition RWMutex.h:165
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition Magic.cpp:33
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition Error.cpp:61
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
Expected< std::string > getCachedOrDownloadExecutable(object::BuildIDRef ID)
Fetches an executable by searching the default local cache directory and server URLs.
std::string getDebuginfodCacheKey(StringRef UrlPath)
Returns the cache key for a given debuginfod URL path.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
Definition ArrayRef.h:558
static bool isHeader(StringRef S)
SmallVector< StringRef > getDefaultDebuginfodUrls()
Finds default array of Debuginfod server URLs by checking DEBUGINFOD_URLS environment variable.
std::string getDebuginfodSourceUrlPath(object::BuildIDRef ID, StringRef SourceFilePath)
Get the full URL path for a source request of a given BuildID and file path.
Expected< std::string > getCachedOrDownloadDebuginfo(object::BuildIDRef ID)
Fetches a debug binary by searching the default local cache directory and server URLs.
std::string utostr(uint64_t X, bool isNeg=false)
static std::string buildIDToString(BuildIDRef ID)
std::string getDebuginfodExecutableUrlPath(object::BuildIDRef ID)
Get the full URL path for an executable request of a given BuildID.
LLVM_ABI Expected< CachePruningPolicy > parseCachePruningPolicy(StringRef PolicyStr)
Parse the given string as a cache pruning policy.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
@ argument_out_of_domain
Definition Errc.h:37
@ io_error
Definition Errc.h:58
Expected< std::string > getCachedOrDownloadArtifact(StringRef UniqueKey, StringRef UrlPath)
Fetches any debuginfod artifact using the default local cache directory and server URLs.
std::string getDebuginfodDebuginfoUrlPath(object::BuildIDRef ID)
Get the full URL path for a debug binary request of a given BuildID.
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Timeout
Reached timeout while waiting for the owner to release the lock.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
Expected< std::string > getCachedOrDownloadSource(object::BuildIDRef ID, StringRef SourceFilePath)
Fetches a specified source file by searching the default local cache directory and server URLs.
std::chrono::milliseconds getDefaultDebuginfodTimeout()
Finds a default timeout for debuginfod HTTP requests.
void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...
bool isPrint(char C)
Checks whether character C is printable.
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition Error.cpp:107
static bool hasELFMagic(StringRef FilePath)
bool streamFile(HTTPServerRequest &Request, StringRef FilePath)
Sets the response to stream the file at FilePath, if available, and otherwise an HTTP 404 error respo...
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
static SmallVector< std::string, 0 > getHeaders()
void setDefaultDebuginfodUrls(const SmallVector< StringRef > &URLs)
Sets the list of debuginfod server URLs to query.
LLVM_ABI Expected< bool > pruneCache(StringRef Path, CachePruningPolicy Policy, const std::vector< std::unique_ptr< MemoryBuffer > > &Files={})
Perform pruning using the supplied policy, returns true if pruning occurred, i.e.
std::function< Expected< std::unique_ptr< CachedFileStream > >( unsigned Task, const Twine &ModuleName)> AddStreamFn
This type defines the callback to add a file that is generated on the fly.
Definition Caching.h:58
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106
LLVM_ABI Expected< FileCache > localCache(const Twine &CacheNameRef, const Twine &TempFilePrefixRef, const Twine &CacheDirectoryPathRef, AddBufferFn AddBuffer=[](size_t Task, const Twine &ModuleName, std::unique_ptr< MemoryBuffer > MB) {})
Create a local file system cache which uses the given cache name, temporary file prefix,...
Definition Caching.cpp:29
bool canUseDebuginfod()
Returns false if a debuginfod lookup can be determined to have no chance of succeeding.
Expected< std::string > getDefaultDebuginfodCacheDirectory()
Finds a default local file caching directory for the debuginfod client, first checking DEBUGINFOD_CAC...
DebuginfodLog & Log
Definition Debuginfod.h:156
DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection)
DebuginfodCollection & Collection
Definition Debuginfod.h:157
This type represents a file cache system that manages caching of files.
Definition Caching.h:84
A stateless description of an outbound HTTP request.
Definition HTTPClient.h:31
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
Definition Magic.h:21
@ elf_relocatable
ELF Relocatable object file.
Definition Magic.h:28
@ elf_shared_object
ELF dynamically linked shared lib.
Definition Magic.h:30
@ elf_executable
ELF Executable image.
Definition Magic.h:29
@ elf_core
ELF core image.
Definition Magic.h:31
@ elf
ELF Unknown type.
Definition Magic.h:27