22#include "llvm/ADT/StringRef.h"
23#include "llvm/Demangle/Demangle.h"
24#include "llvm/Support/Compiler.h"
45 if (name.startswith(
"?"))
48 if (name.startswith(
"_R"))
51 if (name.startswith(
"_D"))
54 if (name.startswith(
"_Z"))
58 if (name.startswith(
"___Z"))
67 if (name.startswith(
"_TtC") || name.startswith(
"_TtGC") ||
68 name.startswith(
"_TtP"))
74 if (name.startswith(
"$S") || name.startswith(
"_$S") ||
75 name.startswith(
"$s") || name.startswith(
"_$s") ||
76 name.startswith(
"@__swiftmacro_"))
98Mangled::operator bool()
const {
return m_mangled || m_demangled; }
129 char *demangled_cstr = llvm::microsoftDemangle(
131 llvm::MSDemangleFlags(
132 llvm::MSDF_NoAccessSpecifier | llvm::MSDF_NoCallingConvention |
133 llvm::MSDF_NoMemberType | llvm::MSDF_NoVariableType));
136 if (demangled_cstr && demangled_cstr[0])
137 LLDB_LOGF(log,
"demangled msvc: %s -> \"%s\"", M.data(), demangled_cstr);
139 LLDB_LOGF(log,
"demangled msvc: %s -> error", M.data());
142 return demangled_cstr;
146 char *demangled_cstr =
nullptr;
148 llvm::ItaniumPartialDemangler ipd;
149 bool err = ipd.partialDemangle(M);
152 size_t demangled_size = 80;
153 demangled_cstr =
static_cast<char *
>(std::malloc(demangled_size));
154 demangled_cstr = ipd.finishDemangle(demangled_cstr, &demangled_size);
156 assert(demangled_cstr &&
157 "finishDemangle must always succeed if partialDemangle did");
158 assert(demangled_cstr[demangled_size - 1] ==
'\0' &&
159 "Expected demangled_size to return length including trailing null");
164 LLDB_LOGF(log,
"demangled itanium: %s -> \"%s\"", M, demangled_cstr);
166 LLDB_LOGF(log,
"demangled itanium: %s -> error: failed to demangle", M);
169 return demangled_cstr;
173 char *demangled_cstr = llvm::rustDemangle(M);
176 if (demangled_cstr && demangled_cstr[0])
177 LLDB_LOG(log,
"demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr);
179 LLDB_LOG(log,
"demangled rustv0: {0} -> error: failed to demangle", M);
182 return demangled_cstr;
186 char *demangled_cstr = llvm::dlangDemangle(M);
189 if (demangled_cstr && demangled_cstr[0])
190 LLDB_LOG(log,
"demangled dlang: {0} -> \"{1}\"", M, demangled_cstr);
192 LLDB_LOG(log,
"demangled dlang: {0} -> error: failed to demangle", M);
195 return demangled_cstr;
253 llvm_unreachable(
"Fully covered switch above!");
272 char *demangled_name =
nullptr;
273 switch (mangling_scheme) {
292 llvm_unreachable(
"eManglingSchemeNone was handled already");
294 if (demangled_name) {
296 llvm::StringRef(demangled_name),
m_mangled);
297 free(demangled_name);
333 return lang->GetDemangledFunctionNameWithoutArguments(*
this);
352 s->
Printf(
", demangled = %s", demangled[0] ? demangled :
"<error>");
359 s->
Printf(
"%*p: Mangled mangled = ",
static_cast<int>(
sizeof(
void *) * 2),
360 static_cast<const void *
>(
this));
362 s->
Printf(
", demangled = ");
383 if (
l->SymbolNameFitsToLanguage(*
this)) {
384 result = l->GetLanguageType();
399 s <<
", demangled = '" << demangled <<
'\'';
401 s <<
", demangled = <error>";
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
static char * GetRustV0DemangledStr(std::string_view M)
static char * GetDLangDemangledStr(std::string_view M)
@ MangledAndDemangled
If we have a Mangled object with two different names that are not related then we need to save both s...
@ DemangledOnly
If the Mangled object has only a demangled name and no mangled named, we can encode only the demangle...
@ Empty
If the Mangled object has neither a mangled name or demangled name we can encode the object with one ...
@ MangledOnly
If the mangle name can calculate the demangled name (it is the mangled/demangled counterpart),...
static char * GetMSVCDemangledStr(std::string_view M)
static bool cstring_is_mangled(llvm::StringRef s)
static char * GetItaniumDemangledStr(const char *M)
Many cache files require string tables to store data efficiently.
uint32_t Add(ConstString s)
Add a string into the string table.
A uniqued constant string class.
bool GetMangledCounterpart(ConstString &counterpart) const
Retrieve the mangled or demangled counterpart for a mangled or demangled ConstString.
size_t MemorySize() const
Get the memory cost of this object.
bool IsNull() const
Test for null string.
void SetCString(const char *cstr)
Set the C string value.
static int Compare(ConstString lhs, ConstString rhs, const bool case_sensitive=true)
Compare two string objects.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
void DumpDebug(Stream *s) const
Dump the object debug description to a stream.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
void Clear()
Clear this object's state.
const char * GetCString() const
Get the string value as a C string.
void SetStringWithMangledCounterpart(llvm::StringRef demangled, ConstString mangled)
Set the C string value and its mangled counterpart.
An binary data encoding class.
void AppendU32(uint32_t value)
void AppendU8(uint8_t value)
Append a unsigned integer to the end of the owned data.
static Language * FindPlugin(lldb::LanguageType language)
static void ForEach(std::function< bool(Language *)> callback)
A class that handles mangled names.
void Encode(DataEncoder &encoder, ConstStringTable &strtab) const
Encode this object into a data encoder object.
bool NameMatches(ConstString name) const
Check if "name" matches either the mangled or demangled name.
static int Compare(const Mangled &lhs, const Mangled &rhs)
Compare the mangled string values.
@ ePreferDemangledWithoutArguments
Mangled()=default
Default constructor.
void DumpDebug(Stream *s) const
Dump a debug description of this object to a Stream s.
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef const name)
Try to identify the mangling scheme used.
size_t MemorySize() const
Get the memory cost of this object.
bool GetRichManglingInfo(RichManglingContext &context, SkipMangledNameFn *skip_mangled_name)
Get rich mangling information.
ConstString GetDemangledName() const
Demangled name get accessor.
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.
bool(llvm::StringRef, ManglingScheme) SkipMangledNameFn
Function signature for filtering mangled names.
ConstString & GetMangledName()
Mangled name get accessor.
void SetValue(ConstString name)
Set the string value in this object.
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
ConstString m_mangled
Mangled member variables.
ConstString m_demangled
Mutable so we can get it on demand with a const version of this object.
ConstString GetDisplayDemangledName() const
Display demangled name get accessor.
void Dump(Stream *s) const
Dump a description of this object to a Stream s.
void Clear()
Clear the mangled and demangled values.
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
Uniform wrapper for access to rich mangling information from different providers.
bool FromItaniumName(ConstString mangled)
Use the ItaniumPartialDemangler to obtain rich mangling information from the given mangled name.
bool FromCxxMethodName(ConstString demangled)
Use the legacy language parser implementation to obtain rich mangling information from the given dema...
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Many cache files require string tables to store data efficiently.
llvm::StringRef Get(uint32_t offset) const
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Stream & operator<<(Stream &s, const Mangled &obj)
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.