JDevlieghere created this revision. JDevlieghere added reviewers: jingham, clayborg, labath. Herald added a subscriber: arphaman. JDevlieghere requested review of this revision.
The symbol table needs to demangle all symbols when building its index. However, the index doesn't need the demangeld symbols after it's done. We keep the demangled symbols in memory for caching purposes, so that if we do need to demangle them again. Most of the time you don't need (all) the demangled symbols again. This patch add a setting to prefer using less memory over p and not cache all the demangled strings that are generated for indexing. If the symbol does get demangled later on, it is cached as usual. This change only impacts the batch demangled operation when building the symbol table index. I was going to keep this setting default to "on" to keep the existing behavior, but Jim argued that the amount of memory we save here is well worth the small performance hit of having to demangle a subset of symbols twice. https://reviews.llvm.org/D118814 Files: lldb/include/lldb/Core/Mangled.h lldb/include/lldb/Core/ModuleList.h lldb/source/Core/CoreProperties.td lldb/source/Core/Mangled.cpp 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 @@ -299,6 +299,8 @@ const uint64_t mangling_limit = ModuleList::GetGlobalModuleListProperties().GetDemanglingLimit(); + const bool store_mangled_name = + ModuleList::GetGlobalModuleListProperties().GetCacheDemangledNames(); // Instantiation of the demangler is expensive, so better use a single one // for all entries during batch processing. @@ -335,7 +337,8 @@ const SymbolType type = symbol->GetType(); if (type == eSymbolTypeCode || type == eSymbolTypeResolver) { - if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name)) + if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name, + store_mangled_name)) RegisterMangledNameEntry(value, class_contexts, backlog, rmc); } } Index: lldb/source/Core/ModuleList.cpp =================================================================== --- lldb/source/Core/ModuleList.cpp +++ lldb/source/Core/ModuleList.cpp @@ -131,6 +131,12 @@ nullptr, idx, g_modulelist_properties[idx].default_uint_value); } +bool ModuleListProperties::GetCacheDemangledNames() const { + const uint32_t idx = ePropertyCacheDemangledNames; + return m_collection_sp->GetPropertyAtIndexAsBoolean( + nullptr, idx, g_modulelist_properties[idx].default_uint_value != 0); +} + bool ModuleListProperties::SetLLDBIndexCachePath(const FileSpec &path) { return m_collection_sp->SetPropertyAtIndexAsFileSpec( nullptr, ePropertyLLDBIndexCachePath, path); Index: lldb/source/Core/Mangled.cpp =================================================================== --- lldb/source/Core/Mangled.cpp +++ lldb/source/Core/Mangled.cpp @@ -195,8 +195,9 @@ // Explicit demangling for scheduled requests during batch processing. This // makes use of ItaniumPartialDemangler's rich demangle info -bool Mangled::DemangleWithRichManglingInfo( - RichManglingContext &context, SkipMangledNameFn *skip_mangled_name) { +bool Mangled::DemangleWithRichManglingInfo(RichManglingContext &context, + SkipMangledNameFn *skip_mangled_name, + bool store_demangled_name) { // Others are not meant to arrive here. ObjC names or C's main() for example // have their names stored in m_demangled, while m_mangled is empty. assert(m_mangled); @@ -218,8 +219,9 @@ // If we got an info, we have a name. Copy to string pool and connect the // counterparts to accelerate later access in GetDemangledName(). context.ParseFullName(); - m_demangled.SetStringWithMangledCounterpart(context.GetBufferRef(), - m_mangled); + if (store_demangled_name) + m_demangled.SetStringWithMangledCounterpart(context.GetBufferRef(), + m_mangled); return true; } else { m_demangled.SetCString(""); @@ -233,8 +235,9 @@ if (char *d = GetMSVCDemangledStr(m_mangled.GetCString())) { // If we got an info, we have a name. Copy to string pool and connect // the counterparts to accelerate later access in GetDemangledName(). - m_demangled.SetStringWithMangledCounterpart(llvm::StringRef(d), - m_mangled); + if (store_demangled_name) + m_demangled.SetStringWithMangledCounterpart(llvm::StringRef(d), + m_mangled); ::free(d); } else { m_demangled.SetCString(""); Index: lldb/source/Core/CoreProperties.td =================================================================== --- lldb/source/Core/CoreProperties.td +++ lldb/source/Core/CoreProperties.td @@ -13,6 +13,10 @@ 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 CacheDemangledNames: Property<"cache-demangled-names", "Boolean">, + Global, + DefaultFalse, + Desc<"Keep the demangled names in memory after indexing the symbol table.">; 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 @@ -59,6 +59,7 @@ FileSpec GetClangModulesCachePath() const; bool SetClangModulesCachePath(const FileSpec &path); uint64_t GetDemanglingLimit() const; + bool GetCacheDemangledNames() const; bool GetEnableExternalLookup() const; bool SetEnableExternalLookup(bool new_value); bool GetEnableLLDBIndexCache() const; Index: lldb/include/lldb/Core/Mangled.h =================================================================== --- lldb/include/lldb/Core/Mangled.h +++ lldb/include/lldb/Core/Mangled.h @@ -249,7 +249,8 @@ /// \return /// True on success, false otherwise. bool DemangleWithRichManglingInfo(RichManglingContext &context, - SkipMangledNameFn *skip_mangled_name); + SkipMangledNameFn *skip_mangled_name, + bool store_demangled_name = true); /// Try to identify the mangling scheme used. /// \param[in] name
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits