17#include "llvm/Debuginfod/Debuginfod.h"
18#include "llvm/Debuginfod/HTTPClient.h"
27#define LLDB_PROPERTIES_symbollocatordebuginfod
28#include "SymbolLocatorDebuginfodProperties.inc"
31#define LLDB_PROPERTIES_symbollocatordebuginfod
32#include "SymbolLocatorDebuginfodPropertiesEnum.inc"
37 static llvm::StringRef GetSettingName() {
42 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
43 m_collection_sp->Initialize(g_symbollocatordebuginfod_properties);
46 llvm::SmallVector<llvm::StringRef> urls = llvm::getDefaultDebuginfodUrls();
48 m_collection_sp->SetPropertyAtIndexFromArgs(ePropertyServerURLs, arg_urls);
50 m_collection_sp->SetValueChangedCallback(
51 ePropertyServerURLs, [
this] { ServerURLsChangedCallback(); });
54 Args GetDebugInfoDURLs()
const {
56 m_collection_sp->GetPropertyAtIndexAsArgs(ePropertyServerURLs, urls);
60 llvm::Expected<std::string> GetCachePath() {
62 m_collection_sp->GetPropertyAtIndexAsOptionValueString(
63 ePropertySymbolCachePath);
66 llvm::Expected<std::string> maybeCachePath =
67 llvm::getDefaultDebuginfodCacheDirectory();
69 return maybeCachePath;
70 return *maybeCachePath;
75 std::chrono::milliseconds GetTimeout()
const {
76 std::optional<uint64_t> seconds =
77 m_collection_sp->GetPropertyAtIndexAs<uint64_t>(ePropertyTimeout);
78 if (seconds && *seconds != 0) {
79 return std::chrono::duration_cast<std::chrono::milliseconds>(
80 std::chrono::seconds(*seconds));
82 return llvm::getDefaultDebuginfodTimeout();
87 void ServerURLsChangedCallback() {
88 m_server_urls = GetDebugInfoDURLs();
89 llvm::SmallVector<llvm::StringRef> dbginfod_urls;
90 llvm::for_each(m_server_urls, [&](
const auto &obj) {
91 dbginfod_urls.push_back(obj.ref());
93 llvm::setDefaultDebuginfodUrls(dbginfod_urls);
102 static PluginProperties g_settings;
109 static llvm::once_flag g_once_flag;
111 llvm::call_once(g_once_flag, []() {
116 llvm::HTTPClient::initialize();
122 debugger, PluginProperties::GetSettingName())) {
123 const bool is_global_setting =
true;
126 "Properties for the Debuginfod Symbol Locator plug-in.",
133 llvm::HTTPClient::cleanup();
137 return "Debuginfod symbol locator.";
144static std::optional<FileSpec>
146 std::function<std::string(llvm::object::BuildID)> UrlBuilder) {
150 if (!module_uuid.
IsValid() || !llvm::canUseDebuginfod() ||
157 llvm::Expected<std::string> cache_path_or_err = plugin_props.GetCachePath();
159 if (!cache_path_or_err)
161 std::string cache_path = *cache_path_or_err;
162 llvm::SmallVector<llvm::StringRef> debuginfod_urls =
163 llvm::getDefaultDebuginfodUrls();
164 std::chrono::milliseconds timeout = plugin_props.GetTimeout();
167 llvm::object::BuildID build_id(module_uuid.
GetBytes());
168 std::string url_path = UrlBuilder(build_id);
169 std::string cache_key = llvm::getDebuginfodCacheKey(url_path);
170 llvm::Expected<std::string> result = llvm::getCachedOrDownloadArtifact(
171 cache_key, url_path, cache_path, debuginfod_urls, timeout);
176 auto err_message = llvm::toString(result.takeError());
178 "Debuginfod failed to download symbol artifact {0} with error {1}",
179 url_path, err_message);
static PluginProperties & GetGlobalPluginProperties()
#define LLDB_LOGV(log,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
static PluginProperties & GetGlobalPluginProperties()
static std::optional< FileSpec > GetFileForModule(const ModuleSpec &module_spec, std::function< std::string(llvm::object::BuildID)> UrlBuilder)
A command line argument class.
A class to manage flag bits.
bool GetEnableExternalLookup() const
static ModuleListProperties & GetGlobalModuleListProperties()
llvm::StringRef GetCurrentValueAsRef() const
const char * GetCurrentValue() const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForSymbolLocatorPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool CreateSettingForSymbolLocatorPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static std::optional< FileSpec > LocateExecutableSymbolFile(const ModuleSpec &module_spec, const FileSpecList &default_search_paths)
static lldb_private::SymbolLocator * CreateInstance()
static void DebuggerInitialize(Debugger &debugger)
static llvm::StringRef GetPluginDescriptionStatic()
static llvm::StringRef GetPluginNameStatic()
SymbolLocatorDebuginfod()
static std::optional< ModuleSpec > LocateExecutableObjectFile(const ModuleSpec &module_spec)
llvm::ArrayRef< uint8_t > GetBytes() const
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.