LLVM 22.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 <optional>
45#include <thread>
46
47namespace llvm {
48
50
51namespace {
52std::optional<SmallVector<StringRef>> DebuginfodUrls;
53// Many Readers/Single Writer lock protecting the global debuginfod URL list.
54llvm::sys::RWMutex UrlsMutex;
55} // namespace
56
58 return utostr(xxh3_64bits(S));
59}
60
61// Returns a binary BuildID as a normalized hex string.
62// Uses lowercase for compatibility with common debuginfod servers.
63static std::string buildIDToString(BuildIDRef ID) {
64 return llvm::toHex(ID, /*LowerCase=*/true);
65}
66
69}
70
72 std::shared_lock<llvm::sys::RWMutex> ReadGuard(UrlsMutex);
73 if (!DebuginfodUrls) {
74 // Only read from the environment variable if the user hasn't already
75 // set the value.
76 ReadGuard.unlock();
77 std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
78 DebuginfodUrls = SmallVector<StringRef>();
79 if (const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS")) {
80 StringRef(DebuginfodUrlsEnv)
81 .split(DebuginfodUrls.value(), " ", -1, false);
82 }
83 WriteGuard.unlock();
84 ReadGuard.lock();
85 }
86 return DebuginfodUrls.value();
87}
88
89// Set the default debuginfod URL list, override the environment variable.
91 std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
92 DebuginfodUrls = URLs;
93}
94
95/// Finds a default local file caching directory for the debuginfod client,
96/// first checking DEBUGINFOD_CACHE_PATH.
98 if (const char *CacheDirectoryEnv = std::getenv("DEBUGINFOD_CACHE_PATH"))
99 return CacheDirectoryEnv;
100
101 SmallString<64> CacheDirectory;
102 if (!sys::path::cache_directory(CacheDirectory))
103 return createStringError(
104 errc::io_error, "Unable to determine appropriate cache directory.");
105 sys::path::append(CacheDirectory, "llvm-debuginfod", "client");
106 return std::string(CacheDirectory);
107}
108
109std::chrono::milliseconds getDefaultDebuginfodTimeout() {
110 long Timeout;
111 const char *DebuginfodTimeoutEnv = std::getenv("DEBUGINFOD_TIMEOUT");
112 if (DebuginfodTimeoutEnv &&
113 to_integer(StringRef(DebuginfodTimeoutEnv).trim(), Timeout, 10))
114 return std::chrono::milliseconds(Timeout * 1000);
115
116 return std::chrono::milliseconds(90 * 1000);
117}
118
119/// The following functions fetch a debuginfod artifact to a file in a local
120/// cache and return the cached file path. They first search the local cache,
121/// followed by the debuginfod servers.
122
123std::string getDebuginfodSourceUrlPath(BuildIDRef ID,
124 StringRef SourceFilePath) {
125 SmallString<64> UrlPath;
126 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
127 buildIDToString(ID), "source",
128 sys::path::convert_to_slash(SourceFilePath));
129 return std::string(UrlPath);
130}
131
133 StringRef SourceFilePath) {
134 std::string UrlPath = getDebuginfodSourceUrlPath(ID, SourceFilePath);
135 return getCachedOrDownloadArtifact(getDebuginfodCacheKey(UrlPath), UrlPath);
136}
137
138std::string getDebuginfodExecutableUrlPath(BuildIDRef ID) {
139 SmallString<64> UrlPath;
140 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
141 buildIDToString(ID), "executable");
142 return std::string(UrlPath);
143}
144
146 std::string UrlPath = getDebuginfodExecutableUrlPath(ID);
147 return getCachedOrDownloadArtifact(getDebuginfodCacheKey(UrlPath), UrlPath);
148}
149
150std::string getDebuginfodDebuginfoUrlPath(BuildIDRef ID) {
151 SmallString<64> UrlPath;
152 sys::path::append(UrlPath, sys::path::Style::posix, "buildid",
153 buildIDToString(ID), "debuginfo");
154 return std::string(UrlPath);
155}
156
158 std::string UrlPath = getDebuginfodDebuginfoUrlPath(ID);
159 return getCachedOrDownloadArtifact(getDebuginfodCacheKey(UrlPath), UrlPath);
160}
161
162// General fetching function.
164 StringRef UrlPath) {
165 SmallString<10> CacheDir;
166
168 if (!CacheDirOrErr)
169 return CacheDirOrErr.takeError();
170 CacheDir = *CacheDirOrErr;
171
172 return getCachedOrDownloadArtifact(UniqueKey, UrlPath, CacheDir,
175}
176
177namespace {
178
179/// A simple handler which streams the returned data to a cache file. The cache
180/// file is only created if a 200 OK status is observed.
181class StreamedHTTPResponseHandler : public HTTPResponseHandler {
182 using CreateStreamFn =
183 std::function<Expected<std::unique_ptr<CachedFileStream>>()>;
184 CreateStreamFn CreateStream;
185 HTTPClient &Client;
186 std::unique_ptr<CachedFileStream> FileStream;
187
188public:
189 StreamedHTTPResponseHandler(CreateStreamFn CreateStream, HTTPClient &Client)
190 : CreateStream(CreateStream), Client(Client) {}
191
192 /// Must be called exactly once after the writes have been completed
193 /// but before the StreamedHTTPResponseHandler object is destroyed.
194 Error commit();
195
196 virtual ~StreamedHTTPResponseHandler() = default;
197
198 Error handleBodyChunk(StringRef BodyChunk) override;
199};
200
201} // namespace
202
203Error StreamedHTTPResponseHandler::handleBodyChunk(StringRef BodyChunk) {
204 if (!FileStream) {
205 unsigned Code = Client.responseCode();
206 if (Code && Code != 200)
207 return Error::success();
208 Expected<std::unique_ptr<CachedFileStream>> FileStreamOrError =
209 CreateStream();
210 if (!FileStreamOrError)
211 return FileStreamOrError.takeError();
212 FileStream = std::move(*FileStreamOrError);
213 }
214 *FileStream->OS << BodyChunk;
215 return Error::success();
216}
217
218Error StreamedHTTPResponseHandler::commit() {
219 if (FileStream)
220 return FileStream->commit();
221 return Error::success();
222}
223
224// An over-accepting simplification of the HTTP RFC 7230 spec.
225static bool isHeader(StringRef S) {
228 std::tie(Name, Value) = S.split(':');
229 if (Name.empty() || Value.empty())
230 return false;
231 return all_of(Name, [](char C) { return llvm::isPrint(C) && C != ' '; }) &&
232 all_of(Value, [](char C) { return llvm::isPrint(C) || C == '\t'; });
233}
234
236 const char *Filename = getenv("DEBUGINFOD_HEADERS_FILE");
237 if (!Filename)
238 return {};
240 MemoryBuffer::getFile(Filename, /*IsText=*/true);
241 if (!HeadersFile)
242 return {};
243
245 uint64_t LineNumber = 0;
246 for (StringRef Line : llvm::split((*HeadersFile)->getBuffer(), '\n')) {
247 LineNumber++;
248 Line.consume_back("\r");
249 if (!isHeader(Line)) {
250 if (!all_of(Line, llvm::isSpace))
252 << "could not parse debuginfod header: " << Filename << ':'
253 << LineNumber << '\n';
254 continue;
255 }
256 Headers.emplace_back(Line);
257 }
258 return Headers;
259}
260
262 StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
263 ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout) {
264 SmallString<64> AbsCachedArtifactPath;
265 sys::path::append(AbsCachedArtifactPath, CacheDirectoryPath,
266 "llvmcache-" + UniqueKey);
267
268 Expected<FileCache> CacheOrErr =
269 localCache("Debuginfod-client", ".debuginfod-client", CacheDirectoryPath);
270 if (!CacheOrErr)
271 return CacheOrErr.takeError();
272
273 FileCache Cache = *CacheOrErr;
274 // We choose an arbitrary Task parameter as we do not make use of it.
275 unsigned Task = 0;
276 Expected<AddStreamFn> CacheAddStreamOrErr = Cache(Task, UniqueKey, "");
277 if (!CacheAddStreamOrErr)
278 return CacheAddStreamOrErr.takeError();
279 AddStreamFn &CacheAddStream = *CacheAddStreamOrErr;
280 if (!CacheAddStream)
281 return std::string(AbsCachedArtifactPath);
282 // The artifact was not found in the local cache, query the debuginfod
283 // servers.
286 "No working HTTP client is available.");
287
289 return createStringError(
291 "A working HTTP client is available, but it is not initialized. To "
292 "allow Debuginfod to make HTTP requests, call HTTPClient::initialize() "
293 "at the beginning of main.");
294
295 HTTPClient Client;
296 Client.setTimeout(Timeout);
297 for (StringRef ServerUrl : DebuginfodUrls) {
298 SmallString<64> ArtifactUrl;
299 sys::path::append(ArtifactUrl, sys::path::Style::posix, ServerUrl, UrlPath);
300
301 // Perform the HTTP request and if successful, write the response body to
302 // the cache.
303 {
304 StreamedHTTPResponseHandler Handler(
305 [&]() { return CacheAddStream(Task, ""); }, Client);
306 HTTPRequest Request(ArtifactUrl);
307 Request.Headers = getHeaders();
308 Error Err = Client.perform(Request, Handler);
309 if (Err)
310 return std::move(Err);
311 if ((Err = Handler.commit()))
312 return std::move(Err);
313
314 unsigned Code = Client.responseCode();
315 if (Code && Code != 200)
316 continue;
317 }
318
319 Expected<CachePruningPolicy> PruningPolicyOrErr =
320 parseCachePruningPolicy(std::getenv("DEBUGINFOD_CACHE_POLICY"));
321 if (!PruningPolicyOrErr)
322 return PruningPolicyOrErr.takeError();
323 pruneCache(CacheDirectoryPath, *PruningPolicyOrErr);
324
325 // Return the path to the artifact on disk.
326 return std::string(AbsCachedArtifactPath);
327 }
328
329 return createStringError(errc::argument_out_of_domain, "build id not found");
330}
331
333 : Message(Message.str()) {}
334
335void DebuginfodLog::push(const Twine &Message) {
336 push(DebuginfodLogEntry(Message));
337}
338
340 {
341 std::lock_guard<std::mutex> Guard(QueueMutex);
342 LogEntryQueue.push(Entry);
343 }
344 QueueCondition.notify_one();
345}
346
348 {
349 std::unique_lock<std::mutex> Guard(QueueMutex);
350 // Wait for messages to be pushed into the queue.
351 QueueCondition.wait(Guard, [&] { return !LogEntryQueue.empty(); });
352 }
353 std::lock_guard<std::mutex> Guard(QueueMutex);
354 if (!LogEntryQueue.size())
355 llvm_unreachable("Expected message in the queue.");
356
357 DebuginfodLogEntry Entry = LogEntryQueue.front();
358 LogEntryQueue.pop();
359 return Entry;
360}
361
363 DebuginfodLog &Log,
365 double MinInterval)
366 : Log(Log), Pool(Pool), MinInterval(MinInterval) {
367 for (StringRef Path : PathsRef)
368 Paths.push_back(Path.str());
369}
370
372 std::lock_guard<sys::Mutex> Guard(UpdateMutex);
373 if (UpdateTimer.isRunning())
374 UpdateTimer.stopTimer();
375 UpdateTimer.clear();
376 for (const std::string &Path : Paths) {
377 Log.push("Updating binaries at path " + Path);
378 if (Error Err = findBinaries(Path))
379 return Err;
380 }
381 Log.push("Updated collection");
382 UpdateTimer.startTimer();
383 return Error::success();
384}
385
386Expected<bool> DebuginfodCollection::updateIfStale() {
387 if (!UpdateTimer.isRunning())
388 return false;
389 UpdateTimer.stopTimer();
390 double Time = UpdateTimer.getTotalTime().getWallTime();
391 UpdateTimer.startTimer();
392 if (Time < MinInterval)
393 return false;
394 if (Error Err = update())
395 return std::move(Err);
396 return true;
397}
398
400 while (true) {
401 if (Error Err = update())
402 return Err;
403 std::this_thread::sleep_for(Interval);
404 }
405 llvm_unreachable("updateForever loop should never end");
406}
407
408static bool hasELFMagic(StringRef FilePath) {
410 std::error_code EC = identify_magic(FilePath, Type);
411 if (EC)
412 return false;
413 switch (Type) {
414 case file_magic::elf:
419 return true;
420 default:
421 return false;
422 }
423}
424
425Error DebuginfodCollection::findBinaries(StringRef Path) {
426 std::error_code EC;
427 sys::fs::recursive_directory_iterator I(Twine(Path), EC), E;
428 std::mutex IteratorMutex;
429 ThreadPoolTaskGroup IteratorGroup(Pool);
430 for (unsigned WorkerIndex = 0; WorkerIndex < Pool.getMaxConcurrency();
431 WorkerIndex++) {
432 IteratorGroup.async([&, this]() -> void {
433 std::string FilePath;
434 while (true) {
435 {
436 // Check if iteration is over or there is an error during iteration
437 std::lock_guard<std::mutex> Guard(IteratorMutex);
438 if (I == E || EC)
439 return;
440 // Grab a file path from the directory iterator and advance the
441 // iterator.
442 FilePath = I->path();
443 I.increment(EC);
444 }
445
446 // Inspect the file at this path to determine if it is debuginfo.
447 if (!hasELFMagic(FilePath))
448 continue;
449
450 Expected<object::OwningBinary<object::Binary>> BinOrErr =
451 object::createBinary(FilePath);
452
453 if (!BinOrErr) {
454 consumeError(BinOrErr.takeError());
455 continue;
456 }
457 object::Binary *Bin = std::move(BinOrErr.get().getBinary());
458 if (!Bin->isObject())
459 continue;
460
461 // TODO: Support non-ELF binaries
462 object::ELFObjectFileBase *Object =
463 dyn_cast<object::ELFObjectFileBase>(Bin);
464 if (!Object)
465 continue;
466
467 BuildIDRef ID = getBuildID(Object);
468 if (ID.empty())
469 continue;
470
471 std::string IDString = buildIDToString(ID);
472 if (Object->hasDebugInfo()) {
473 std::lock_guard<sys::RWMutex> DebugBinariesGuard(DebugBinariesMutex);
474 (void)DebugBinaries.try_emplace(IDString, std::move(FilePath));
475 } else {
476 std::lock_guard<sys::RWMutex> BinariesGuard(BinariesMutex);
477 (void)Binaries.try_emplace(IDString, std::move(FilePath));
478 }
479 }
480 });
481 }
482 IteratorGroup.wait();
483 std::unique_lock<std::mutex> Guard(IteratorMutex);
484 if (EC)
485 return errorCodeToError(EC);
486 return Error::success();
487}
488
489Expected<std::optional<std::string>>
490DebuginfodCollection::getBinaryPath(BuildIDRef ID) {
491 Log.push("getting binary path of ID " + buildIDToString(ID));
492 std::shared_lock<sys::RWMutex> Guard(BinariesMutex);
493 auto Loc = Binaries.find(buildIDToString(ID));
494 if (Loc != Binaries.end()) {
495 std::string Path = Loc->getValue();
496 return Path;
497 }
498 return std::nullopt;
499}
500
501Expected<std::optional<std::string>>
502DebuginfodCollection::getDebugBinaryPath(BuildIDRef ID) {
503 Log.push("getting debug binary path of ID " + buildIDToString(ID));
504 std::shared_lock<sys::RWMutex> Guard(DebugBinariesMutex);
505 auto Loc = DebugBinaries.find(buildIDToString(ID));
506 if (Loc != DebugBinaries.end()) {
507 std::string Path = Loc->getValue();
508 return Path;
509 }
510 return std::nullopt;
511}
512
514 {
515 // Check collection; perform on-demand update if stale.
516 Expected<std::optional<std::string>> PathOrErr = getBinaryPath(ID);
517 if (!PathOrErr)
518 return PathOrErr.takeError();
519 std::optional<std::string> Path = *PathOrErr;
520 if (!Path) {
521 Expected<bool> UpdatedOrErr = updateIfStale();
522 if (!UpdatedOrErr)
523 return UpdatedOrErr.takeError();
524 if (*UpdatedOrErr) {
525 // Try once more.
526 PathOrErr = getBinaryPath(ID);
527 if (!PathOrErr)
528 return PathOrErr.takeError();
529 Path = *PathOrErr;
530 }
531 }
532 if (Path)
533 return *Path;
534 }
535
536 // Try federation.
538 if (!PathOrErr)
539 consumeError(PathOrErr.takeError());
540
541 // Fall back to debug binary.
542 return findDebugBinaryPath(ID);
543}
544
546 // Check collection; perform on-demand update if stale.
547 Expected<std::optional<std::string>> PathOrErr = getDebugBinaryPath(ID);
548 if (!PathOrErr)
549 return PathOrErr.takeError();
550 std::optional<std::string> Path = *PathOrErr;
551 if (!Path) {
552 Expected<bool> UpdatedOrErr = updateIfStale();
553 if (!UpdatedOrErr)
554 return UpdatedOrErr.takeError();
555 if (*UpdatedOrErr) {
556 // Try once more.
557 PathOrErr = getBinaryPath(ID);
558 if (!PathOrErr)
559 return PathOrErr.takeError();
560 Path = *PathOrErr;
561 }
562 }
563 if (Path)
564 return *Path;
565
566 // Try federation.
568}
569
570Error DebuginfodServer::init(DebuginfodLog &Log,
571 DebuginfodCollection &Collection) {
572
573 Error Err =
574 Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
575 Log.push("GET " + Request.UrlPath);
576 std::string IDString;
577 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
578 Request.setResponse(
579 {404, "text/plain", "Build ID is not a hex string\n"});
580 return;
581 }
582 object::BuildID ID(IDString.begin(), IDString.end());
583 Expected<std::string> PathOrErr = Collection.findDebugBinaryPath(ID);
584 if (Error Err = PathOrErr.takeError()) {
585 consumeError(std::move(Err));
586 Request.setResponse({404, "text/plain", "Build ID not found\n"});
587 return;
588 }
589 streamFile(Request, *PathOrErr);
590 });
591 if (Err)
592 return Err;
593
594 Err =
595 Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
596 Log.push("GET " + Request.UrlPath);
597 std::string IDString;
598 if (!tryGetFromHex(Request.UrlPathMatches[0], IDString)) {
599 Request.setResponse(
600 {404, "text/plain", "Build ID is not a hex string\n"});
601 return;
602 }
603 object::BuildID ID(IDString.begin(), IDString.end());
604 Expected<std::string> PathOrErr = Collection.findBinaryPath(ID);
605 if (Error Err = PathOrErr.takeError()) {
606 consumeError(std::move(Err));
607 Request.setResponse({404, "text/plain", "Build ID not found\n"});
608 return;
609 }
610 streamFile(Request, *PathOrErr);
611 });
612 if (Err)
613 return Err;
614 return Error::success();
615}
616
617Expected<DebuginfodServer>
618DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
619 DebuginfodServer Serverd;
620 if (llvm::Error Err = Serverd.init(Log, Collection))
621 return std::move(Err);
622 return std::move(Serverd);
623}
624
625} // 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
std::pair< uint64_t, uint64_t > Interval
if(PassOpts->AAPipeline)
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:124
DebuginfodCollection(ArrayRef< StringRef > Paths, DebuginfodLog &Log, ThreadPoolInterface &Pool, double MinInterval)
Definition: Debuginfod.cpp:362
Expected< std::string > findBinaryPath(object::BuildIDRef)
Definition: Debuginfod.cpp:513
Error updateForever(std::chrono::milliseconds Interval)
Definition: Debuginfod.cpp:399
Expected< std::string > findDebugBinaryPath(object::BuildIDRef)
Definition: Debuginfod.cpp:545
DebuginfodLogEntry pop()
Definition: Debuginfod.cpp:347
void push(DebuginfodLogEntry Entry)
Definition: Debuginfod.cpp:339
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.
Definition: HTTPClient.cpp:145
static bool IsInitialized
Definition: HTTPClient.h:62
unsigned responseCode()
Returns the last received response code or zero if none.
Definition: HTTPClient.cpp:158
Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler)
Performs the Request, passing response data to the Handler.
Definition: HTTPClient.cpp:153
void setTimeout(std::chrono::milliseconds Timeout)
Sets the timeout for the entire request, in milliseconds.
Definition: HTTPClient.cpp:151
void setResponse(StreamingHTTPResponse Response)
Definition: HTTPServer.cpp:173
SmallVector< std::string, 1 > UrlPathMatches
The elements correspond to match groups in the url path matching regex.
Definition: HTTPServer.h:60
Error get(StringRef UrlPathPattern, HTTPRequestHandler Handler)
Registers a URL pattern routing rule.
Definition: HTTPServer.cpp:177
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:938
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
iterator end()
Definition: StringMap.h:224
iterator find(StringRef Key)
Definition: StringMap.h:237
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:372
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:710
This defines the abstract base interface for a ThreadPool allowing asynchronous parallel execution on...
Definition: ThreadPool.h:50
virtual unsigned getMaxConcurrency() const =0
Returns the maximum number of worker this pool can eventually grow to.
double getWallTime() const
Definition: Timer.h:46
bool isRunning() const
Check if the timer is currently running.
Definition: Timer.h:120
LLVM_ABI void stopTimer()
Stop the timer.
Definition: Timer.cpp:158
LLVM_ABI void clear()
Clear the timer state.
Definition: Timer.cpp:168
LLVM_ABI void startTimer()
Start the timer running.
Definition: Timer.cpp:149
TimeRecord getTotalTime() const
Return the duration for which this timer has been running.
Definition: Timer.h:140
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:45
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:56
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
NodeAddr< CodeNode * > Code
Definition: RDFGraph.h:388
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:568
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:456
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1744
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.
Definition: Debuginfod.cpp:57
LLVM_ABI uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Definition: xxhash.cpp:553
static bool isHeader(StringRef S)
Definition: Debuginfod.cpp:225
SmallVector< StringRef > getDefaultDebuginfodUrls()
Finds default array of Debuginfod server URLs by checking DEBUGINFOD_URLS environment variable.
Definition: Debuginfod.cpp:71
std::string getDebuginfodSourceUrlPath(object::BuildIDRef ID, StringRef SourceFilePath)
Get the full URL path for a source request of a given BuildID and file path.
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:60
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:63
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:1305
@ 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:163
std::string getDebuginfodDebuginfoUrlPath(object::BuildIDRef ID)
Get the full URL path for a debug binary request of a given BuildID.
@ Timeout
Reached timeout while waiting for the owner to release the lock.
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.
Definition: Debuginfod.cpp:109
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:111
static bool hasELFMagic(StringRef FilePath)
Definition: Debuginfod.cpp:408
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:235
void setDefaultDebuginfodUrls(const SmallVector< StringRef > &URLs)
Sets the list of debuginfod server URLs to query.
Definition: Debuginfod.cpp:90
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1083
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.
Definition: Debuginfod.cpp:67
Expected< std::string > getDefaultDebuginfodCacheDirectory()
Finds a default local file caching directory for the debuginfod client, first checking DEBUGINFOD_CAC...
Definition: Debuginfod.cpp:97
This type represents a file cache system that manages caching of files.
Definition: Caching.h:85
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