LLDB mainline
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
lldb_private::Mangled Class Reference

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)
 
ConstStringGetMangledName ()
 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 &regex) 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.
 

Detailed Description

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.

Definition at line 33 of file Mangled.h.

Member Typedef Documentation

◆ SkipMangledNameFn

Function signature for filtering mangled names.

Definition at line 214 of file Mangled.h.

Member Enumeration Documentation

◆ ManglingScheme

Enumerator
eManglingSchemeNone 
eManglingSchemeMSVC 
eManglingSchemeItanium 
eManglingSchemeRustV0 
eManglingSchemeD 
eManglingSchemeSwift 

Definition at line 41 of file Mangled.h.

◆ NamePreference

Enumerator
ePreferMangled 
ePreferDemangled 
ePreferDemangledWithoutArguments 

Definition at line 35 of file Mangled.h.

Constructor & Destructor Documentation

◆ Mangled() [1/3]

lldb_private::Mangled::Mangled ( )
default

Default constructor.

Initialize with both mangled and demangled names empty.

◆ Mangled() [2/3]

Mangled::Mangled ( ConstString  name)
explicit

Construct with name.

Constructor with an optional string and auto-detect if name is mangled or not.

Parameters
[in]nameThe already const name to copy into this object.

Definition at line 82 of file Mangled.cpp.

References SetValue().

◆ Mangled() [3/3]

Mangled::Mangled ( llvm::StringRef  name)
explicit

Definition at line 87 of file Mangled.cpp.

References SetValue().

Member Function Documentation

◆ Clear()

void Mangled::Clear ( )

Clear the mangled and demangled values.

Definition at line 101 of file Mangled.cpp.

References lldb_private::ConstString::Clear(), m_demangled, and m_mangled.

Referenced by lldb_private::Symbol::Clear().

◆ Compare()

int Mangled::Compare ( const Mangled lhs,
const Mangled rhs 
)
static

Compare the mangled string values.

Compares the Mangled::GetName() string in lhs and rhs.

Parameters
[in]lhsA const reference to the Left Hand Side object to compare.
[in]rhsA const reference to the Right Hand Side object to compare.
Returns
-1 if lhs is less than rhs 0 if lhs is equal to rhs 1 if lhs is greater than rhs

Definition at line 107 of file Mangled.cpp.

References lldb_private::ConstString::Compare(), ePreferMangled, and GetName().

Referenced by SymbolContextsMightBeEquivalent().

◆ Decode()

bool Mangled::Decode ( const DataExtractor data,
lldb::offset_t offset_ptr,
const StringTableReader strtab 
)

Decode a serialized version of this object from data.

Parameters
dataThe decoder object that references the serialized data.
offset_ptrA pointer that contains the offset from which the data will be decoded from that gets updated as data gets decoded.
strtabAll 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 433 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().

◆ Dump()

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).

Parameters
[in]sThe stream to which to dump the object description.

Definition at line 348 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().

◆ DumpDebug()

void Mangled::DumpDebug ( Stream s) const

Dump a debug description of this object to a Stream s.

Parameters
[in]sThe stream to which to dump the object description.

Definition at line 360 of file Mangled.cpp.

References lldb_private::ConstString::DumpDebug(), m_demangled, m_mangled, and lldb_private::Stream::Printf().

◆ Encode()

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.

Parameters
encoderA data encoder object that serialized bytes will be encoded into.
strtabAll 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 483 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().

◆ GetDemangledName()

ConstString Mangled::GetDemangledName ( ) const

Demangled name get accessor.

Returns
A const reference to the demangled name string object.

Definition at line 262 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(), 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().

◆ GetDisplayDemangledName()

ConstString Mangled::GetDisplayDemangledName ( ) const

◆ GetMangledName() [1/2]

ConstString & lldb_private::Mangled::GetMangledName ( )
inline

◆ GetMangledName() [2/2]

ConstString lldb_private::Mangled::GetMangledName ( ) const
inline

Mangled name get accessor.

Returns
A const reference to the mangled name string object.

Definition at line 151 of file Mangled.h.

References m_mangled.

◆ GetManglingScheme()

Mangled::ManglingScheme Mangled::GetManglingScheme ( llvm::StringRef const  name)
static

Try to identify the mangling scheme used.

Parameters
[in]nameThe name we are attempting to identify the mangling scheme for.
Returns
eManglingSchemeNone if no known mangling scheme could be identified for s, otherwise the enumerator for the mangling scheme detected.

Definition at line 41 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().

◆ GetName()

ConstString Mangled::GetName ( Mangled::NamePreference  preference = ePreferDemangled) const

◆ GetRichManglingInfo()

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.

Parameters
[in]contextThe context for this function. A single instance can be stack- allocated in the caller's frame and used for multiple calls.
[in]skip_mangled_nameA filtering function for skipping entities based on name and mangling scheme. This can be null if unused.
Returns
True on success, false otherwise.

Definition at line 202 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().

◆ GuessLanguage()

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).

Returns
The language for the mangled/demangled name, eLanguageTypeUnknown if there is no mangled or demangled counterpart.

Definition at line 381 of file Mangled.cpp.

References lldb::eLanguageTypeUnknown, lldb_private::Language::ForEach(), and l.

Referenced by CommandObjectMultiwordItaniumABI_Demangle::DoExecute(), lldb_private::Function::GetLanguage(), lldb_private::Symbol::GetLanguage(), lldb_private::SymbolContext::GetLanguage(), lldb_private::Variable::GetLanguage(), GetName(), and lldb_private::StackFrame::GuessLanguage().

◆ MemorySize()

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.

Returns
The number of bytes that this object occupies in memory.

Definition at line 371 of file Mangled.cpp.

References m_demangled, m_mangled, and lldb_private::ConstString::MemorySize().

Referenced by lldb_private::InlineFunctionInfo::MemorySize().

◆ NameMatches() [1/2]

bool Mangled::NameMatches ( const RegularExpression regex) const

◆ NameMatches() [2/2]

bool lldb_private::Mangled::NameMatches ( ConstString  name) const
inline

Check if "name" matches either the mangled or demangled name.

Parameters
[in]nameA name to match against both strings.
Returns
True if name matches either name, false otherwise.

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().

◆ operator bool()

Mangled::operator bool ( ) const
explicit

Convert to bool operator.

This allows code to check any Mangled objects to see if they contain anything valid using code such as:

Mangled mangled(...);
if (mangled)
{ ...
A class that handles mangled names.
Definition: Mangled.h:33
Returns
Returns true if either the mangled or unmangled name is set, false if the object has an empty mangled and unmangled name.

Definition at line 98 of file Mangled.cpp.

◆ operator!=()

bool lldb_private::Mangled::operator!= ( const Mangled rhs) const
inline

Definition at line 71 of file Mangled.h.

◆ operator==()

bool lldb_private::Mangled::operator== ( const Mangled rhs) const
inline

Definition at line 66 of file Mangled.h.

References GetDemangledName(), and m_mangled.

◆ SetDemangledName()

void lldb_private::Mangled::SetDemangledName ( ConstString  name)
inline

◆ SetMangledName()

void lldb_private::Mangled::SetMangledName ( ConstString  name)
inline

◆ SetValue()

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.

Parameters
[in]nameThe already const version of the name for this object.

Definition at line 112 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().

Member Data Documentation

◆ m_demangled

ConstString lldb_private::Mangled::m_demangled
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().

◆ m_mangled

ConstString lldb_private::Mangled::m_mangled
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().


The documentation for this class was generated from the following files: