LLDB mainline
|
A class that handles mangled names. More...
#include "lldb/Core/Mangled.h"
Public Types | |
enum | NamePreference { ePreferMangled , ePreferDemangled , ePreferDemangledWithoutArguments } |
enum | ManglingScheme { eManglingSchemeNone = 0 , eManglingSchemeMSVC , eManglingSchemeItanium , eManglingSchemeRustV0 , eManglingSchemeD , eManglingSchemeSwift } |
using | SkipMangledNameFn = bool(llvm::StringRef, ManglingScheme) |
Function signature for filtering mangled names. | |
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 () |
Mangled name get accessor. | |
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 |
size_t | MemorySize () const |
Get the memory cost of this object. | |
void | SetValue (ConstString name) |
Set the string value in this object. | |
lldb::LanguageType | GuessLanguage () const |
Try to guess the language from the mangling. | |
bool | GetRichManglingInfo (RichManglingContext &context, SkipMangledNameFn *skip_mangled_name) |
Get rich mangling information. | |
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. | |
Static Public Member Functions | |
static int | Compare (const Mangled &lhs, const Mangled &rhs) |
Compare the mangled string values. | |
static Mangled::ManglingScheme | GetManglingScheme (llvm::StringRef const name) |
Try to identify the mangling scheme used. | |
Private Attributes | |
ConstString | m_mangled |
Mangled member variables. | |
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::SkipMangledNameFn = bool(llvm::StringRef, ManglingScheme) |
|
default |
Default constructor.
Initialize with both mangled and demangled names empty.
|
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 90 of file Mangled.cpp.
References SetValue().
|
explicit |
Definition at line 95 of file Mangled.cpp.
References SetValue().
void Mangled::Clear | ( | ) |
Clear the mangled and demangled values.
Definition at line 109 of file Mangled.cpp.
References lldb_private::ConstString::Clear(), m_demangled, and m_mangled.
Referenced by lldb_private::Symbol::Clear().
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 115 of file Mangled.cpp.
References lldb_private::ConstString::Compare(), ePreferMangled, and GetName().
Referenced by SymbolContextsMightBeEquivalent().
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 443 of file Mangled.cpp.
References lldb_private::ConstString::Clear(), DemangledOnly, Empty, lldb_private::StringTableReader::Get(), lldb_private::DataExtractor::GetU32(), lldb_private::DataExtractor::GetU8(), m_demangled, m_mangled, MangledAndDemangled, MangledOnly, and lldb_private::ConstString::SetString().
Referenced by lldb_private::Symbol::Decode().
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 358 of file Mangled.cpp.
References lldb_private::ConstString::AsCString(), m_demangled, m_mangled, and lldb_private::Stream::Printf().
Referenced by lldb_private::Function::Dump(), and lldb_private::InlineFunctionInfo::Dump().
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 370 of file Mangled.cpp.
References lldb_private::ConstString::DumpDebug(), m_demangled, m_mangled, and lldb_private::Stream::Printf().
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 the built in demanglers. 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 obejct 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 493 of file Mangled.cpp.
References lldb_private::ConstStringTable::Add(), lldb_private::DataEncoder::AppendU32(), lldb_private::DataEncoder::AppendU8(), DemangledOnly, Empty, lldb_private::ConstString::GetMangledCounterpart(), m_demangled, m_mangled, MangledAndDemangled, and MangledOnly.
Referenced by lldb_private::Symbol::Encode().
ConstString Mangled::GetDemangledName | ( | ) | const |
Demangled name get accessor.
Definition at line 270 of file Mangled.cpp.
References eManglingSchemeD, eManglingSchemeItanium, eManglingSchemeMSVC, eManglingSchemeNone, eManglingSchemeRustV0, eManglingSchemeSwift, lldb_private::ConstString::GetCString(), GetDLangDemangledStr(), GetItaniumDemangledStr(), lldb_private::ConstString::GetMangledCounterpart(), GetManglingScheme(), GetMSVCDemangledStr(), GetRustV0DemangledStr(), lldb_private::ConstString::GetStringRef(), lldb_private::ConstString::IsNull(), m_demangled, m_mangled, lldb_private::ConstString::SetCString(), and lldb_private::ConstString::SetStringWithMangledCounterpart().
Referenced by lldb_private::Symtab::AppendSymbolNamesToMap(), lldb_private::Symbol::Compare(), lldb_private::CPlusPlusLanguage::FindBestAlternateFunctionMangledName(), lldb_private::Language::GetDemangledFunctionNameWithoutArguments(), lldb_private::CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(), lldb::SBTypeMemberFunction::GetDemangledName(), lldb_private::Symbol::GetDescription(), GetDisplayDemangledName(), lldb_private::Language::GetDisplayDemangledName(), SymbolFilePDB::GetMangledForPDBFunc(), GetName(), lldb_private::ItaniumABILanguageRuntime::GetTypeInfo(), lldb_private::ItaniumABILanguageRuntime::GetVTableInfo(), lldb_private::Symtab::InitNameIndexes(), lldb_private::Symbol::IsSyntheticWithAutoGeneratedName(), NameMatches(), lldb_private::Module::LookupInfo::NameMatchesLookupInfo(), operator<<(), operator==(), ObjectFileELF::ParseSymbols(), ObjectFileMachO::ParseSymtab(), lldb_private::PersistentExpressionState::RegisterExecutionUnit(), lldb_private::ObjCLanguage::SymbolNameFitsToLanguage(), and lldb_private::ValueObjectVTable::UpdateValue().
ConstString Mangled::GetDisplayDemangledName | ( | ) | const |
Display demangled name get accessor.
Definition at line 320 of file Mangled.cpp.
References lldb_private::Language::FindPlugin(), GetDemangledName(), and GuessLanguage().
Referenced by CommandObjectMultiwordItaniumABI_Demangle::DoExecute(), lldb::SBFunction::GetDisplayName(), lldb::SBSymbol::GetDisplayName(), lldb_private::InlineFunctionInfo::GetDisplayName(), lldb_private::Function::GetDisplayName(), and lldb_private::Symbol::GetDisplayName().
|
inline |
Mangled name get accessor.
Definition at line 145 of file Mangled.h.
References m_mangled.
Referenced by lldb_private::ClangExpressionDeclMap::AddOneFunction(), lldb_private::Symtab::AppendSymbolNamesToMap(), lldb_private::Symbol::Compare(), lldb_private::SymbolContext::FindBestGlobalDataSymbol(), lldb_private::Language::GetDemangledFunctionNameWithoutArguments(), lldb_private::CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(), lldb_private::BreakpointLocation::GetDescription(), lldb_private::Function::GetDescription(), lldb_private::Symbol::GetDescription(), lldb::SBFunction::GetMangledName(), lldb::SBSymbol::GetMangledName(), lldb_private::Symtab::InitNameIndexes(), operator<<(), ObjectFileELF::ParseSymbols(), and lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage().
|
inline |
|
static |
Try to identify the mangling scheme used.
[in] | name | The name we are attempting to identify the mangling scheme for. |
Definition at line 42 of file Mangled.cpp.
References eManglingSchemeD, eManglingSchemeItanium, eManglingSchemeMSVC, eManglingSchemeNone, eManglingSchemeRustV0, and eManglingSchemeSwift.
Referenced by cstring_is_mangled(), lldb_private::plugin::dwarf::SymbolFileDWARF::FindGlobalVariables(), GetDemangledName(), GetRichManglingInfo(), lldb_private::CPlusPlusLanguage::IsCPPMangledName(), and lldb_private::Module::LookupInfo::NameMatchesLookupInfo().
ConstString Mangled::GetName | ( | Mangled::NamePreference | preference = ePreferDemangled | ) | const |
Best name get accessor.
[in] | preference | Which name would you prefer to get? |
Definition at line 335 of file Mangled.cpp.
References ePreferDemangled, ePreferDemangledWithoutArguments, ePreferMangled, lldb_private::Language::FindPlugin(), GetDemangledName(), GuessLanguage(), and m_mangled.
Referenced by Compare(), lldb_private::Symbol::Dump(), lldb_private::InlineFunctionInfo::DumpStopContext(), lldb_private::DynamicLoaderDarwin::FindEquivalentSymbols(), lldb_private::FormatEntity::Format(), lldb_private::plugin::dwarf::SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap(), lldb_private::SymbolContext::GetFunctionName(), lldb_private::InlineFunctionInfo::GetName(), lldb_private::Function::GetName(), lldb_private::Symbol::GetName(), lldb_private::Variable::GetName(), lldb_private::Function::GetNameNoArguments(), lldb_private::Symbol::GetNameNoArguments(), DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(), lldb_private::DynamicLoaderDarwin::GetStepThroughTrampolinePlan(), DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(), GetSymbolDeclarationFromAddress(), ObjectFileELF::ParseSymbols(), and ObjectFileMachO::ParseSymtab().
bool Mangled::GetRichManglingInfo | ( | RichManglingContext & | context, |
SkipMangledNameFn * | skip_mangled_name | ||
) |
Get rich mangling information.
This is optimized for batch processing while populating a name index. To get the pure demangled name string for a single entity, use GetDemangledName() instead.
For names that match the Itanium mangling scheme, this uses LLVM's ItaniumPartialDemangler. All other names fall back to LLDB's builtin parser currently.
This function is thread-safe when used with different context instances in different threads.
[in] | context | The context for this function. A single instance can be stack- allocated in the caller's frame and used for multiple calls. |
[in] | skip_mangled_name | A filtering function for skipping entities based on name and mangling scheme. This can be null if unused. |
Definition at line 210 of file Mangled.cpp.
References eManglingSchemeD, eManglingSchemeItanium, eManglingSchemeMSVC, eManglingSchemeNone, eManglingSchemeRustV0, eManglingSchemeSwift, lldb_private::RichManglingContext::FromCxxMethodName(), lldb_private::RichManglingContext::FromItaniumName(), lldb_private::ConstString::GetMangledCounterpart(), GetManglingScheme(), GetMSVCDemangledStr(), lldb_private::ConstString::GetStringRef(), lldb_private::ConstString::IsEmpty(), m_demangled, m_mangled, lldb_private::ConstString::SetCString(), and lldb_private::ConstString::SetStringWithMangledCounterpart().
Referenced by lldb_private::Symtab::InitNameIndexes().
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 391 of file Mangled.cpp.
References lldb::eLanguageTypeUnknown, lldb_private::Language::ForEach(), and l.
Referenced by CommandObjectMultiwordItaniumABI_Demangle::DoExecute(), GetDisplayDemangledName(), lldb_private::Function::GetLanguage(), lldb_private::Symbol::GetLanguage(), lldb_private::SymbolContext::GetLanguage(), lldb_private::Variable::GetLanguage(), GetName(), and lldb_private::StackFrame::GuessLanguage().
size_t Mangled::MemorySize | ( | ) | const |
Get the memory cost of this object.
Return the size in bytes that this object takes in memory. This returns the size in bytes of this object, not any shared string values it may refer to.
Definition at line 381 of file Mangled.cpp.
References m_demangled, m_mangled, and lldb_private::ConstString::MemorySize().
Referenced by lldb_private::InlineFunctionInfo::MemorySize().
bool Mangled::NameMatches | ( | const RegularExpression & | regex | ) | const |
Definition at line 326 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 171 of file Mangled.h.
References GetDemangledName(), and m_mangled.
Referenced by lldb_private::plugin::dwarf::AppleDWARFIndex::GetGlobalVariables(), lldb_private::plugin::dwarf::DebugNamesDWARFIndex::GetGlobalVariables(), lldb_private::Variable::NameMatches(), 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 106 of file Mangled.cpp.
|
inline |
|
inline |
Definition at line 66 of file Mangled.h.
References GetDemangledName(), and m_mangled.
|
inline |
Definition at line 137 of file Mangled.h.
References m_demangled.
Referenced by ObjectFilePECOFF::AppendFromExportTable(), SymbolFilePDB::GetMangledForPDBFunc(), ObjectFileELF::ParseSymbols(), ObjectFileMachO::ParseSymtab(), and lldb_private::Symbol::SynthesizeNameIfNeeded().
|
inline |
Definition at line 139 of file Mangled.h.
References m_mangled.
Referenced by SymbolFilePDB::GetMangledForPDBFunc(), 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 common mangling prefixes.
[in] | name | The already const version of the name for this object. |
Definition at line 120 of file Mangled.cpp.
References lldb_private::ConstString::Clear(), cstring_is_mangled(), lldb_private::ConstString::GetStringRef(), m_demangled, and m_mangled.
Referenced by ObjectFilePECOFF::AppendFromCOFFSymbolTable(), ObjectFilePECOFF::AppendFromExportTable(), SymbolFilePDB::GetMangledForPDBFunc(), lldb_private::breakpad::SymbolFileBreakpad::GetOrCreateFunction(), Mangled(), DWARFASTParserClang::ParseFunctionFromDWARF(), ObjectFileCOFF::ParseSymtab(), and ObjectFileMachO::ParseSymtab().
|
mutableprivate |
Mutable so we can get it on demand with a const version of this object.
Definition at line 281 of file Mangled.h.
Referenced by Clear(), Decode(), Dump(), DumpDebug(), Encode(), GetDemangledName(), GetRichManglingInfo(), MemorySize(), SetDemangledName(), and SetValue().
|
private |
Mangled member variables.
The mangled version of the name
Definition at line 280 of file Mangled.h.
Referenced by Clear(), Decode(), Dump(), DumpDebug(), Encode(), GetDemangledName(), GetMangledName(), GetName(), GetRichManglingInfo(), MemorySize(), NameMatches(), operator==(), SetMangledName(), and SetValue().