LLVM 18.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"
31#include "llvm/Object/BuildID.h"
35#include "llvm/Support/Errc.h"
36#include "llvm/Support/Error.h"
39#include "llvm/Support/Path.h"
41#include "llvm/Support/xxhash.h"
42
43#include <atomic>
44#include <thread>
45
46namespace llvm {
47
49
50static std::string uniqueKey(llvm::StringRef S) {
51 return utostr(xxh3_64bits(S));
52}
53
54// Returns a binary BuildID as a normalized hex string.
55// Uses lowercase for compatibility with common debuginfod servers.
56static std::string buildIDToString(BuildIDRef ID) {
57 return llvm::toHex(ID, /*LowerCase=*/true);
58}
59
62}
63
65 const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS");
66 if (DebuginfodUrlsEnv == nullptr)
68
69 SmallVector<StringRef> DebuginfodUrls;
70 StringRef(DebuginfodUrlsEnv).split(DebuginfodUrls, " ");
71 return DebuginfodUrls;
72}
73
74/// Finds a default local file caching directory for the debuginfod client,
75/// first checking DEBUGINFOD_CACHE_PATH.
77 if (const char *CacheDirectoryEnv = std::getenv("DEBUGINFOD_CACHE_PATH"))
78 return CacheDirectoryEnv;
79
80 SmallString<64> CacheDirectory;
81 if (!sys::path::cache_directory(CacheDirectory))
82 return createStringError(
83 errc::io_error, "Unable to determine appropriate cache directory.");
84 sys::path::append(CacheDirectory, "llvm-debuginfod", "client");
85 return std::string(CacheDirectory);
86}
87
88std::chrono::milliseconds getDefaultDebuginfodTimeout() {
89 long Timeout;
90 const char *DebuginfodTimeoutEnv = std::getenv("DEBUGINFOD_TIMEOUT");
91 if (DebuginfodTimeoutEnv &&
92 to_integer(StringRef(DebuginfodTimeoutEnv).trim(), Timeout, 10))
93 return std::chrono::milliseconds(Timeout * 1000);
94
95 return std::chrono::milliseconds(90 * 1000);
96}
97
98/// The following functions fetch a debuginfod artifact to a file in a local
99/// cache and return the cached file path. They first search the local cache,
100/// followed by the debuginfod servers.
101
103 StringRef SourceFilePath) {
104 SmallString<64> UrlPath;
105 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
106 buildIDToString(ID), "source",
107 sys::path::convert_to_slash(SourceFilePath));
108 return getCachedOrDownloadArtifact(uniqueKey(UrlPath), UrlPath);
109}
110
112 SmallString<64> UrlPath;
113 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
114 buildIDToString(ID), "executable");
115 return getCachedOrDownloadArtifact(uniqueKey(UrlPath), UrlPath);
116}
117
119 SmallString<64> UrlPath;
120 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
121 buildIDToString(ID), "debuginfo");
122 return getCachedOrDownloadArtifact(uniqueKey(UrlPath), UrlPath);
123}
124
125// General fetching function.
127 StringRef UrlPath) {
128 SmallString<10> CacheDir;
129
131 if (!CacheDirOrErr)
132 return CacheDirOrErr.takeError();
133 CacheDir = *CacheDirOrErr;
134
135 return getCachedOrDownloadArtifact(UniqueKey, UrlPath, CacheDir,
138}
139
140namespace {
141
142/// A simple handler which streams the returned data to a cache file. The cache
143/// file is only created if a 200 OK status is observed.
144class StreamedHTTPResponseHandler : public HTTPResponseHandler {
145 using CreateStreamFn =
146 std::function<Expected<std::unique_ptr<CachedFileStream>>()>;
147 CreateStreamFn CreateStream;
148 HTTPClient &Client;
149 std::unique_ptr<CachedFileStream> FileStream;
150
151public:
152 StreamedHTTPResponseHandler(CreateStreamFn CreateStream, HTTPClient &Client)
153 : CreateStream(CreateStream), Client(Client) {}
154 virtual ~StreamedHTTPResponseHandler() = default;
155
156 Error handleBodyChunk(StringRef BodyChunk) override;
157};
158
159} // namespace
160
161Error StreamedHTTPResponseHandler::handleBodyChunk(StringRef BodyChunk) {
162 if (!FileStream) {
163 unsigned Code = Client.responseCode();
164 if (Code && Code != 200)
165 return Error::success();
166 Expected<std::unique_ptr<CachedFileStream>> FileStreamOrError =
167 CreateStream();
168 if (!FileStreamOrError)
169 return FileStreamOrError.takeError();
170 FileStream = std::move(*FileStreamOrError);
171 }
172 *FileStream->OS << BodyChunk;
173 return Error::success();
174}
175
176// An over-accepting simplification of the HTTP RFC 7230 spec.
177static bool isHeader(StringRef S) {
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 if (!Line.empty() && Line.back() == '\r')
201 Line = Line.drop_back();
202 if (!isHeader(Line)) {
203 if (!all_of(Line, llvm::isSpace))
205 << "could not parse debuginfod header: " << Filename << ':'
206 << LineNumber << '\n';
207 continue;
208 }
209 Headers.emplace_back(Line);
210 }
211 return Headers;
212}
213
215 StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
216 ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout) {
217 SmallString<64> AbsCachedArtifactPath;
218 sys::path::append(AbsCachedArtifactPath, CacheDirectoryPath,
219 "llvmcache-" + UniqueKey);
220
221 Expected<FileCache> CacheOrErr =
222 localCache("Debuginfod-client", ".debuginfod-client", CacheDirectoryPath);
223 if (!CacheOrErr)
224 return CacheOrErr.takeError();
225
226 FileCache Cache = *CacheOrErr;
227 // We choose an arbitrary Task parameter as we do not make use of it.
228 unsigned Task = 0;
229 Expected<AddStreamFn> CacheAddStreamOrErr = Cache(Task, UniqueKey, "");
230 if (!CacheAddStreamOrErr)
231 return CacheAddStreamOrErr.takeError();
232 AddStreamFn &CacheAddStream = *CacheAddStreamOrErr;
233 if (!CacheAddStream)
234 return std::string(AbsCachedArtifactPath);
235 // The artifact was not found in the local cache, query the debuginfod
236 // servers.
239 "No working HTTP client is available.");
240
242 return createStringError(
244 "A working HTTP client is available, but it is not initialized. To "
245 "allow Debuginfod to make HTTP requests, call HTTPClient::initialize() "
246 "at the beginning of main.");
247
248 HTTPClient Client;
249 Client.setTimeout(Timeout);
250 for (StringRef ServerUrl : DebuginfodUrls) {
251 SmallString<64> ArtifactUrl;
252 sys::path::append(ArtifactUrl, sys::path::Style::posix, ServerUrl, UrlPath);
253
254 // Perform the HTTP request and if successful, write the response body to
255 // the cache.
256 {
257 StreamedHTTPResponseHandler Handler(
258 [&]() { return CacheAddStream(Task, ""); }, Client);
259 HTTPRequest Request(ArtifactUrl);
260 Request.Headers = getHeaders();
261 Error Err = Client.perform(Request, Handler);
262 if (Err)
263 return std::move(Err);
264
265 unsigned Code = Client.responseCode();
266 if (Code && Code != 200)
267 continue;
268 }
269
270 Expected<CachePruningPolicy> PruningPolicyOrErr =
271 parseCachePruningPolicy(std::getenv("DEBUGINFOD_CACHE_POLICY"));
272 if (!PruningPolicyOrErr)
273 return PruningPolicyOrErr.takeError();
274 pruneCache(CacheDirectoryPath, *PruningPolicyOrErr);
275
276 // Return the path to the artifact on disk.
277 return std::string(AbsCachedArtifactPath);
278 }
279
280 return createStringError(errc::argument_out_of_domain, "build id not found");
281}
282
284 : Message(Message.str()) {}
285
286void DebuginfodLog::push(const Twine &Message) {
287 push(DebuginfodLogEntry(Message));
288}
289
291 {
292 std::lock_guard<std::mutex> Guard(QueueMutex);
293 LogEntryQueue.push(Entry);
294 }
295 QueueCondition.notify_one();
296}
297
299 {
300 std::unique_lock<std::mutex> Guard(QueueMutex);
301 // Wait for messages to be pushed into the queue.
302 QueueCondition.wait(Guard, [&] { return !LogEntryQueue.empty(); });
303 }
304 std::lock_guard<std::mutex> Guard(QueueMutex);
305 if (!LogEntryQueue.size())
306 llvm_unreachable("Expected message in the queue.");
307
308 DebuginfodLogEntry Entry = LogEntryQueue.front();
309 LogEntryQueue.pop();
310 return Entry;
311}
312
314 DebuginfodLog &Log, ThreadPool &Pool,
315 double MinInterval)
316 : Log(Log), Pool(Pool), MinInterval(MinInterval) {
317 for (StringRef Path : PathsRef)
318 Paths.push_back(Path.str());
319}
320
322 std::lock_guard<sys::Mutex> Guard(UpdateMutex);
323 if (UpdateTimer.isRunning())
324 UpdateTimer.stopTimer();
325 UpdateTimer.clear();
326 for (const std::string &Path : Paths) {
327 Log.push("Updating binaries at path " + Path);
328 if (Error Err = findBinaries(Path))
329 return Err;
330 }
331 Log.push("Updated collection");
332 UpdateTimer.startTimer();
333 return Error::success();
334}
335
336Expected<bool> DebuginfodCollection::updateIfStale() {
337 if (!UpdateTimer.isRunning())
338 return false;
339 UpdateTimer.stopTimer();
340 double Time = UpdateTimer.getTotalTime().getWallTime();
341 UpdateTimer.startTimer();
342 if (Time < MinInterval)
343 return false;
344 if (Error Err = update())
345 return std::move(Err);
346 return true;
347}
348
350 while (true) {
351 if (Error Err = update())
352 return Err;
353 std::this_thread::sleep_for(Interval);
354 }
355 llvm_unreachable("updateForever loop should never end");
356}
357
358static bool hasELFMagic(StringRef FilePath) {
360 std::error_code EC = identify_magic(FilePath, Type);
361 if (EC)
362 return false;
363 switch (Type) {
364 case file_magic::elf:
369 return true;
370 default:
371 return false;
372 }
373}
374
375Error DebuginfodCollection::findBinaries(StringRef Path) {
376 std::error_code EC;
377 sys::fs::recursive_directory_iterator I(Twine(Path), EC), E;
378 std::mutex IteratorMutex;
379 ThreadPoolTaskGroup IteratorGroup(Pool);
380 for (unsigned WorkerIndex = 0; WorkerIndex < Pool.getThreadCount();
381 WorkerIndex++) {
382 IteratorGroup.async([&, this]() -> void {
383 std::string FilePath;
384 while (true) {
385 {
386 // Check if iteration is over or there is an error during iteration
387 std::lock_guard<std::mutex> Guard(IteratorMutex);
388 if (I == E || EC)
389 return;
390 // Grab a file path from the directory iterator and advance the
391 // iterator.
392 FilePath = I->path();
393 I.increment(EC);
394 }
395
396 // Inspect the file at this path to determine if it is debuginfo.
397 if (!hasELFMagic(FilePath))
398 continue;
399
400 Expected<object::OwningBinary<object::Binary>> BinOrErr =
401 object::createBinary(FilePath);
402
403 if (!BinOrErr) {
404 consumeError(BinOrErr.takeError());
405 continue;
406 }
407 object::Binary *Bin = std::move(BinOrErr.get().getBinary());
408 if (!Bin->isObject())
409 continue;
410
411 // TODO: Support non-ELF binaries
412 object::ELFObjectFileBase *Object =
413 dyn_cast<object::ELFObjectFileBase>(Bin);
414 if (!Object)
415 continue;
416
417 BuildIDRef ID = getBuildID(Object);
418 if (ID.empty())
419 continue;
420
421 std::string IDString = buildIDToString(ID);
422 if (Object->hasDebugInfo()) {
423 std::lock_guard<sys::RWMutex> DebugBinariesGuard(DebugBinariesMutex);
424 (void)DebugBinaries.try_emplace(IDString, std::move(FilePath));
425 } else {
426 std::lock_guard<sys::RWMutex> BinariesGuard(BinariesMutex);
427 (void)Binaries.try_emplace(IDString, std::move(FilePath));
428 }
429 }
430 });
431 }
432 IteratorGroup.wait();
433 std::unique_lock<std::mutex> Guard(IteratorMutex);
434 if (EC)
435 return errorCodeToError(EC);
436 return Error::success();
437}
438
439Expected<std::optional<std::string>>
440DebuginfodCollection::getBinaryPath(BuildIDRef ID) {
441 Log.push("getting binary path of ID " + buildIDToString(ID));
442 std::shared_lock<sys::RWMutex> Guard(BinariesMutex);
443 auto Loc = Binaries.find(buildIDToString(ID));
444 if (Loc != Binaries.end()) {
445 std::string Path = Loc->getValue();
446 return Path;
447 }
448 return std::nullopt;
449}
450
451Expected<std::optional<std::string>>
452DebuginfodCollection::getDebugBinaryPath(BuildIDRef ID) {
453 Log.push("getting debug binary path of ID " + buildIDToString(ID));
454 std::shared_lock<sys::RWMutex> Guard(DebugBinariesMutex);
455 auto Loc = DebugBinaries.find(buildIDToString(ID));
456 if (Loc != DebugBinaries.end()) {
457 std::string Path = Loc->getValue();
458 return Path;
459 }
460 return std::nullopt;
461}
462
464 {
465 // Check collection; perform on-demand update if stale.
466 Expected<std::optional<std::string>> PathOrErr = getBinaryPath(ID);
467 if (!PathOrErr)
468 return PathOrErr.takeError();
469 std::optional<std::string> Path = *PathOrErr;
470 if (!Path) {
471 Expected<bool> UpdatedOrErr = updateIfStale();
472 if (!UpdatedOrErr)
473 return UpdatedOrErr.takeError();
474 if (*UpdatedOrErr) {
475 // Try once more.
476 PathOrErr = getBinaryPath(ID);
477 if (!PathOrErr)
478 return PathOrErr.takeError();
479 Path = *PathOrErr;
480 }
481 }
482 if (Path)
483 return *Path;
484 }
485
486 // Try federation.
488 if (!PathOrErr)
489 consumeError(PathOrErr.takeError());
490
491 // Fall back to debug binary.
492 return findDebugBinaryPath(ID);
493}
494
496 // Check collection; perform on-demand update if stale.
497 Expected<std::optional<std::string>> PathOrErr = getDebugBinaryPath(ID);
498 if (!PathOrErr)
499 return PathOrErr.takeError();
500 std::optional<std::string> Path = *PathOrErr;
501 if (!Path) {
502 Expected<bool> UpdatedOrErr = updateIfStale();
503 if (!UpdatedOrErr)
504 return UpdatedOrErr.takeError();
505 if (*UpdatedOrErr) {
506 // Try once more.
507 PathOrErr = getBinaryPath(ID);
508 if (!PathOrErr)
509 return PathOrErr.takeError();
510 Path = *PathOrErr;
511 }
512 }
513 if (Path)
514 return *Path;
515
516 // Try federation.
518}
519
521 DebuginfodCollection &Collection)
522 : Log(Log), Collection(Collection) {
523 cantFail(
524 Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
525 Log.push("GET " + Request.UrlPath);
526 std::string IDString;
527 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
528 Request.setResponse(
529 {404, "text/plain", "Build ID is not a hex string\n"});
530 return;
531 }
532 object::BuildID ID(IDString.begin(), IDString.end());
534 if (Error Err = PathOrErr.takeError()) {
535 consumeError(std::move(Err));
536 Request.setResponse({404, "text/plain", "Build ID not found\n"});
537 return;
538 }
539 streamFile(Request, *PathOrErr);
540 }));
541 cantFail(
542 Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
543 Log.push("GET " + Request.UrlPath);
544 std::string IDString;
545 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
546 Request.setResponse(
547 {404, "text/plain", "Build ID is not a hex string\n"});
548 return;
549 }
550 object::BuildID ID(IDString.begin(), IDString.end());
551 Expected<std::string> PathOrErr = Collection.findBinaryPath(ID);
552 if (Error Err = PathOrErr.takeError()) {
553 consumeError(std::move(Err));
554 Request.setResponse({404, "text/plain", "Build ID not found\n"});
555 return;
556 }
557 streamFile(Request, *PathOrErr);
558 }));
559}
560
561} // 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.
std::string Name
This file contains the declarations of the HTTPClient library for issuing HTTP requests and handling ...
#define I(x, y, z)
Definition: MD5.cpp:58
if(VerifyEach)
This file contains some functions that are useful when dealing with strings.
Tracks a collection of debuginfod artifacts on the local filesystem.
Definition: Debuginfod.h:106
DebuginfodCollection(ArrayRef< StringRef > Paths, DebuginfodLog &Log, ThreadPool &Pool, double MinInterval)
Definition: Debuginfod.cpp:313
Expected< std::string > findBinaryPath(object::BuildIDRef)
Definition: Debuginfod.cpp:463
Error updateForever(std::chrono::milliseconds Interval)
Definition: Debuginfod.cpp:349
Expected< std::string > findDebugBinaryPath(object::BuildIDRef)
Definition: Debuginfod.cpp:495
DebuginfodLogEntry pop()
Definition: Debuginfod.cpp:298
void push(DebuginfodLogEntry Entry)
Definition: Debuginfod.cpp:290
Represents either an error or a value T.
Definition: ErrorOr.h:56
Lightweight error class with error context and mandatory checking.
Definition: Error.h:154
static ErrorSuccess success()
Create a success value.
Definition: Error.h:328
Tagged union holding either a T or a Error.
Definition: Error.h:468
Error takeError()
Take ownership of the stored error.
Definition: Error.h:595
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.
Definition: HTTPClient.cpp:143
static bool IsInitialized
Definition: HTTPClient.h:62
unsigned responseCode()
Returns the last received response code or zero if none.
Definition: HTTPClient.cpp:156
Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler)
Performs the Request, passing response data to the Handler.
Definition: HTTPClient.cpp:151
void setTimeout(std::chrono::milliseconds Timeout)
Sets the timeout for the entire request, in milliseconds.
Definition: HTTPClient.cpp:149
Error get(StringRef UrlPathPattern, HTTPRequestHandler Handler)
Registers a URL pattern routing rule.
Definition: HTTPServer.cpp:175
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
Definition: Interval.h:36
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)
Definition: SmallVector.h:941
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
iterator end()
Definition: StringMap.h:205
iterator find(StringRef Key)
Definition: StringMap.h:218
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
Definition: StringMap.h:341
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:704
A ThreadPool for asynchronous parallel execution on a defined number of threads.
Definition: ThreadPool.h:52
unsigned getThreadCount() const
Definition: ThreadPool.h:110
double getWallTime() const
Definition: Timer.h:43
bool isRunning() const
Check if the timer is currently running.
Definition: Timer.h:116
void stopTimer()
Stop the timer.
Definition: Timer.cpp:197
void clear()
Clear the timer state.
Definition: Timer.cpp:205
void startTimer()
Start the timer running.
Definition: Timer.cpp:190
TimeRecord getTotalTime() const
Return the duration for which this timer has been running.
Definition: Timer.h:133
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
static 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
BuildIDRef getBuildID(const ObjectFile *Obj)
Returns the build ID, if any, contained in the given object file.
Definition: BuildID.cpp:56
ArrayRef< uint8_t > BuildIDRef
A reference to a BuildID in binary form.
Definition: BuildID.h:28
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
NodeAddr< CodeNode * > Code
Definition: RDFGraph.h:388
bool cache_directory(SmallVectorImpl< char > &result)
Get the directory where installed packages should put their machine-local cache, e....
std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
Definition: Path.cpp:570
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:458
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Magic.cpp:33
static std::string uniqueKey(llvm::StringRef S)
Definition: Debuginfod.cpp:50
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:1727
Expected< std::string > getCachedOrDownloadExecutable(object::BuildIDRef ID)
Fetches an executable by searching the default local cache directory and server URLs.
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Definition: xxhash.cpp:397
static bool isHeader(StringRef S)
Definition: Debuginfod.cpp:177
SmallVector< StringRef > getDefaultDebuginfodUrls()
Finds default array of Debuginfod server URLs by checking DEBUGINFOD_URLS environment variable.
Definition: Debuginfod.cpp:64
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:42
Expected< std::string > getCachedOrDownloadDebuginfo(object::BuildIDRef ID)
Fetches a debug binary by searching the default local cache directory and server URLs.
static std::string buildIDToString(BuildIDRef ID)
Definition: Debuginfod.cpp:56
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:1238
@ argument_out_of_domain
Expected< std::string > getCachedOrDownloadArtifact(StringRef UniqueKey, StringRef UrlPath)
Fetches any debuginfod artifact using the default local cache directory and server URLs.
Definition: Debuginfod.cpp:126
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:743
Expected< std::string > getCachedOrDownloadSource(object::BuildIDRef ID, StringRef SourceFilePath)
Fetches a specified source file by searching the default local cache directory and server URLs.
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.
Definition: Debuginfod.cpp:88
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:103
static bool hasELFMagic(StringRef FilePath)
Definition: Debuginfod.cpp:358
bool streamFile(HTTPServerRequest &Request, StringRef FilePath)
Sets the response to stream the file at FilePath, if available, and otherwise an HTTP 404 error respo...
Definition: HTTPServer.cpp:37
static SmallVector< std::string, 0 > getHeaders()
Definition: Debuginfod.cpp:187
std::function< Expected< AddStreamFn >(unsigned Task, StringRef Key, const Twine &ModuleName)> FileCache
This is the type of a file cache.
Definition: Caching.h:58
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1035
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.
Definition: Debuginfod.cpp:60
Expected< std::string > getDefaultDebuginfodCacheDirectory()
Finds a default local file caching directory for the debuginfod client, first checking DEBUGINFOD_CAC...
Definition: Debuginfod.cpp:76
DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection)
Definition: Debuginfod.cpp:520
DebuginfodCollection & Collection
Definition: Debuginfod.h:140
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:20
@ elf_relocatable
ELF Relocatable object file.
Definition: Magic.h:26
@ elf_shared_object
ELF dynamically linked shared lib.
Definition: Magic.h:28
@ elf_executable
ELF Executable image.
Definition: Magic.h:27
@ elf_core
ELF core image.
Definition: Magic.h:29
@ elf
ELF Unknown type.
Definition: Magic.h:25