22#include "llvm/ADT/StringExtras.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/Demangle/Demangle.h"
25#include "llvm/Support/Compiler.h"
46 if (name.starts_with(
"?"))
49 if (name.starts_with(
"_R"))
52 if (name.starts_with(
"_D")) {
57 llvm::StringRef buf = name.drop_front(2);
58 if (!buf.empty() && (llvm::isDigit(buf.front()) || name ==
"_Dmain"))
62 if (name.starts_with(
"_Z"))
66 if (name.starts_with(
"___Z"))
75 if (name.starts_with(
"_TtC") || name.starts_with(
"_TtGC") ||
76 name.starts_with(
"_TtP"))
82 if (name.starts_with(
"$S") || name.starts_with(
"_$S") ||
83 name.starts_with(
"$s") || name.starts_with(
"_$s") ||
84 name.starts_with(
"@__swiftmacro_"))
106Mangled::operator bool()
const {
return m_mangled || m_demangled; }
137 char *demangled_cstr = llvm::microsoftDemangle(
139 llvm::MSDemangleFlags(
140 llvm::MSDF_NoAccessSpecifier | llvm::MSDF_NoCallingConvention |
141 llvm::MSDF_NoMemberType | llvm::MSDF_NoVariableType));
144 if (demangled_cstr && demangled_cstr[0])
145 LLDB_LOGF(log,
"demangled msvc: %s -> \"%s\"", M.data(), demangled_cstr);
147 LLDB_LOGF(log,
"demangled msvc: %s -> error", M.data());
150 return demangled_cstr;
154 char *demangled_cstr =
nullptr;
156 llvm::ItaniumPartialDemangler ipd;
157 bool err = ipd.partialDemangle(M);
160 size_t demangled_size = 80;
161 demangled_cstr =
static_cast<char *
>(std::malloc(demangled_size));
162 demangled_cstr = ipd.finishDemangle(demangled_cstr, &demangled_size);
164 assert(demangled_cstr &&
165 "finishDemangle must always succeed if partialDemangle did");
166 assert(demangled_cstr[demangled_size - 1] ==
'\0' &&
167 "Expected demangled_size to return length including trailing null");
172 LLDB_LOGF(log,
"demangled itanium: %s -> \"%s\"", M, demangled_cstr);
174 LLDB_LOGF(log,
"demangled itanium: %s -> error: failed to demangle", M);
177 return demangled_cstr;
181 char *demangled_cstr = llvm::rustDemangle(M);
184 if (demangled_cstr && demangled_cstr[0])
185 LLDB_LOG(log,
"demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr);
187 LLDB_LOG(log,
"demangled rustv0: {0} -> error: failed to demangle",
188 static_cast<std::string_view
>(M));
191 return demangled_cstr;
195 char *demangled_cstr = llvm::dlangDemangle(M);
198 if (demangled_cstr && demangled_cstr[0])
199 LLDB_LOG(log,
"demangled dlang: {0} -> \"{1}\"", M, demangled_cstr);
201 LLDB_LOG(log,
"demangled dlang: {0} -> error: failed to demangle",
202 static_cast<std::string_view
>(M));
205 return demangled_cstr;
263 llvm_unreachable(
"Fully covered switch above!");
282 char *demangled_name =
nullptr;
283 switch (mangling_scheme) {
302 llvm_unreachable(
"eManglingSchemeNone was handled already");
304 if (demangled_name) {
306 llvm::StringRef(demangled_name),
m_mangled);
307 free(demangled_name);
322 return lang->GetDisplayDemangledName(*
this);
345 return lang->GetDemangledFunctionNameWithoutArguments(*
this);
364 s->
Printf(
", demangled = %s", demangled[0] ? demangled :
"<error>");
371 s->
Printf(
"%*p: Mangled mangled = ",
static_cast<int>(
sizeof(
void *) * 2),
372 static_cast<const void *
>(
this));
374 s->
Printf(
", demangled = ");
395 if (
l->SymbolNameFitsToLanguage(*
this)) {
396 result = l->GetLanguageType();
411 s <<
", demangled = '" << demangled <<
'\'';
413 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 * GetDLangDemangledStr(llvm::StringRef M)
static char * GetRustV0DemangledStr(llvm::StringRef 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 bool cstring_is_mangled(llvm::StringRef s)
static char * GetItaniumDemangledStr(const char *M)
static char * GetMSVCDemangledStr(llvm::StringRef 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.