diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-12-18 20:30:12 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2024-04-06 20:11:55 +0000 |
commit | 5f757f3ff9144b609b3c433dfd370cc6bdc191ad (patch) | |
tree | 1b4e980b866cd26a00af34c0a653eb640bd09caf /contrib/llvm-project/llvm/lib/Debuginfod/Debuginfod.cpp | |
parent | 3e1c8a35f741a5d114d0ba670b15191355711fe9 (diff) | |
parent | 312c0ed19cc5276a17bacf2120097bec4515b0f1 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Debuginfod/Debuginfod.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Debuginfod/Debuginfod.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/contrib/llvm-project/llvm/lib/Debuginfod/Debuginfod.cpp b/contrib/llvm-project/llvm/lib/Debuginfod/Debuginfod.cpp index 394f2b29aee6..9df30ab55cba 100644 --- a/contrib/llvm-project/llvm/lib/Debuginfod/Debuginfod.cpp +++ b/contrib/llvm-project/llvm/lib/Debuginfod/Debuginfod.cpp @@ -41,13 +41,22 @@ #include "llvm/Support/xxhash.h" #include <atomic> +#include <optional> #include <thread> namespace llvm { using llvm::object::BuildIDRef; -static std::string uniqueKey(llvm::StringRef S) { return utostr(xxHash64(S)); } +namespace { +std::optional<SmallVector<StringRef>> DebuginfodUrls; +// Many Readers/Single Writer lock protecting the global debuginfod URL list. +llvm::sys::RWMutex UrlsMutex; +} // namespace + +static std::string uniqueKey(llvm::StringRef S) { + return utostr(xxh3_64bits(S)); +} // Returns a binary BuildID as a normalized hex string. // Uses lowercase for compatibility with common debuginfod servers. @@ -60,13 +69,27 @@ bool canUseDebuginfod() { } SmallVector<StringRef> getDefaultDebuginfodUrls() { - const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS"); - if (DebuginfodUrlsEnv == nullptr) - return SmallVector<StringRef>(); + std::shared_lock<llvm::sys::RWMutex> ReadGuard(UrlsMutex); + if (!DebuginfodUrls) { + // Only read from the environment variable if the user hasn't already + // set the value + ReadGuard.unlock(); + std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex); + DebuginfodUrls = SmallVector<StringRef>(); + if (const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS")) { + StringRef(DebuginfodUrlsEnv) + .split(DebuginfodUrls.value(), " ", -1, false); + } + WriteGuard.unlock(); + ReadGuard.lock(); + } + return DebuginfodUrls.value(); +} - SmallVector<StringRef> DebuginfodUrls; - StringRef(DebuginfodUrlsEnv).split(DebuginfodUrls, " "); - return DebuginfodUrls; +// Set the default debuginfod URL list, override the environment variable +void setDefaultDebuginfodUrls(const SmallVector<StringRef> &URLs) { + std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex); + DebuginfodUrls = URLs; } /// Finds a default local file caching directory for the debuginfod client, |