File indexing completed on 2026-05-10 08:43:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef LLVM_DEBUGINFOD_DEBUGINFOD_H
0021 #define LLVM_DEBUGINFOD_DEBUGINFOD_H
0022
0023 #include "HTTPServer.h"
0024
0025 #include "llvm/ADT/StringMap.h"
0026 #include "llvm/ADT/StringRef.h"
0027 #include "llvm/Object/BuildID.h"
0028 #include "llvm/Support/Error.h"
0029 #include "llvm/Support/MemoryBuffer.h"
0030 #include "llvm/Support/Mutex.h"
0031 #include "llvm/Support/RWMutex.h"
0032 #include "llvm/Support/Timer.h"
0033
0034 #include <chrono>
0035 #include <condition_variable>
0036 #include <optional>
0037 #include <queue>
0038
0039 namespace llvm {
0040
0041
0042
0043 bool canUseDebuginfod();
0044
0045
0046
0047 SmallVector<StringRef> getDefaultDebuginfodUrls();
0048
0049
0050 std::string getDebuginfodCacheKey(StringRef UrlPath);
0051
0052
0053
0054 void setDefaultDebuginfodUrls(const SmallVector<StringRef> &URLs);
0055
0056
0057
0058 Expected<std::string> getDefaultDebuginfodCacheDirectory();
0059
0060
0061
0062 std::chrono::milliseconds getDefaultDebuginfodTimeout();
0063
0064
0065
0066 std::string getDebuginfodSourceUrlPath(object::BuildIDRef ID,
0067 StringRef SourceFilePath);
0068
0069
0070
0071 Expected<std::string> getCachedOrDownloadSource(object::BuildIDRef ID,
0072 StringRef SourceFilePath);
0073
0074
0075 std::string getDebuginfodExecutableUrlPath(object::BuildIDRef ID);
0076
0077
0078
0079 Expected<std::string> getCachedOrDownloadExecutable(object::BuildIDRef ID);
0080
0081
0082 std::string getDebuginfodDebuginfoUrlPath(object::BuildIDRef ID);
0083
0084
0085
0086 Expected<std::string> getCachedOrDownloadDebuginfo(object::BuildIDRef ID);
0087
0088
0089
0090 Expected<std::string> getCachedOrDownloadArtifact(StringRef UniqueKey,
0091 StringRef UrlPath);
0092
0093
0094
0095
0096 Expected<std::string> getCachedOrDownloadArtifact(
0097 StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
0098 ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout);
0099
0100 class ThreadPoolInterface;
0101
0102 struct DebuginfodLogEntry {
0103 std::string Message;
0104 DebuginfodLogEntry() = default;
0105 DebuginfodLogEntry(const Twine &Message);
0106 };
0107
0108 class DebuginfodLog {
0109 std::mutex QueueMutex;
0110 std::condition_variable QueueCondition;
0111 std::queue<DebuginfodLogEntry> LogEntryQueue;
0112
0113 public:
0114
0115 void push(DebuginfodLogEntry Entry);
0116
0117 void push(const Twine &Message);
0118
0119
0120 DebuginfodLogEntry pop();
0121 };
0122
0123
0124 class DebuginfodCollection {
0125 SmallVector<std::string, 1> Paths;
0126 sys::RWMutex BinariesMutex;
0127 StringMap<std::string> Binaries;
0128 sys::RWMutex DebugBinariesMutex;
0129 StringMap<std::string> DebugBinaries;
0130 Error findBinaries(StringRef Path);
0131 Expected<std::optional<std::string>> getDebugBinaryPath(object::BuildIDRef);
0132 Expected<std::optional<std::string>> getBinaryPath(object::BuildIDRef);
0133
0134
0135
0136 Expected<bool> updateIfStale();
0137 DebuginfodLog &Log;
0138 ThreadPoolInterface &Pool;
0139 Timer UpdateTimer;
0140 sys::Mutex UpdateMutex;
0141
0142
0143
0144 double MinInterval;
0145
0146 public:
0147 DebuginfodCollection(ArrayRef<StringRef> Paths, DebuginfodLog &Log,
0148 ThreadPoolInterface &Pool, double MinInterval);
0149 Error update();
0150 Error updateForever(std::chrono::milliseconds Interval);
0151 Expected<std::string> findDebugBinaryPath(object::BuildIDRef);
0152 Expected<std::string> findBinaryPath(object::BuildIDRef);
0153 };
0154
0155 struct DebuginfodServer {
0156 HTTPServer Server;
0157 DebuginfodLog &Log;
0158 DebuginfodCollection &Collection;
0159 DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection);
0160 };
0161
0162 }
0163
0164 #endif