Skip to content

Commit 3b1818b

Browse files
committed
[lldb] Expand background symbol lookup
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.lazy-lookup) and changes its values from a boolean to an enum. Users can now specify lazy-lookup as "off", "background" and "foreground". The default remains "off" although I'll probably change that in the near future.
1 parent 1833de3 commit 3b1818b

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-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_lazy_lookup_enum_values[] = {
51+
{
52+
lldb::eLazyLookupOff,
53+
"off",
54+
"Disable lazy symbol lookup.",
55+
},
56+
{
57+
lldb::eLazyLookupBackground,
58+
"background",
59+
"Lazily look up symbols in the background without blocking the "
60+
"debugger.",
61+
},
62+
{
63+
lldb::eLazyLookupForeground,
64+
"foreground",
65+
"Lazily look up symbols in the foreground and block the debugger until "
66+
"they're found.",
67+
},
68+
};
69+
5070
class ModuleListProperties : public Properties {
5171
mutable llvm::sys::RWMutex m_symlink_paths_mutex;
5272
PathMappingList m_symlink_paths;
@@ -60,7 +80,6 @@ class ModuleListProperties : public Properties {
6080
bool SetClangModulesCachePath(const FileSpec &path);
6181
bool GetEnableExternalLookup() const;
6282
bool SetEnableExternalLookup(bool new_value);
63-
bool GetEnableBackgroundLookup() const;
6483
bool GetEnableLLDBIndexCache() const;
6584
bool SetEnableLLDBIndexCache(bool new_value);
6685
uint64_t GetLLDBIndexCacheMaxByteSize();
@@ -71,6 +90,8 @@ class ModuleListProperties : public Properties {
7190

7291
bool GetLoadSymbolOnDemand();
7392

93+
lldb::LazySymbolLookup GetLazySymbolLookup() const;
94+
7495
PathMappingList GetSymlinkMappings() const;
7596
};
7697

lldb/include/lldb/lldb-enumerations.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,12 @@ enum CompletionType {
13051305
eTerminatorCompletion = (1ul << 27)
13061306
};
13071307

1308+
enum LazySymbolLookup {
1309+
eLazyLookupOff = 0,
1310+
eLazyLookupBackground = 1,
1311+
eLazyLookupForeground = 2,
1312+
};
1313+
13081314
} // namespace lldb
13091315

13101316
#endif // LLDB_LLDB_ENUMERATIONS_H

lldb/source/Core/CoreProperties.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
55
Global,
66
DefaultTrue,
77
Desc<"Control the use of external tools and repositories to locate symbol files. Directories listed in target.debug-file-search-paths and directory of the executable are always checked first for separate debug info files. Then depending on this setting: On macOS, Spotlight would be also used to locate a matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory /usr/libdata/debug would be also searched. On platforms other than NetBSD directory /usr/lib/debug would be also searched. If all other methods fail there may be symbol-locator plugins that, if configured properly, will also attempt to acquire symbols. The debuginfod plugin defaults to the DEGUFINFOD_URLS environment variable which is configurable through the 'plugin.symbol-locator.debuginfod.server_urls' setting.">;
8-
def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
8+
def LazySymbolLookup: Property<"lazy-lookup", "Enum">,
99
Global,
10-
DefaultFalse,
11-
Desc<"On macOS, enable calling dsymForUUID (or an equivalent script/binary) in the background to locate symbol files that weren't found.">;
10+
DefaultEnumValue<"eLazyLookupOff">,
11+
EnumValues<"OptionEnumValues(g_lazy_lookup_enum_values)">,
12+
Desc<"On macOS, lazily look up symbols with dsymForUUID (or an equivalent script/binary) as images appear in the current backtrace.">;
1213
def ClangModulesCachePath: Property<"clang-modules-cache-path", "FileSpec">,
1314
Global,
1415
DefaultStringValue<"">,

lldb/source/Core/ModuleList.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ bool ModuleListProperties::SetEnableExternalLookup(bool new_value) {
104104
return SetPropertyAtIndex(ePropertyEnableExternalLookup, new_value);
105105
}
106106

107-
bool ModuleListProperties::GetEnableBackgroundLookup() const {
108-
const uint32_t idx = ePropertyEnableBackgroundLookup;
109-
return GetPropertyAtIndexAs<bool>(
110-
idx, g_modulelist_properties[idx].default_uint_value != 0);
107+
LazySymbolLookup ModuleListProperties::GetLazySymbolLookup() const {
108+
const uint32_t idx = ePropertyLazySymbolLookup;
109+
return GetPropertyAtIndexAs<lldb::LazySymbolLookup>(
110+
idx, static_cast<lldb::LazySymbolLookup>(
111+
g_modulelist_properties[idx].default_uint_value));
111112
}
112113

113114
FileSpec ModuleListProperties::GetClangModulesCachePath() const {

lldb/source/Symbol/SymbolLocator.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ using namespace lldb;
1818
using namespace lldb_private;
1919

2020
void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
21-
if (!ModuleList::GetGlobalModuleListProperties().GetEnableBackgroundLookup())
22-
return;
23-
2421
static llvm::SmallSet<UUID, 8> g_seen_uuids;
2522
static std::mutex g_mutex;
26-
Debugger::GetThreadPool().async([=]() {
23+
24+
auto lookup = [=]() {
2725
{
2826
std::lock_guard<std::mutex> guard(g_mutex);
2927
if (g_seen_uuids.count(uuid))
@@ -43,5 +41,16 @@ void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
4341
return;
4442

4543
Debugger::ReportSymbolChange(module_spec);
46-
});
44+
};
45+
46+
switch (ModuleList::GetGlobalModuleListProperties().GetLazySymbolLookup()) {
47+
case eLazyLookupOff:
48+
break;
49+
case eLazyLookupBackground:
50+
Debugger::GetThreadPool().async(lookup);
51+
break;
52+
case eLazyLookupForeground:
53+
lookup();
54+
break;
55+
};
4756
}

0 commit comments

Comments
 (0)