Skip to content

[lldb] Expand background symbol download (#80890) #8155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ class UUID;
class VariableList;
struct ModuleFunctionSearchOptions;

static constexpr OptionEnumValueElement g_auto_download_enum_values[] = {
{
lldb::eSymbolDownloadOff,
"off",
"Disable automatically downloading symbols.",
},
{
lldb::eSymbolDownloadBackground,
"background",
"Download symbols in the background for images as they appear in the "
"backtrace.",
},
{
lldb::eSymbolDownloadForeground,
"foreground",
"Download symbols in the foreground for images as they appear in the "
"backtrace.",
},
};

class ModuleListProperties : public Properties {
mutable llvm::sys::RWMutex m_symlink_paths_mutex;
PathMappingList m_symlink_paths;
Expand Down Expand Up @@ -78,7 +98,6 @@ class ModuleListProperties : public Properties {
bool SetClangModulesCachePath(const FileSpec &path);
bool GetEnableExternalLookup() const;
bool SetEnableExternalLookup(bool new_value);
bool GetEnableBackgroundLookup() const;
bool GetEnableLLDBIndexCache() const;
bool SetEnableLLDBIndexCache(bool new_value);
uint64_t GetLLDBIndexCacheMaxByteSize();
Expand All @@ -89,6 +108,8 @@ class ModuleListProperties : public Properties {

bool GetLoadSymbolOnDemand();

lldb::SymbolDownload GetSymbolAutoDownload() const;

PathMappingList GetSymlinkMappings() const;
};

Expand Down
6 changes: 6 additions & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,12 @@ enum CompletionType {
eCustomCompletion = (1u << 25)
};

enum SymbolDownload {
eSymbolDownloadOff = 0,
eSymbolDownloadBackground = 1,
eSymbolDownloadForeground = 2,
};

} // namespace lldb

#endif // LLDB_LLDB_ENUMERATIONS_H
7 changes: 6 additions & 1 deletion lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ let Definition = "modulelist" in {
def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
Global,
DefaultFalse,
Desc<"On macOS, enable calling dsymForUUID (or an equivalent script/binary) in the background to locate symbol files that weren't found.">;
Desc<"Alias for backward compatibility: when enabled this is the equivalent to 'symbols.download background'.">;
def AutoDownload: Property<"auto-download", "Enum">,
Global,
DefaultEnumValue<"eSymbolDownloadOff">,
EnumValues<"OptionEnumValues(g_auto_download_enum_values)">,
Desc<"On macOS, automatically download symbols with dsymForUUID (or an equivalent script/binary) for relevant images in the debug session.">;
def ClangModulesCachePath: Property<"clang-modules-cache-path", "FileSpec">,
Global,
DefaultStringValue<"">,
Expand Down
13 changes: 9 additions & 4 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ bool ModuleListProperties::SetEnableExternalLookup(bool new_value) {
return SetPropertyAtIndex(ePropertyEnableExternalLookup, new_value);
}

bool ModuleListProperties::GetEnableBackgroundLookup() const {
const uint32_t idx = ePropertyEnableBackgroundLookup;
return GetPropertyAtIndexAs<bool>(
idx, g_modulelist_properties[idx].default_uint_value != 0);
SymbolDownload ModuleListProperties::GetSymbolAutoDownload() const {
// Backward compatibility alias.
if (GetPropertyAtIndexAs<bool>(ePropertyEnableBackgroundLookup, false))
return eSymbolDownloadBackground;

const uint32_t idx = ePropertyAutoDownload;
return GetPropertyAtIndexAs<lldb::SymbolDownload>(
idx, static_cast<lldb::SymbolDownload>(
g_modulelist_properties[idx].default_uint_value));
}

FileSpec ModuleListProperties::GetClangModulesCachePath() const {
Expand Down
25 changes: 17 additions & 8 deletions lldb/source/Symbol/LocateSymbolFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,10 @@ Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec,
}

void Symbols::DownloadSymbolFileAsync(const UUID &uuid) {
if (!ModuleList::GetGlobalModuleListProperties().GetEnableBackgroundLookup())
return;

static llvm::SmallSet<UUID, 8> g_seen_uuids;
static std::mutex g_mutex;
Debugger::GetThreadPool().async([=]() {

auto lookup = [=]() {
{
std::lock_guard<std::mutex> guard(g_mutex);
if (g_seen_uuids.count(uuid))
Expand All @@ -416,16 +414,27 @@ void Symbols::DownloadSymbolFileAsync(const UUID &uuid) {
Status error;
ModuleSpec module_spec;
module_spec.GetUUID() = uuid;
if (!Symbols::DownloadObjectAndSymbolFile(module_spec, error,
/*force_lookup=*/true,
/*copy_executable=*/false))
if (!PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
/*force_lookup=*/true,
/*copy_executable=*/true))
return;

if (error.Fail())
return;

Debugger::ReportSymbolChange(module_spec);
});
};

switch (ModuleList::GetGlobalModuleListProperties().GetSymbolAutoDownload()) {
case eSymbolDownloadOff:
break;
case eSymbolDownloadBackground:
Debugger::GetThreadPool().async(lookup);
break;
case eSymbolDownloadForeground:
lookup();
break;
};
}

#if !defined(__APPLE__)
Expand Down