LLVM 23.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"
30#include "llvm/Object/BuildID.h"
34#include "llvm/Support/Errc.h"
35#include "llvm/Support/Error.h"
40#include "llvm/Support/Path.h"
42#include "llvm/Support/xxhash.h"
43
44#include <atomic>
45#include <optional>
46#include <thread>
47
48namespace llvm {
49
51
52namespace {
53std::optional<SmallVector<StringRef>> DebuginfodUrls;
54// Many Readers/Single Writer lock protecting the global debuginfod URL list.
55llvm::sys::RWMutex UrlsMutex;
56} // namespace
57
59 return utostr(xxh3_64bits(S));
60}
61
62// Returns a binary BuildID as a normalized hex string.
63// Uses lowercase for compatibility with common debuginfod servers.
64static std::string buildIDToString(BuildIDRef ID) {
65 return llvm::toHex(ID, /*LowerCase=*/true);
66}
67
71
73 std::shared_lock<llvm::sys::RWMutex> ReadGuard(UrlsMutex);
74 if (!DebuginfodUrls) {
75 // Only read from the environment variable if the user hasn't already
76 // set the value.
77 ReadGuard.unlock();
78 std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
79 DebuginfodUrls = SmallVector<StringRef>();
80 if (const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS")) {
81 StringRef(DebuginfodUrlsEnv)
82 .split(DebuginfodUrls.value(), " ", -1, false);
83 }
84 WriteGuard.unlock();
85 ReadGuard.lock();
86 }
87 return DebuginfodUrls.value();
88}
89
90// Set the default debuginfod URL list, override the environment variable.
92 std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
93 DebuginfodUrls = URLs;
94}
95
96/// Finds a default local file caching directory for the debuginfod client,
97/// first checking DEBUGINFOD_CACHE_PATH.
99 if (const char *CacheDirectoryEnv = std::getenv("DEBUGINFOD_CACHE_PATH"))
100 return CacheDirectoryEnv;
101
102 SmallString<64> CacheDirectory;
103 if (!sys::path::cache_directory(CacheDirectory))
104 return createStringError(
105 errc::io_error, "Unable to determine appropriate cache directory.");
106 sys::path::append(CacheDirectory, "llvm-debuginfod", "client");
107 return std::string(CacheDirectory);
108}
109
110std::chrono::milliseconds getDefaultDebuginfodTimeout() {
111 long Timeout;
112 const char *DebuginfodTimeoutEnv = std::getenv("DEBUGINFOD_TIMEOUT");
113 if (DebuginfodTimeoutEnv &&
114 to_integer(StringRef(DebuginfodTimeoutEnv).trim(), Timeout, 10))
115 return std::chrono::milliseconds(Timeout * 1000);
116
117 return std::chrono::milliseconds(90 * 1000);
118}
119
120/// The following functions fetch a debuginfod artifact to a file in a local
121/// cache and return the cached file path. They first search the local cache,
122/// followed by the debuginfod servers.
123
125 StringRef SourceFilePath) {
126 SmallString<64> UrlPath;
127 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
128 buildIDToString(ID), "source",
129 sys::path::convert_to_slash(SourceFilePath));
130 return std::string(UrlPath);
131}
132
134 StringRef SourceFilePath) {
135 std::string UrlPath = getDebuginfodSourceUrlPath(ID, SourceFilePath);
136 return getCachedOrDownloadArtifact(getDebuginfodCacheKey(UrlPath), UrlPath);
137}
138
140 SmallString<64> UrlPath;
141 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
142 buildIDToString(ID), "executable");
143 return std::string(UrlPath);
144}
145
150
152 SmallString<64> UrlPath;
153 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
154 buildIDToString(ID), "debuginfo");
155 return std::string(UrlPath);
156}
157
162
163// General fetching function.
165 StringRef UrlPath) {
166 SmallString<10> CacheDir;
167
169 if (!CacheDirOrErr)
170 return CacheDirOrErr.takeError();
171 CacheDir = *CacheDirOrErr;
172
173 return getCachedOrDownloadArtifact(UniqueKey, UrlPath, CacheDir,
176}
177
178// An over-accepting simplification of the HTTP RFC 7230 spec.
179static bool isHeader(StringRef S) {
180 StringRef Name;
182 std::tie(Name, Value) = S.split(':');
183 if (Name.empty() || Value.empty())
184 return false;
185 return all_of(Name, [](char C) { return llvm::isPrint(C) && C != ' '; }) &&
186 all_of(Value, [](char C) { return llvm::isPrint(C) || C == '\t'; });
187}
188
190 const char *Filename = getenv("DEBUGINFOD_HEADERS_FILE");
191 if (!Filename)
192 return {};
194 MemoryBuffer::getFile(Filename, /*IsText=*/true);
195 if (!HeadersFile)
196 return {};
197
199 uint64_t LineNumber = 0;
200 for (StringRef Line : llvm::split((*HeadersFile)->getBuffer(), '\n')) {
201 LineNumber++;
202 Line.consume_back("\r");
203 if (!isHeader(Line)) {
204 if (!all_of(Line, llvm::isSpace))
206 << "could not parse debuginfod header: " << Filename << ':'
207 << LineNumber << '\n';
208 continue;
209 }
210 Headers.emplace_back(Line);
211 }
212 return Headers;
213}
214
216 StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
217 ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout) {
218 SmallString<64> AbsCachedArtifactPath;
219 sys::path::append(AbsCachedArtifactPath, CacheDirectoryPath,
220 "llvmcache-" + UniqueKey);
221
222 Expected<FileCache> CacheOrErr =
223 localCache("Debuginfod-client", ".debuginfod-client", CacheDirectoryPath);
224 if (!CacheOrErr)
225 return CacheOrErr.takeError();
226
227 FileCache Cache = *CacheOrErr;
228 // We choose an arbitrary Task parameter as we do not make use of it.
229 unsigned Task = 0;
230 Expected<AddStreamFn> CacheAddStreamOrErr = Cache(Task, UniqueKey, "");
231 if (!CacheAddStreamOrErr)
232 return CacheAddStreamOrErr.takeError();
233 AddStreamFn &CacheAddStream = *CacheAddStreamOrErr;
234 if (!CacheAddStream)
235 return std::string(AbsCachedArtifactPath);
236 // The artifact was not found in the local cache, query the debuginfod
237 // servers.
240 "No working HTTP client is available.");
241
243 return createStringError(
245 "A working HTTP client is available, but it is not initialized. To "
246 "allow Debuginfod to make HTTP requests, call HTTPClient::initialize() "
247 "at the beginning of main.");
248
249 HTTPClient Client;
250 Client.setTimeout(Timeout);
251 for (StringRef ServerUrl : DebuginfodUrls) {
252 SmallString<64> ArtifactUrl;
253 sys::path::append(ArtifactUrl, sys::path::Style::posix, ServerUrl, UrlPath);
254
255 // Perform the HTTP request and if successful, write the response body to
256 // the cache.
257 {
259 [&]() { return CacheAddStream(Task, ""); }, Client);
260 HTTPRequest Request(ArtifactUrl);
261 Request.Headers = getHeaders();
262 Error Err = Client.perform(Request, Handler);
263 if (Err)
264 return std::move(Err);
265 if ((Err = Handler.commit()))
266 return std::move(Err);
267
268 unsigned Code = Client.responseCode();
269 if (Code && Code != 200)
270 continue;
271 }
272
273 Expected<CachePruningPolicy> PruningPolicyOrErr =
274 parseCachePruningPolicy(std::getenv("DEBUGINFOD_CACHE_POLICY"));
275 if (!PruningPolicyOrErr)
276 return PruningPolicyOrErr.takeError();
277 pruneCache(CacheDirectoryPath, *PruningPolicyOrErr);
278
279 // Return the path to the artifact on disk.
280 return std::string(AbsCachedArtifactPath);
281 }
282
283 return createStringError(errc::argument_out_of_domain, "build id not found");
284}
285
288
289void DebuginfodLog::push(const Twine &Message) {
290 push(DebuginfodLogEntry(Message));
291}
292
294 {
295 std::lock_guard<std::mutex> Guard(QueueMutex);
296 LogEntryQueue.push(Entry);
297 }
298 QueueCondition.notify_one();
299}
300
302 {
303 std::unique_lock<std::mutex> Guard(QueueMutex);
304 // Wait for messages to be pushed into the queue.
305 QueueCondition.wait(Guard, [&] { return !LogEntryQueue.empty(); });
306 }
307 std::lock_guard<std::mutex> Guard(QueueMutex);
308 if (!LogEntryQueue.size())
309 llvm_unreachable("Expected message in the queue.");
310
311 DebuginfodLogEntry Entry = LogEntryQueue.front();
312 LogEntryQueue.pop();
313 return Entry;
314}
315
317 DebuginfodLog &Log,
319 double MinInterval)
320 : Log(Log), Pool(Pool), MinInterval(MinInterval) {
321 for (StringRef Path : PathsRef)
322 Paths.push_back(Path.str());
323}
324
326 std::lock_guard<sys::Mutex> Guard(UpdateMutex);
327 if (UpdateTimer.isRunning())
328 UpdateTimer.stopTimer();
329 UpdateTimer.clear();
330 for (const std::string &Path : Paths) {
331 Log.push("Updating binaries at path " + Path);
332 if (Error Err = findBinaries(Path))
333 return Err;
334 }
335 Log.push("Updated collection");
336 UpdateTimer.startTimer();
337 return Error::success();
338}
339
340Expected<bool> DebuginfodCollection::updateIfStale() {
341 if (!UpdateTimer.isRunning())
342 return false;
343 UpdateTimer.stopTimer();
344 double Time = UpdateTimer.getTotalTime().getWallTime();
345 UpdateTimer.startTimer();
346 if (Time < MinInterval)
347 return false;
348 if (Error Err = update())
349 return std::move(Err);
350 return true;
351}
352
354 while (true) {
355 if (Error Err = update())
356 return Err;
357 std::this_thread::sleep_for(Interval);
358 }
359 llvm_unreachable("updateForever loop should never end");
360}
361
362static bool hasELFMagic(StringRef FilePath) {
364 std::error_code EC = identify_magic(FilePath, Type);
365 if (EC)
366 return false;
367 switch (Type) {
368 case file_magic::elf:
373 return true;
374 default:
375 return false;
376 }
377}
378
379Error DebuginfodCollection::findBinaries(StringRef Path) {
380 std::error_code EC;
381 sys::fs::recursive_directory_iterator I(Twine(Path), EC), E;
382 std::mutex IteratorMutex;
383 ThreadPoolTaskGroup IteratorGroup(Pool);
384 for (unsigned WorkerIndex = 0; WorkerIndex < Pool.getMaxConcurrency();
385 WorkerIndex++) {
386 IteratorGroup.async([&, this]() -> void {
387 std::string FilePath;
388 while (true) {
389 {
390 // Check if iteration is over or there is an error during iteration
391 std::lock_guard<std::mutex> Guard(IteratorMutex);
392 if (I == E || EC)
393 return;
394 // Grab a file path from the directory iterator and advance the
395 // iterator.
396 FilePath = I->path();
397 I.increment(EC);
398 }
399
400 // Inspect the file at this path to determine if it is debuginfo.
401 if (!hasELFMagic(FilePath))
402 continue;
403
404 Expected<object::OwningBinary<object::Binary>> BinOrErr =
405 object::createBinary(FilePath);
406
407 if (!BinOrErr) {
408 consumeError(BinOrErr.takeError());
409 continue;
410 }
411 object::Binary *Bin = std::move(BinOrErr.get().getBinary());
412 if (!Bin->isObject())
413 continue;
414
415 // TODO: Support non-ELF binaries
416 object::ELFObjectFileBase *Object =
418 if (!Object)
419 continue;
420
421 BuildIDRef ID = getBuildID(Object);
422 if (ID.empty())
423 continue;
424
425 std::string IDString = buildIDToString(ID);
426 if (Object->hasDebugInfo()) {
427 std::lock_guard<sys::RWMutex> DebugBinariesGuard(DebugBinariesMutex);
428 (void)DebugBinaries.try_emplace(IDString, std::move(FilePath));
429 } else {
430 std::lock_guard<sys::RWMutex> BinariesGuard(BinariesMutex);
431 (void)Binaries.try_emplace(IDString, std::move(FilePath));
432 }
433 }
434 });
435 }
436 IteratorGroup.wait();
437 std::unique_lock<std::mutex> Guard(IteratorMutex);
438 if (EC)
439 return errorCodeToError(EC);
440 return Error::success();
441}
442
444DebuginfodCollection::getBinaryPath(BuildIDRef ID) {
445 Log.push("getting binary path of ID " + buildIDToString(ID));
446 std::shared_lock<sys::RWMutex> Guard(BinariesMutex);
447 auto Loc = Binaries.find(buildIDToString(ID));
448 if (Loc != Binaries.end()) {
449 std::string Path = Loc->getValue();
450 return Path;
451 }
452 return std::nullopt;
453}
454
456DebuginfodCollection::getDebugBinaryPath(BuildIDRef ID) {
457 Log.push("getting debug binary path of ID " + buildIDToString(ID));
458 std::shared_lock<sys::RWMutex> Guard(DebugBinariesMutex);
459 auto Loc = DebugBinaries.find(buildIDToString(ID));
460 if (Loc != DebugBinaries.end()) {
461 std::string Path = Loc->getValue();
462 return Path;
463 }
464 return std::nullopt;
465}
466
468 {
469 // Check collection; perform on-demand update if stale.
470 Expected<std::optional<std::string>> PathOrErr = getBinaryPath(ID);
471 if (!PathOrErr)
472 return PathOrErr.takeError();
473 std::optional<std::string> Path = *PathOrErr;
474 if (!Path) {
475 Expected<bool> UpdatedOrErr = updateIfStale();
476 if (!UpdatedOrErr)
477 return UpdatedOrErr.takeError();
478 if (*UpdatedOrErr) {
479 // Try once more.
480 PathOrErr = getBinaryPath(ID);
481 if (!PathOrErr)
482 return PathOrErr.takeError();
483 Path = *PathOrErr;
484 }
485 }
486 if (Path)
487 return *Path;
488 }
489
490 // Try federation.
492 if (!PathOrErr)
493 consumeError(PathOrErr.takeError());
494
495 // Fall back to debug binary.
496 return findDebugBinaryPath(ID);
497}
498
500 // Check collection; perform on-demand update if stale.
501 Expected<std::optional<std::string>> PathOrErr = getDebugBinaryPath(ID);
502 if (!PathOrErr)
503 return PathOrErr.takeError();
504 std::optional<std::string> Path = *PathOrErr;
505 if (!Path) {
506 Expected<bool> UpdatedOrErr = updateIfStale();
507 if (!UpdatedOrErr)
508 return UpdatedOrErr.takeError();
509 if (*UpdatedOrErr) {
510 // Try once more.
511 PathOrErr = getBinaryPath(ID);
512 if (!PathOrErr)
513 return PathOrErr.takeError();
514 Path = *PathOrErr;
515 }
516 }
517 if (Path)
518 return *Path;
519
520 // Try federation.
522}
523
527 cantFail(
528 Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
529 Log.push("GET " + Request.UrlPath);
530 std::string IDString;
531 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
532 Request.setResponse(
533 {404, "text/plain", "Build ID is not a hex string\n"});
534 return;
535 }
536 object::BuildID ID(IDString.begin(), IDString.end());
537 Expected<std::string> PathOrErr = Collection.findDebugBinaryPath(ID);
538 if (Error Err = PathOrErr.takeError()) {
539 consumeError(std::move(Err));
540 Request.setResponse({404, "text/plain", "Build ID not found\n"});
541 return;
542 }
543 streamFile(Request, *PathOrErr);
544 }));
545 cantFail(
546 Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
547 Log.push("GET " + Request.UrlPath);
548 std::string IDString;
549 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
550 Request.setResponse(
551 {404, "text/plain", "Build ID is not a hex string\n"});
552 return;
553 }
554 object::BuildID ID(IDString.begin(), IDString.end());
555 Expected<std::string> PathOrErr = Collection.findBinaryPath(ID);
556 if (Error Err = PathOrErr.takeError()) {
557 consumeError(std::move(Err));
558 Request.setResponse({404, "text/plain", "Build ID not found\n"});
559 return;
560 }
561 streamFile(Request, *PathOrErr);
562 }));
563}
564
565} // namespace llvm
This file declares a library for handling Build IDs and using them to find debug info.
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.
ArrayRef - 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:53
static bool isAvailable()
Returns true only if LLVM has been compiled with a working HTTPClient.
static bool IsInitialized
Definition HTTPClient.h:62
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:730
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:85
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
SmallVector< uint8_t, 10 > BuildID
A build ID in binary form.
Definition BuildID.h:26
LLVM_ABI BuildIDRef getBuildID(const ObjectFile *Obj)
Returns the build ID, if any, contained in the given object file.
Definition BuildID.cpp:70
ArrayRef< uint8_t > BuildIDRef
A reference to a BuildID in binary form.
Definition BuildID.h:29
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:569
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:457
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
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
LLVM_ABI uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Definition xxhash.cpp:553
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:1328
@ 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.
LLVM_ABI bool pruneCache(StringRef Path, CachePruningPolicy Policy, const std::vector< std::unique_ptr< MemoryBuffer > > &Files={})
Peform pruning using the supplied policy, returns true if pruning occurred, i.e.
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.
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:30
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