23#include "llvm/ADT/StringExtras.h"
24#include "llvm/ADT/StringRef.h"
25#include "llvm/Demangle/Demangle.h"
26#include "llvm/Support/Compiler.h"
47 if (name.starts_with(
"?"))
50 if (name.starts_with(
"_R"))
53 if (name.starts_with(
"_D")) {
58 llvm::StringRef buf = name.drop_front(2);
59 if (!buf.empty() && (llvm::isDigit(buf.front()) || name ==
"_Dmain"))
63 if (name.starts_with(
"_Z"))
67 if (name.starts_with(
"___Z"))
76 if (name.starts_with(
"_TtC") || name.starts_with(
"_TtGC") ||
77 name.starts_with(
"_TtP"))
84 if (name.starts_with(
"$S") || name.starts_with(
"_$S") ||
85 name.starts_with(
"$s") || name.starts_with(
"_$s") ||
86 name.starts_with(
"$e") || name.starts_with(
"_$e") ||
87 name.starts_with(
"@__swiftmacro_"))
144 char *demangled_cstr = llvm::microsoftDemangle(
146 llvm::MSDemangleFlags(
147 llvm::MSDF_NoAccessSpecifier | llvm::MSDF_NoCallingConvention |
148 llvm::MSDF_NoMemberType | llvm::MSDF_NoVariableType));
151 if (demangled_cstr && demangled_cstr[0])
152 LLDB_LOGF(log,
"demangled msvc: %s -> \"%s\"", M.data(), demangled_cstr);
154 LLDB_LOGF(log,
"demangled msvc: %s -> error", M.data());
157 return demangled_cstr;
160static std::pair<char *, DemangledNameInfo>
162 char *demangled_cstr =
nullptr;
165 llvm::ItaniumPartialDemangler ipd;
166 bool err = ipd.partialDemangle(M);
170 size_t demangled_size = 80;
171 demangled_cstr =
static_cast<char *
>(std::malloc(80));
174 demangled_cstr = ipd.finishDemangle(&OB);
177 assert(demangled_cstr &&
178 "finishDemangle must always succeed if partialDemangle did");
179 assert(demangled_cstr[OB.getCurrentPosition() - 1] ==
'\0' &&
180 "Expected demangled_size to return length including trailing null");
185 LLDB_LOGF(log,
"demangled itanium: %s -> \"%s\"", M, demangled_cstr);
187 LLDB_LOGF(log,
"demangled itanium: %s -> error: failed to demangle", M);
191 "demangled itanium: %s -> error: failed to retrieve name info",
195 return {demangled_cstr, std::move(info)};
199 char *demangled_cstr = llvm::rustDemangle(M);
202 if (demangled_cstr && demangled_cstr[0])
203 LLDB_LOG(log,
"demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr);
205 LLDB_LOG(log,
"demangled rustv0: {0} -> error: failed to demangle",
206 static_cast<std::string_view
>(M));
209 return demangled_cstr;
213 char *demangled_cstr = llvm::dlangDemangle(M);
216 if (demangled_cstr && demangled_cstr[0])
217 LLDB_LOG(log,
"demangled dlang: {0} -> \"{1}\"", M, demangled_cstr);
219 LLDB_LOG(log,
"demangled dlang: {0} -> error: failed to demangle",
220 static_cast<std::string_view
>(M));
223 return demangled_cstr;
236 if (skip_mangled_name && skip_mangled_name(
m_mangled.GetStringRef(), scheme))
257 m_demangled.SetStringWithMangledCounterpart(llvm::StringRef(d),
281 llvm_unreachable(
"Fully covered switch above!");
313 char *demangled_name =
nullptr;
319 std::pair<char *, DemangledNameInfo> demangled =
321 demangled_name = demangled.first;
340 if (demangled_name) {
342 free(demangled_name);
356 return lang->GetDisplayDemangledName(*
this);
379 return lang->GetDemangledFunctionNameWithoutArguments(*
this);
398 s->
Printf(
", demangled = %s", demangled[0] ? demangled :
"<error>");
405 s->
Printf(
"%*p: Mangled mangled = ",
static_cast<int>(
sizeof(
void *) * 2),
406 static_cast<const void *
>(
this));
408 s->
Printf(
", demangled = ");
429 if (
l->SymbolNameFitsToLanguage(*
this)) {
430 result =
l->GetLanguageType();
445 s <<
", demangled = '" << demangled <<
'\'';
447 s <<
", demangled = <error>";
562 if (!demangled_info.has_value())
569 const char *name_str = demangled_name.
AsCString();
570 const auto &range = demangled_info->BasenameRange;
572 llvm::StringRef(name_str + range.first, range.second - range.first));
#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)
static std::pair< char *, DemangledNameInfo > GetItaniumDemangledStr(const char *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(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.
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.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
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.
static bool IsMangledName(llvm::StringRef name)
@ ePreferDemangledWithoutArguments
std::optional< DemangledNameInfo > m_demangled_info
If available, holds information about where in m_demangled certain parts of the name (e....
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.
ConstString GetBaseName() const
Compute the base name (without namespace/class qualifiers) from the demangled name.
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.
const std::optional< DemangledNameInfo > & GetDemangledInfo() const
Retrieve DemangledNameInfo of the demangled name held by this object.
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
ConstString GetDemangledNameImpl(bool force) const
If force is false, this function will re-use the previously demangled name (if any).
ConstString m_mangled
The mangled version of the name.
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.
Stores information about where certain portions of a demangled function name begin and end.
bool hasBasename() const
Returns true if this object holds a valid basename range.
An OutputBuffer which keeps a record of where certain parts of a demangled name begin/end (e....
DemangledNameInfo NameInfo
Holds information about the demangled name that is being printed into this buffer.