[Lldb-commits] [PATCH] D118812: [lldb] Add a setting to skip long mangled names

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 2 09:50:57 PST 2022


JDevlieghere created this revision.
JDevlieghere added reviewers: jingham, clayborg, labath.
JDevlieghere requested review of this revision.

Libraries which rely heavily on templates (e.g. boost) can generate extremely long symbol names, with mangled names in the 10 000 of characters. These symbols take a long time to demangle and can results in unmangled names that are several megabytes in size. This patch adds a setting to skip past these symbols when indexing the symbol table to speed up launch/attach times and keep memory usage in check.

I arbitrarily picked 10000 as the default value which seems large enough to not affect most workflows.


https://reviews.llvm.org/D118812

Files:
  lldb/include/lldb/Core/ModuleList.h
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/ModuleList.cpp
  lldb/source/Symbol/Symtab.cpp


Index: lldb/source/Symbol/Symtab.cpp
===================================================================
--- lldb/source/Symbol/Symtab.cpp
+++ lldb/source/Symbol/Symtab.cpp
@@ -297,11 +297,19 @@
     std::vector<std::pair<NameToIndexMap::Entry, const char *>> backlog;
     backlog.reserve(num_symbols / 2);
 
+    const uint64_t mangling_limit =
+        ModuleList::GetGlobalModuleListProperties().GetDemanglingLimit();
+
     // Instantiation of the demangler is expensive, so better use a single one
     // for all entries during batch processing.
     RichManglingContext rmc;
     for (uint32_t value = 0; value < num_symbols; ++value) {
       Symbol *symbol = &m_symbols[value];
+      Mangled &mangled = symbol->GetMangled();
+
+      if (mangling_limit)
+        if (mangled.GetMangledName().GetLength() > mangling_limit)
+          continue;
 
       // Don't let trampolines get into the lookup by name map If we ever need
       // the trampoline symbols to be searchable by name we can remove this and
@@ -314,7 +322,6 @@
 
       // If the symbol's name string matched a Mangled::ManglingScheme, it is
       // stored in the mangled field.
-      Mangled &mangled = symbol->GetMangled();
       if (ConstString name = mangled.GetMangledName()) {
         name_to_index.Append(name, value);
 
Index: lldb/source/Core/ModuleList.cpp
===================================================================
--- lldb/source/Core/ModuleList.cpp
+++ lldb/source/Core/ModuleList.cpp
@@ -125,6 +125,12 @@
       ->GetCurrentValue();
 }
 
+uint64_t ModuleListProperties::GetDemanglingLimit() const {
+  const uint32_t idx = ePropertyDemanglingLimit;
+  return m_collection_sp->GetPropertyAtIndexAsUInt64(
+      nullptr, idx, g_modulelist_properties[idx].default_uint_value);
+}
+
 bool ModuleListProperties::SetLLDBIndexCachePath(const FileSpec &path) {
   return m_collection_sp->SetPropertyAtIndexAsFileSpec(
       nullptr, ePropertyLLDBIndexCachePath, path);
Index: lldb/source/Core/CoreProperties.td
===================================================================
--- lldb/source/Core/CoreProperties.td
+++ lldb/source/Core/CoreProperties.td
@@ -9,6 +9,10 @@
     Global,
     DefaultStringValue<"">,
     Desc<"The path to the clang modules cache directory (-fmodules-cache-path).">;
+  def DemanglingLimit: Property<"demangling-max-length", "UInt64">,
+    Global,
+    DefaultUnsignedValue<1000>,
+    Desc<"The maximum length of the mangled symbol name. Mangled symbols that exceed this threshold will not be demangled when indexing the symbol table. A value of 0 means no limit.">;
   def SymLinkPaths: Property<"debug-info-symlink-paths", "FileSpecList">,
     Global,
     DefaultStringValue<"">,
Index: lldb/include/lldb/Core/ModuleList.h
===================================================================
--- lldb/include/lldb/Core/ModuleList.h
+++ lldb/include/lldb/Core/ModuleList.h
@@ -58,6 +58,7 @@
 
   FileSpec GetClangModulesCachePath() const;
   bool SetClangModulesCachePath(const FileSpec &path);
+  uint64_t GetDemanglingLimit() const;
   bool GetEnableExternalLookup() const;
   bool SetEnableExternalLookup(bool new_value);
   bool GetEnableLLDBIndexCache() const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118812.405314.patch
Type: text/x-patch
Size: 3201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220202/bafe67cc/attachment.bin>


More information about the lldb-commits mailing list