Skip to content

Commit d0696a2

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.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.
1 parent 1833de3 commit d0696a2

File tree

6 files changed

+55
-14
lines changed

6 files changed

+55
-14
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_download_enum_values[] = {
51+
{
52+
lldb::eSymbolDownloadOff,
53+
"off",
54+
"Disable 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;
@@ -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::SymbolDownload GetSymbolDownload() 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 SymbolDownload {
1309+
eSymbolDownloadOff = 0,
1310+
eSymbolDownloadBackground = 1,
1311+
eSymbolDownloadForeground = 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 Download: Property<"download", "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<"eSymbolDownloadOff">,
11+
EnumValues<"OptionEnumValues(g_download_enum_values)">,
12+
Desc<"On macOS, lazily download 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+
SymbolDownload ModuleListProperties::GetSymbolDownload() const {
108+
const uint32_t idx = ePropertyDownload;
109+
return GetPropertyAtIndexAs<lldb::SymbolDownload>(
110+
idx, static_cast<lldb::SymbolDownload>(
111+
g_modulelist_properties[idx].default_uint_value));
111112
}
112113

113114
FileSpec ModuleListProperties::GetClangModulesCachePath() const {

lldb/source/Host/common/Host.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ llvm::Error Host::OpenFileInExternalEditor(llvm::StringRef editor,
550550
}
551551

552552
bool Host::IsInteractiveGraphicSession() { return false; }
553+
554+
bool Host::IsNetworkLimited() { return false; }
553555
#endif
554556

555557
std::unique_ptr<Connection> Host::CreateDefaultConnection(llvm::StringRef url) {

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().GetSymbolDownload()) {
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)