https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/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.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.

>From 3b1818b83c18e50e1ad3f0db06089349b8525f6c Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jo...@devlieghere.com>
Date: Tue, 6 Feb 2024 10:07:12 -0800
Subject: [PATCH] [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.
---
 lldb/include/lldb/Core/ModuleList.h   | 23 ++++++++++++++++++++++-
 lldb/include/lldb/lldb-enumerations.h |  6 ++++++
 lldb/source/Core/CoreProperties.td    |  7 ++++---
 lldb/source/Core/ModuleList.cpp       |  9 +++++----
 lldb/source/Symbol/SymbolLocator.cpp  | 19 ++++++++++++++-----
 5 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index d78f7c5ef3f706..5c19cbc1e799c7 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -47,6 +47,26 @@ class UUID;
 class VariableList;
 struct ModuleFunctionSearchOptions;
 
+static constexpr OptionEnumValueElement g_lazy_lookup_enum_values[] = {
+    {
+        lldb::eLazyLookupOff,
+        "off",
+        "Disable lazy symbol lookup.",
+    },
+    {
+        lldb::eLazyLookupBackground,
+        "background",
+        "Lazily look up symbols in the background without blocking the "
+        "debugger.",
+    },
+    {
+        lldb::eLazyLookupForeground,
+        "foreground",
+        "Lazily look up symbols in the foreground and block the debugger until 
"
+        "they're found.",
+    },
+};
+
 class ModuleListProperties : public Properties {
   mutable llvm::sys::RWMutex m_symlink_paths_mutex;
   PathMappingList m_symlink_paths;
@@ -60,7 +80,6 @@ class ModuleListProperties : public Properties {
   bool SetClangModulesCachePath(const FileSpec &path);
   bool GetEnableExternalLookup() const;
   bool SetEnableExternalLookup(bool new_value);
-  bool GetEnableBackgroundLookup() const;
   bool GetEnableLLDBIndexCache() const;
   bool SetEnableLLDBIndexCache(bool new_value);
   uint64_t GetLLDBIndexCacheMaxByteSize();
@@ -71,6 +90,8 @@ class ModuleListProperties : public Properties {
 
   bool GetLoadSymbolOnDemand();
 
+  lldb::LazySymbolLookup GetLazySymbolLookup() const;
+
   PathMappingList GetSymlinkMappings() const;
 };
 
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 392d333c23a447..c1f9fab5244997 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -1305,6 +1305,12 @@ enum CompletionType {
   eTerminatorCompletion = (1ul << 27)
 };
 
+enum LazySymbolLookup {
+  eLazyLookupOff = 0,
+  eLazyLookupBackground = 1,
+  eLazyLookupForeground = 2,
+};
+
 } // namespace lldb
 
 #endif // LLDB_LLDB_ENUMERATIONS_H
diff --git a/lldb/source/Core/CoreProperties.td 
b/lldb/source/Core/CoreProperties.td
index 8d81967bdb50a4..fcf89bd412b844 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
     Global,
     DefaultTrue,
     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.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,
     Global,
-    DefaultFalse,
-    Desc<"On macOS, enable calling dsymForUUID (or an equivalent 
script/binary) in the background to locate symbol files that weren't found.">;
+    DefaultEnumValue<"eLazyLookupOff">,
+    EnumValues<"OptionEnumValues(g_lazy_lookup_enum_values)">,
+    Desc<"On macOS, lazily look up symbols with dsymForUUID (or an equivalent 
script/binary) as images appear in the current backtrace.">;
   def ClangModulesCachePath: Property<"clang-modules-cache-path", "FileSpec">,
     Global,
     DefaultStringValue<"">,
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index b7f393636ba28d..a7ab7c56eb7a12 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -104,10 +104,11 @@ bool ModuleListProperties::SetEnableExternalLookup(bool 
new_value) {
   return SetPropertyAtIndex(ePropertyEnableExternalLookup, new_value);
 }
 
-bool ModuleListProperties::GetEnableBackgroundLookup() const {
-  const uint32_t idx = ePropertyEnableBackgroundLookup;
-  return GetPropertyAtIndexAs<bool>(
-      idx, g_modulelist_properties[idx].default_uint_value != 0);
+LazySymbolLookup ModuleListProperties::GetLazySymbolLookup() const {
+  const uint32_t idx = ePropertyLazySymbolLookup;
+  return GetPropertyAtIndexAs<lldb::LazySymbolLookup>(
+      idx, static_cast<lldb::LazySymbolLookup>(
+               g_modulelist_properties[idx].default_uint_value));
 }
 
 FileSpec ModuleListProperties::GetClangModulesCachePath() const {
diff --git a/lldb/source/Symbol/SymbolLocator.cpp 
b/lldb/source/Symbol/SymbolLocator.cpp
index 918f13ed9c193f..288c986cbdc285 100644
--- a/lldb/source/Symbol/SymbolLocator.cpp
+++ b/lldb/source/Symbol/SymbolLocator.cpp
@@ -18,12 +18,10 @@ using namespace lldb;
 using namespace lldb_private;
 
 void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
-  if (!ModuleList::GetGlobalModuleListProperties().GetEnableBackgroundLookup())
-    return;
-
   static llvm::SmallSet<UUID, 8> g_seen_uuids;
   static std::mutex g_mutex;
-  Debugger::GetThreadPool().async([=]() {
+
+  auto lookup = [=]() {
     {
       std::lock_guard<std::mutex> guard(g_mutex);
       if (g_seen_uuids.count(uuid))
@@ -43,5 +41,16 @@ void SymbolLocator::DownloadSymbolFileAsync(const UUID 
&uuid) {
       return;
 
     Debugger::ReportSymbolChange(module_spec);
-  });
+  };
+
+  switch (ModuleList::GetGlobalModuleListProperties().GetLazySymbolLookup()) {
+  case eLazyLookupOff:
+    break;
+  case eLazyLookupBackground:
+    Debugger::GetThreadPool().async(lookup);
+    break;
+  case eLazyLookupForeground:
+    lookup();
+    break;
+  };
 }

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to