|
LLDB mainline
|
A class that handles mangled names. More...
#include "lldb/Core/Mangled.h"
Classes | |
| struct | FunctionNameParts |
| The parts of a mangled function name used in the symbol table's indices. More... | |
Public Types | |
| enum | NamePreference { ePreferMangled , ePreferDemangled , ePreferDemangledWithoutArguments } |
| enum | ManglingScheme : uint8_t { eManglingSchemeNone = 0 , eFirstRegisteredManglingScheme } |
| enum class | FunctionNameKind { TopLevel , InNamespace , Method , ConstructorOrDestructor , Unknown } |
| What a mangled function name says about the function's declaration. More... | |
| using | ManglingSchemeMatcher = bool (*)(llvm::StringRef name) |
Public Member Functions | |
| Mangled ()=default | |
| Default constructor. | |
| Mangled (ConstString name) | |
| Construct with name. | |
| Mangled (llvm::StringRef name) | |
| bool | operator== (const Mangled &rhs) const |
| bool | operator!= (const Mangled &rhs) const |
| operator bool () const | |
| Convert to bool operator. | |
| void | Clear () |
| Clear the mangled and demangled values. | |
| void | Dump (Stream *s) const |
| Dump a description of this object to a Stream s. | |
| void | DumpDebug (Stream *s) const |
| Dump a debug description of this object to a Stream s. | |
| ConstString | GetDemangledName () const |
| Demangled name get accessor. | |
| ConstString | GetDisplayDemangledName () const |
| Display demangled name get accessor. | |
| void | SetDemangledName (ConstString name) |
| void | SetMangledName (ConstString name) |
| ConstString | GetMangledName () const |
| Mangled name get accessor. | |
| ConstString | GetName (NamePreference preference=ePreferDemangled) const |
| Best name get accessor. | |
| bool | NameMatches (ConstString name) const |
| Check if "name" matches either the mangled or demangled name. | |
| bool | NameMatches (const RegularExpression ®ex) const |
| void | SetValue (ConstString name) |
| Set the string value in this object. | |
| lldb::LanguageType | GuessLanguage () const |
| Try to guess the language from the mangling. | |
| bool | Decode (const DataExtractor &data, lldb::offset_t *offset_ptr, const StringTableReader &strtab) |
| Decode a serialized version of this object from data. | |
| void | Encode (DataEncoder &encoder, ConstStringTable &strtab) const |
| Encode this object into a data encoder object. | |
| std::optional< DemangledNameInfo > | ComputeDemangledInfo () const |
Compute the DemangledNameInfo of the demangled name. | |
| ConstString | GetBaseName () const |
| Compute the base name (without namespace/class qualifiers) from the demangled name. | |
Static Public Member Functions | |
| static int | Compare (const Mangled &lhs, const Mangled &rhs) |
| Compare the mangled string values. | |
| static Mangled::ManglingScheme | GetManglingScheme (llvm::StringRef name) |
| Try to identify the mangling scheme used. | |
| static bool | IsMangledName (llvm::StringRef name) |
| static ManglingScheme | RegisterManglingScheme (llvm::ArrayRef< llvm::StringRef > prefixes, lldb::LanguageType language, ManglingSchemeMatcher matches=nullptr) |
Register a mangling scheme for language. | |
| static void | UnregisterManglingScheme (ManglingScheme scheme) |
Stop recognizing the names of scheme, a scheme returned by RegisterManglingScheme(). | |
| static lldb::LanguageType | GetLanguageForManglingScheme (ManglingScheme scheme) |
Returns the language that registered scheme, or eLanguageTypeUnknown if no language did. | |
Static Public Attributes | |
| static constexpr size_t | g_num_mangling_schemes = 16 |
| The number of possible mangling schemes, which sizes the tables that are indexed by ManglingScheme. | |
Private Attributes | |
| ConstString | m_mangled |
| The mangled version of the name. | |
| ConstString | m_demangled |
| Mutable so we can get it on demand with a const version of this object. | |
A class that handles mangled names.
Designed to handle mangled names. The demangled version of any names will be computed when the demangled name is accessed through the Demangled() accessor. This class can also tokenize the demangled version of the name for powerful searches. Functions and symbols could make instances of this class for their mangled names. Uniqued string pools are used for the mangled, demangled, and token string values to allow for faster comparisons and for efficient memory use.
| using lldb_private::Mangled::ManglingSchemeMatcher = bool (*)(llvm::StringRef name) |
|
strong |
| enum lldb_private::Mangled::ManglingScheme : uint8_t |
|
default |
Default constructor.
Initialize with both mangled and demangled names empty.
Referenced by Compare(), operator!=(), and operator==().
|
explicit |
Construct with name.
Constructor with an optional string and auto-detect if name is mangled or not.
| [in] | name | The already const name to copy into this object. |
Definition at line 189 of file Mangled.cpp.
References m_demangled, m_mangled, and SetValue().
|
explicit |
Definition at line 194 of file Mangled.cpp.
References SetValue().
| void Mangled::Clear | ( | ) |
Clear the mangled and demangled values.
Definition at line 208 of file Mangled.cpp.
References m_demangled, and m_mangled.
Compare the mangled string values.
Compares the Mangled::GetName() string in lhs and rhs.
| [in] | lhs | A const reference to the Left Hand Side object to compare. |
| [in] | rhs | A const reference to the Right Hand Side object to compare. |
Definition at line 214 of file Mangled.cpp.
References lldb_private::ConstString::Compare(), ePreferMangled, GetName(), and Mangled().
Referenced by SymbolContextsMightBeEquivalent().
| std::optional< DemangledNameInfo > Mangled::ComputeDemangledInfo | ( | ) | const |
Compute the DemangledNameInfo of the demangled name.
Note that this always re-runs the demangler.
Definition at line 268 of file Mangled.cpp.
References lldb_private::Language::DemangleSymbol(), lldb_private::Language::FindPluginForManglingScheme(), GetManglingScheme(), lldb_private::Language::DemangledName::info, m_mangled, and lldb_private::Language::DemangleOptions::want_info.
Referenced by lldb_private::DemangledNameInfoCache::Get(), and GetBaseName().
| bool Mangled::Decode | ( | const DataExtractor & | data, |
| lldb::offset_t * | offset_ptr, | ||
| const StringTableReader & | strtab ) |
Decode a serialized version of this object from data.
| data | The decoder object that references the serialized data. |
| offset_ptr | A pointer that contains the offset from which the data will be decoded from that gets updated as data gets decoded. |
| strtab | All strings in cache files are put into string tables for efficiency and cache file size reduction. Strings are stored as uint32_t string table offsets in the cache data. |
Definition at line 404 of file Mangled.cpp.
References DemangledOnly, Empty, lldb_private::StringTableReader::Get(), lldb_private::DataExtractor::GetU32(), lldb_private::DataExtractor::GetU8(), m_demangled, m_mangled, MangledAndDemangled, and MangledOnly.
| void Mangled::Dump | ( | Stream * | s | ) | const |
Dump a description of this object to a Stream s.
Dump a Mangled object to stream s. We don't force our demangled name to be computed currently (we don't use the accessor).
| [in] | s | The stream to which to dump the object description. |
Definition at line 320 of file Mangled.cpp.
References lldb_private::Stream::Format(), m_demangled, and m_mangled.
| void Mangled::DumpDebug | ( | Stream * | s | ) | const |
Dump a debug description of this object to a Stream s.
| [in] | s | The stream to which to dump the object description. |
Definition at line 330 of file Mangled.cpp.
References m_demangled, m_mangled, lldb_private::Stream::Printf(), and lldb_private::Stream::PutCString().
| void Mangled::Encode | ( | DataEncoder & | file, |
| ConstStringTable & | strtab ) const |
Encode this object into a data encoder object.
The encoding format for the Mangled object is as follows:
This allows this object to be serialized to disk.
| encoder | A data encoder object that serialized bytes will be encoded into. |
| strtab | All strings in cache files are put into string tables for efficiency and cache file size reduction. Strings are stored as uint32_t string table offsets in the cache data. |
uint8_t encoding; char str1[]; (only if DemangledOnly, MangledOnly) char str2[]; (only if MangledAndDemangled)
The strings are stored as null-terminated UTF8 strings and str1 and str2 are only saved if we need them based on the encoding.
Some mangled names have a mangled name that can be demangled by a plugin. These kinds of mangled objects know when the mangled and demangled names are the counterparts for each other. This is done because demangling is very expensive and avoiding demangling the same name twice saves us a lot of compute time. For these kinds of names we only need to save the mangled name and have the encoding set to "MangledOnly".
If a mangled object has only a demangled name, then we save only that string and have the encoding set to "DemangledOnly".
Some mangled objects have both mangled and demangled names, but the demangled name can not be computed from the mangled name. This is often used for runtime named, like Objective C runtime V2 and V3 names. Both these names must be saved and the encoding is set to "MangledAndDemangled".
For a Mangled object with no names, we only need to set the encoding to "Empty" and not store any string values.
Definition at line 455 of file Mangled.cpp.
References lldb_private::ConstStringTable::Add(), lldb_private::DataEncoder::AppendU32(), lldb_private::DataEncoder::AppendU8(), DemangledOnly, Empty, m_demangled, m_mangled, MangledAndDemangled, and MangledOnly.
| ConstString Mangled::GetBaseName | ( | ) | const |
Compute the base name (without namespace/class qualifiers) from the demangled name.
For a demangled name like "ns::MyClass<int>::templateFunc", this returns just "templateFunc".
Definition at line 487 of file Mangled.cpp.
References ComputeDemangledInfo(), GetDemangledName(), and lldb_private::ConstString::GetStringRef().
| ConstString Mangled::GetDemangledName | ( | ) | const |
Demangled name get accessor.
Definition at line 238 of file Mangled.cpp.
References lldb_private::Language::FindPluginForManglingScheme(), GetManglingScheme(), m_demangled, m_mangled, and lldb_private::Language::DemangledName::name.
Referenced by lldb_private::Symtab::AppendSymbolNamesToMap(), BuildDemangledCodeSymbolIndex(), lldb_private::Symbol::Compare(), lldb_private::CPlusPlusLanguage::FindBestAlternateFunctionMangledName(), lldb_private::ItaniumABIRuntime::FindTypeInfoWithDemangling(), GetAndValidateInfo(), GetBaseName(), lldb_private::CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(), lldb_private::Language::GetDemangledFunctionNameWithoutArguments(), lldb::SBTypeMemberFunction::GetDemangledName(), lldb_private::Language::GetDisplayDemangledName(), GetDisplayDemangledName(), SymbolFilePDB::GetMangledForPDBFunc(), GetName(), lldb_private::MicrosoftABIRuntime::GetTypeInfo(), lldb_private::CPPLanguageRuntime::GetVTableInfoEntry(), lldb_private::Symtab::InitNameIndexes(), lldb_private::ItaniumABIRuntime::IsVTableSymbol(), lldb_private::MicrosoftABIRuntime::IsVTableSymbol(), NameMatches(), NameMatches(), lldb_private::Module::LookupInfo::NameMatchesLookupInfo(), operator<<(), operator==(), ObjectFileELF::ParseSymbols(), ObjectFileMachO::ParseSymtab(), lldb_private::PersistentExpressionState::RegisterExecutionUnit(), and lldb_private::ObjCLanguage::SymbolNameFitsToLanguage().
| ConstString Mangled::GetDisplayDemangledName | ( | ) | const |
Display demangled name get accessor.
Definition at line 282 of file Mangled.cpp.
References lldb_private::Language::FindPlugin(), GetDemangledName(), and GuessLanguage().
Referenced by lldb_private::CommandObjectCPlusPlusDemangle::DoExecute(), and lldb_private::Symbol::GetDisplayName().
|
static |
Returns the language that registered scheme, or eLanguageTypeUnknown if no language did.
Definition at line 174 of file Mangled.cpp.
References GetManglingSchemeRegistry().
Referenced by lldb_private::Language::FindPluginForManglingScheme(), and GuessLanguage().
|
inline |
Mangled name get accessor.
Definition at line 169 of file Mangled.h.
References m_mangled.
Referenced by lldb_private::ClangExpressionDeclMap::AddOneFunction(), lldb_private::plugin::dwarf::SymbolFileWasm::AddSymbols(), lldb_private::Symtab::AppendSymbolNamesToMap(), BuildDemangledCodeSymbolIndex(), lldb_private::Symbol::Compare(), lldb_private::DemangledNameInfoCache::Get(), GetAndValidateInfo(), lldb_private::CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(), lldb_private::Language::GetDemangledFunctionNameWithoutArguments(), lldb_private::BreakpointLocation::GetDescription(), lldb_private::Symtab::InitNameIndexes(), lldb_private::CPPLanguageRuntime::IsSymbolARuntimeThunk(), operator<<(), ObjectFileELF::ParseSymbols(), and lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage().
|
static |
Try to identify the mangling scheme used.
| [in] | name | The name we are attempting to identify the mangling scheme for. |
name, otherwise the scheme that does. Definition at line 182 of file Mangled.cpp.
References eManglingSchemeNone, and GetManglingSchemeRegistry().
Referenced by ComputeDemangledInfo(), lldb_private::plugin::dwarf::SymbolFileDWARF::FindGlobalVariables(), GetDemangledName(), GuessLanguage(), lldb_private::Symtab::InitNameIndexes(), IsMangledName(), lldb_private::Module::LookupInfo::NameMatchesLookupInfo(), DWARFASTParserClang::ParseFunctionFromDWARF(), and lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage().
| ConstString Mangled::GetName | ( | Mangled::NamePreference | preference = ePreferDemangled | ) | const |
Best name get accessor.
| [in] | preference | Which name would you prefer to get? |
Definition at line 297 of file Mangled.cpp.
References ePreferDemangled, ePreferDemangledWithoutArguments, ePreferMangled, lldb_private::Language::FindPlugin(), GetDemangledName(), GuessLanguage(), and m_mangled.
Referenced by lldb_private::plugin::dwarf::SymbolFileWasm::AddSymbols(), Compare(), lldb_private::Symbol::Dump(), lldb_private::DynamicLoaderDarwin::FindEquivalentSymbols(), lldb_private::plugin::dwarf::SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap(), lldb_private::Symbol::GetName(), lldb_private::Symbol::GetNameNoArguments(), DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(), DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(), lldb_private::DynamicLoaderDarwin::GetStepThroughTrampolinePlan(), GetSymbolDeclarationFromAddress(), ObjectFileELF::ParseSymbols(), ObjectFileMachO::ParseSymtab(), PrintFunctionNameWithArgs(), and PrintFunctionNameWithArgs().
| lldb::LanguageType Mangled::GuessLanguage | ( | ) | const |
Try to guess the language from the mangling.
For a mangled name to have a language it must have both a mangled and a demangled name and it can be guessed from the mangling what the language is. Note: this will return C++ for any language that uses Itanium ABI mangling.
Standard C function names will return eLanguageTypeUnknown because they aren't mangled and it isn't clear what language the name represents (there will be no mangled name).
Definition at line 344 of file Mangled.cpp.
References lldb_private::Continue, lldb::eLanguageTypeUnknown, lldb_private::Language::ForEach(), GetLanguageForManglingScheme(), GetManglingScheme(), l, m_mangled, and lldb_private::Stop.
Referenced by lldb_private::CommandObjectCPlusPlusDemangle::DoExecute(), GetDisplayDemangledName(), lldb_private::Symbol::GetLanguage(), GetName(), and lldb_private::StackFrame::GuessLanguage().
|
static |
Definition at line 178 of file Mangled.cpp.
References eManglingSchemeNone, and GetManglingScheme().
Referenced by lldb_private::ClangExpressionDeclMap::AddOneFunction(), SymbolFilePDB::CacheFunctionNames(), lldb_private::npdb::SymbolFileNativePDB::CacheGlobalBaseNames(), lldb_private::npdb::SymbolFileNativePDB::CreateGlobalVariable(), ExtractMangledNameFromFunctionCallLabel(), lldb_private::CPlusPlusLanguage::GetFunctionNameInfo(), and SetValue().
| bool Mangled::NameMatches | ( | const RegularExpression & | regex | ) | const |
Definition at line 288 of file Mangled.cpp.
References lldb_private::RegularExpression::Execute(), GetDemangledName(), lldb_private::ConstString::GetStringRef(), and m_mangled.
|
inline |
Check if "name" matches either the mangled or demangled name.
| [in] | name | A name to match against both strings. |
Definition at line 189 of file Mangled.h.
References GetDemangledName(), and m_mangled.
Referenced by lldb_private::plugin::dwarf::AppleDWARFIndex::GetGlobalVariables(), lldb_private::plugin::dwarf::DebugNamesDWARFIndex::GetGlobalVariables(), and lldb_private::SymbolContextSpecifier::SymbolContextMatches().
|
explicit |
Convert to bool operator.
This allows code to check any Mangled objects to see if they contain anything valid using code such as:
Definition at line 205 of file Mangled.cpp.
References m_demangled, and m_mangled.
Definition at line 90 of file Mangled.h.
References GetDemangledName(), m_mangled, and Mangled().
|
static |
Register a mangling scheme for language.
All mangled names in this scheme start with one of prefixes. If the prefixes are insufficient to unambiguously identify a scheme, matches checks the rest of each name.
Registering the same scheme again returns the same scheme.
Definition at line 163 of file Mangled.cpp.
References GetManglingSchemeRegistry().
Referenced by lldb_private::CPlusPlusLanguage::Initialize(), lldb_private::DLanguage::Initialize(), and lldb_private::RustLanguage::Initialize().
|
inline |
Definition at line 161 of file Mangled.h.
References m_demangled.
Referenced by ObjectFilePECOFF::AppendFromExportTable(), SymbolFilePDB::GetMangledForPDBFunc(), DWARFASTParserClang::ParseFunctionFromDWARF(), DWARFASTParserFortran::ParseFunctionFromDWARF(), ObjectFileELF::ParseSymbols(), and ObjectFileMachO::ParseSymtab().
|
inline |
Definition at line 163 of file Mangled.h.
References m_mangled.
Referenced by lldb_private::plugin::dwarf::SymbolFileWasm::AddSymbols(), SymbolFilePDB::GetMangledForPDBFunc(), DWARFASTParserClang::ParseFunctionFromDWARF(), DWARFASTParserFortran::ParseFunctionFromDWARF(), ObjectFileELF::ParseSymbols(), and ObjectFileMachO::ParseSymtab().
| void Mangled::SetValue | ( | ConstString | name | ) |
Set the string value in this object.
This version auto detects if the string is mangled by inspecting the string value and looking for the prefixes of the registered mangling schemes.
| [in] | name | The already const version of the name for this object. |
Definition at line 219 of file Mangled.cpp.
References lldb_private::ConstString::GetStringRef(), IsMangledName(), m_demangled, and m_mangled.
Referenced by ObjectFilePECOFF::AppendFromCOFFSymbolTable(), ObjectFilePECOFF::AppendFromExportTable(), SymbolFilePDB::GetMangledForPDBFunc(), lldb_private::breakpad::SymbolFileBreakpad::GetOrCreateFunction(), Mangled(), Mangled(), DWARFASTParserClang::ParseFunctionFromDWARF(), ObjectFileCOFF::ParseSymtab(), ObjectFileMachO::ParseSymtab(), and ObjectFileXCOFF::ParseSymtab().
|
static |
Stop recognizing the names of scheme, a scheme returned by RegisterManglingScheme().
Definition at line 169 of file Mangled.cpp.
References GetManglingSchemeRegistry().
Referenced by lldb_private::CPlusPlusLanguage::Terminate(), lldb_private::DLanguage::Terminate(), and lldb_private::RustLanguage::Terminate().
|
staticconstexpr |
The number of possible mangling schemes, which sizes the tables that are indexed by ManglingScheme.
Definition at line 51 of file Mangled.h.
Referenced by lldb_private::Language::FindPluginForManglingScheme(), and lldb_private::Symtab::InitNameIndexes().
|
mutableprivate |
Mutable so we can get it on demand with a const version of this object.
Definition at line 313 of file Mangled.h.
Referenced by Clear(), Decode(), Dump(), DumpDebug(), Encode(), GetDemangledName(), Mangled(), operator bool(), SetDemangledName(), and SetValue().
|
private |
The mangled version of the name.
Definition at line 309 of file Mangled.h.
Referenced by Clear(), ComputeDemangledInfo(), Decode(), Dump(), DumpDebug(), Encode(), GetDemangledName(), GetMangledName(), GetName(), GuessLanguage(), Mangled(), NameMatches(), NameMatches(), operator bool(), operator==(), SetMangledName(), and SetValue().