Skip to content

Commit 9e6b9ea

Browse files
JDevliegherejasonmolenda
authored andcommitted
[lldb] Expand background symbol download (llvm#80890)
LLDB has a setting (symbols.enable-background-lookup) that calls dsymForUUID on a background thread for images as they appear in the current backtrace. Originally, the laziness of only looking up symbols for images in the backtrace only existed to bring the number of dsymForUUID calls down to a manageable number. Users have requesting the same functionality but blocking. This gives them the same user experience as enabling dsymForUUID globally, but without the massive upfront cost of having to download all the images, the majority of which they'll likely not need. This patch renames the setting to have a more generic name (symbols.auto-download) and changes its values from a boolean to an enum. Users can now specify "off", "background" and "foreground". The default remains "off" although I'll probably change that in the near future. (cherry picked from commit 5f4b40c)
1 parent 02a02cb commit 9e6b9ea

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ class UUID;
4747
class VariableList;
4848
struct ModuleFunctionSearchOptions;
4949

50+
static constexpr OptionEnumValueElement g_auto_download_enum_values[] = {
51+
{
52+
lldb::eSymbolDownloadOff,
53+
"off",
54+
"Disable automatically downloading symbols.",
55+
},
56+
{
57+
lldb::eSymbolDownloadBackground,
58+
"background",
59+
"Download symbols in the background for images as they appear in the "
60+
"backtrace.",
61+
},
62+
{
63+
lldb::eSymbolDownloadForeground,
64+
"foreground",
65+
"Download symbols in the foreground for images as they appear in the "
66+
"backtrace.",
67+
},
68+
};
69+
5070
class ModuleListProperties : public Properties {
5171
mutable llvm::sys::RWMutex m_symlink_paths_mutex;
5272
PathMappingList m_symlink_paths;
@@ -78,7 +98,6 @@ class ModuleListProperties : public Properties {
7898
bool SetClangModulesCachePath(const FileSpec &path);
7999
bool GetEnableExternalLookup() const;
80100
bool SetEnableExternalLookup(bool new_value);
81-
bool GetEnableBackgroundLookup() const;
82101
bool GetEnableLLDBIndexCache() const;
83102
bool SetEnableLLDBIndexCache(bool new_value);
84103
uint64_t GetLLDBIndexCacheMaxByteSize();
@@ -89,6 +108,8 @@ class ModuleListProperties : public Properties {
89108

90109
bool GetLoadSymbolOnDemand();
91110

111+
lldb::SymbolDownload GetSymbolAutoDownload() const;
112+
92113
PathMappingList GetSymlinkMappings() const;
93114
};
94115

lldb/include/lldb/lldb-enumerations.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,12 @@ enum CompletionType {
13321332
eCustomCompletion = (1u << 25)
13331333
};
13341334

1335+
enum SymbolDownload {
1336+
eSymbolDownloadOff = 0,
1337+
eSymbolDownloadBackground = 1,
1338+
eSymbolDownloadForeground = 2,
1339+
};
1340+
13351341
} // namespace lldb
13361342

13371343
#endif // LLDB_LLDB_ENUMERATIONS_H

lldb/source/Core/CoreProperties.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ let Definition = "modulelist" in {
88
def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
99
Global,
1010
DefaultFalse,
11-
Desc<"On macOS, enable calling dsymForUUID (or an equivalent script/binary) in the background to locate symbol files that weren't found.">;
11+
Desc<"Alias for backward compatibility: when enabled this is the equivalent to 'symbols.download background'.">;
12+
def AutoDownload: Property<"auto-download", "Enum">,
13+
Global,
14+
DefaultEnumValue<"eSymbolDownloadOff">,
15+
EnumValues<"OptionEnumValues(g_auto_download_enum_values)">,
16+
Desc<"On macOS, automatically download symbols with dsymForUUID (or an equivalent script/binary) for relevant images in the debug session.">;
1217
def ClangModulesCachePath: Property<"clang-modules-cache-path", "FileSpec">,
1318
Global,
1419
DefaultStringValue<"">,

lldb/source/Core/ModuleList.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ bool ModuleListProperties::SetEnableExternalLookup(bool new_value) {
137137
return SetPropertyAtIndex(ePropertyEnableExternalLookup, new_value);
138138
}
139139

140-
bool ModuleListProperties::GetEnableBackgroundLookup() const {
141-
const uint32_t idx = ePropertyEnableBackgroundLookup;
142-
return GetPropertyAtIndexAs<bool>(
143-
idx, g_modulelist_properties[idx].default_uint_value != 0);
140+
SymbolDownload ModuleListProperties::GetSymbolAutoDownload() const {
141+
// Backward compatibility alias.
142+
if (GetPropertyAtIndexAs<bool>(ePropertyEnableBackgroundLookup, false))
143+
return eSymbolDownloadBackground;
144+
145+
const uint32_t idx = ePropertyAutoDownload;
146+
return GetPropertyAtIndexAs<lldb::SymbolDownload>(
147+
idx, static_cast<lldb::SymbolDownload>(
148+
g_modulelist_properties[idx].default_uint_value));
144149
}
145150

146151
FileSpec ModuleListProperties::GetClangModulesCachePath() const {

lldb/source/Symbol/LocateSymbolFile.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,10 @@ Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec,
400400
}
401401

402402
void Symbols::DownloadSymbolFileAsync(const UUID &uuid) {
403-
if (!ModuleList::GetGlobalModuleListProperties().GetEnableBackgroundLookup())
404-
return;
405-
406403
static llvm::SmallSet<UUID, 8> g_seen_uuids;
407404
static std::mutex g_mutex;
408-
Debugger::GetThreadPool().async([=]() {
405+
406+
auto lookup = [=]() {
409407
{
410408
std::lock_guard<std::mutex> guard(g_mutex);
411409
if (g_seen_uuids.count(uuid))
@@ -417,15 +415,26 @@ void Symbols::DownloadSymbolFileAsync(const UUID &uuid) {
417415
ModuleSpec module_spec;
418416
module_spec.GetUUID() = uuid;
419417
if (!Symbols::DownloadObjectAndSymbolFile(module_spec, error,
420-
/*force_lookup=*/true,
421-
/*copy_executable=*/false))
418+
/*force_lookup=*/true,
419+
/*copy_executable=*/true))
422420
return;
423421

424422
if (error.Fail())
425423
return;
426424

427425
Debugger::ReportSymbolChange(module_spec);
428-
});
426+
};
427+
428+
switch (ModuleList::GetGlobalModuleListProperties().GetSymbolAutoDownload()) {
429+
case eSymbolDownloadOff:
430+
break;
431+
case eSymbolDownloadBackground:
432+
Debugger::GetThreadPool().async(lookup);
433+
break;
434+
case eSymbolDownloadForeground:
435+
lookup();
436+
break;
437+
};
429438
}
430439

431440
#if !defined(__APPLE__)

0 commit comments

Comments
 (0)