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"))
83 if (name.starts_with(
"$S") || name.starts_with(
"_$S") ||
84 name.starts_with(
"$s") || name.starts_with(
"_$s") ||
85 name.starts_with(
"$e") || name.starts_with(
"_$e") ||
86 name.starts_with(
"@__swiftmacro_"))
108Mangled::operator bool()
const {
return m_mangled || m_demangled; }
139 char *demangled_cstr = llvm::microsoftDemangle(
141 llvm::MSDemangleFlags(
142 llvm::MSDF_NoAccessSpecifier | llvm::MSDF_NoCallingConvention |
143 llvm::MSDF_NoMemberType | llvm::MSDF_NoVariableType));
146 if (demangled_cstr && demangled_cstr[0])
147 LLDB_LOGF(log,
"demangled msvc: %s -> \"%s\"", M.data(), demangled_cstr);
149 LLDB_LOGF(log,
"demangled msvc: %s -> error", M.data());
152 return demangled_cstr;
156 char *demangled_cstr =
nullptr;
158 llvm::ItaniumPartialDemangler ipd;
159 bool err = ipd.partialDemangle(M);
162 size_t demangled_size = 80;
163 demangled_cstr =
static_cast<char *
>(std::malloc(demangled_size));
164 demangled_cstr = ipd.finishDemangle(demangled_cstr, &demangled_size);
166 assert(demangled_cstr &&
167 "finishDemangle must always succeed if partialDemangle did");
168 assert(demangled_cstr[demangled_size - 1] ==
'\0' &&
169 "Expected demangled_size to return length including trailing null");
174 LLDB_LOGF(log,
"demangled itanium: %s -> \"%s\"", M, demangled_cstr);
176 LLDB_LOGF(log,
"demangled itanium: %s -> error: failed to demangle", M);
179 return demangled_cstr;
183 char *demangled_cstr = llvm::rustDemangle(M);
186 if (demangled_cstr && demangled_cstr[0])
187 LLDB_LOG(log,
"demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr);
189 LLDB_LOG(log,
"demangled rustv0: {0} -> error: failed to demangle",
190 static_cast<std::string_view
>(M));
193 return demangled_cstr;
197 char *demangled_cstr = llvm::dlangDemangle(M);
200 if (demangled_cstr && demangled_cstr[0])
201 LLDB_LOG(log,
"demangled dlang: {0} -> \"{1}\"", M, demangled_cstr);
203 LLDB_LOG(log,
"demangled dlang: {0} -> error: failed to demangle",
204 static_cast<std::string_view
>(M));
207 return demangled_cstr;
265 llvm_unreachable(
"Fully covered switch above!");
284 char *demangled_name =
nullptr;
285 switch (mangling_scheme) {
304 llvm_unreachable(
"eManglingSchemeNone was handled already");
306 if (demangled_name) {
308 llvm::StringRef(demangled_name),
m_mangled);
309 free(demangled_name);
324 return lang->GetDisplayDemangledName(*
this);
347 return lang->GetDemangledFunctionNameWithoutArguments(*
this);
366 s->
Printf(
", demangled = %s", demangled[0] ? demangled :
"<error>");
373 s->
Printf(
"%*p: Mangled mangled = ",
static_cast<int>(
sizeof(
void *) * 2),
374 static_cast<const void *
>(
this));
376 s->
Printf(
", demangled = ");
397 if (
l->SymbolNameFitsToLanguage(*
this)) {
398 result = l->GetLanguageType();
413 s <<
", demangled = '" << demangled <<
'\'';
415 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.