Skip to content

Commit 9fd5509

Browse files
committed
[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 055e55a commit 9fd5509

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
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/SymbolLocator.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "lldb/Core/Debugger.h"
1212
#include "lldb/Core/PluginManager.h"
13+
#include "lldb/Host/Host.h"
1314

1415
#include "llvm/ADT/SmallSet.h"
1516
#include "llvm/Support/ThreadPool.h"
@@ -18,12 +19,10 @@ using namespace lldb;
1819
using namespace lldb_private;
1920

2021
void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
21-
if (!ModuleList::GetGlobalModuleListProperties().GetEnableBackgroundLookup())
22-
return;
23-
2422
static llvm::SmallSet<UUID, 8> g_seen_uuids;
2523
static std::mutex g_mutex;
26-
Debugger::GetThreadPool().async([=]() {
24+
25+
auto lookup = [=]() {
2726
{
2827
std::lock_guard<std::mutex> guard(g_mutex);
2928
if (g_seen_uuids.count(uuid))
@@ -36,12 +35,23 @@ void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
3635
module_spec.GetUUID() = uuid;
3736
if (!PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
3837
/*force_lookup=*/true,
39-
/*copy_executable=*/false))
38+
/*copy_executable=*/true))
4039
return;
4140

4241
if (error.Fail())
4342
return;
4443

4544
Debugger::ReportSymbolChange(module_spec);
46-
});
45+
};
46+
47+
switch (ModuleList::GetGlobalModuleListProperties().GetSymbolAutoDownload()) {
48+
case eSymbolDownloadOff:
49+
break;
50+
case eSymbolDownloadBackground:
51+
Debugger::GetThreadPool().async(lookup);
52+
break;
53+
case eSymbolDownloadForeground:
54+
lookup();
55+
break;
56+
};
4757
}

0 commit comments

Comments
 (0)