Skip to content

Commit 74fc16a

Browse files
authored
[lldb] Expand background symbol download (#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.
1 parent 3d71e41 commit 74fc16a

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-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;
@@ -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 GetSymbolAutoDownload() 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
@@ -1314,6 +1314,12 @@ enum class ChildCacheState {
13141314
///< re-use what we computed the last time we called Update.
13151315
};
13161316

1317+
enum SymbolDownload {
1318+
eSymbolDownloadOff = 0,
1319+
eSymbolDownloadBackground = 1,
1320+
eSymbolDownloadForeground = 2,
1321+
};
1322+
13171323
} // namespace lldb
13181324

13191325
#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
@@ -104,10 +104,15 @@ 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::GetSymbolAutoDownload() const {
108+
// Backward compatibility alias.
109+
if (GetPropertyAtIndexAs<bool>(ePropertyEnableBackgroundLookup, false))
110+
return eSymbolDownloadBackground;
111+
112+
const uint32_t idx = ePropertyAutoDownload;
113+
return GetPropertyAtIndexAs<lldb::SymbolDownload>(
114+
idx, static_cast<lldb::SymbolDownload>(
115+
g_modulelist_properties[idx].default_uint_value));
111116
}
112117

113118
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().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)