22#include "llvm/ADT/StringExtras.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/Demangle/Demangle.h"
25#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_"))
140 char *demangled_cstr = llvm::rustDemangle(M);
143 if (demangled_cstr && demangled_cstr[0])
144 LLDB_LOG(log,
"demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr);
146 LLDB_LOG(log,
"demangled rustv0: {0} -> error: failed to demangle",
147 static_cast<std::string_view
>(M));
150 return demangled_cstr;
154 char *demangled_cstr = llvm::dlangDemangle(M);
157 if (demangled_cstr && demangled_cstr[0])
158 LLDB_LOG(log,
"demangled dlang: {0} -> \"{1}\"", M, demangled_cstr);
160 LLDB_LOG(log,
"demangled dlang: {0} -> error: failed to demangle",
161 static_cast<std::string_view
>(M));
164 return demangled_cstr;
185 char *demangled_name =
nullptr;
193 if (!demangled.
name.empty())
212 if (demangled_name) {
214 free(demangled_name);
244 return lang->GetDisplayDemangledName(*
this);
267 return lang->GetDemangledFunctionNameWithoutArguments(*
this);
291 s->
Printf(
"%*p: Mangled mangled = ",
static_cast<int>(
sizeof(
void *) * 2),
292 static_cast<const void *
>(
this));
308 if (
l->SymbolNameFitsToLanguage(*
this)) {
309 result =
l->GetLanguageType();
324 s <<
", demangled = '" << demangled <<
'\'';
326 s <<
", demangled = <error>";
447 const auto &range = demangled_info->BasenameRange;
449 demangled_name.
GetStringRef().slice(range.first, range.second));
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
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),...
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.
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.
virtual DemangledName DemangleSymbol(ConstString mangled, Mangled::ManglingScheme scheme, const DemangleOptions &options) const
Demangle mangled, a name mangled with scheme, a scheme that this language handles.
static void ForEach(llvm::function_ref< IterationAction(Language *)> callback)
static Language * FindPlugin(lldb::LanguageType language)
static Language * FindPluginForManglingScheme(Mangled::ManglingScheme scheme)
Returns the Language that handles names mangled with scheme, or a nullptr if there is none.
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
Mangled()=default
Default constructor.
void DumpDebug(Stream *s) const
Dump a debug description of this object to a Stream s.
std::optional< DemangledNameInfo > ComputeDemangledInfo() const
Compute the DemangledNameInfo of the demangled name.
ConstString GetMangledName() const
Mangled name get accessor.
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.
void SetValue(ConstString name)
Set the string value in this object.
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef name)
Try to identify the mangling scheme used.
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...
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string 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.
How to demangle a name in DemangleSymbol().
bool want_info
Whether to compute the DemangledNameInfo too.
A demangled name and, if requested, where its parts begin and end.
std::optional< DemangledNameInfo > info
Only computed if DemangleOptions::want_info is true.
std::string name
Empty if the name couldn't be demangled.