diff --git a/lldb/include/lldb/Core/Mangled.h b/lldb/include/lldb/Core/Mangled.h index 19f44c95835c3b..d11d13b63cfcfe 100644 --- a/lldb/include/lldb/Core/Mangled.h +++ b/lldb/include/lldb/Core/Mangled.h @@ -43,7 +43,8 @@ class Mangled { enum ManglingScheme { eManglingSchemeNone = 0, eManglingSchemeMSVC, - eManglingSchemeItanium + eManglingSchemeItanium, + eManglingSchemeRustV0 }; /// Default constructor. diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp index f82c4c5b164f36..fbaf9ff7151a39 100644 --- a/lldb/source/Core/Mangled.cpp +++ b/lldb/source/Core/Mangled.cpp @@ -72,6 +72,9 @@ Mangled::ManglingScheme Mangled::GetManglingScheme(llvm::StringRef const name) { if (name.startswith("?")) return Mangled::eManglingSchemeMSVC; + if (name.startswith("_R")) + return Mangled::eManglingSchemeRustV0; + if (name.startswith("_Z")) return Mangled::eManglingSchemeItanium; @@ -199,6 +202,19 @@ static char *GetItaniumDemangledStr(const char *M) { return demangled_cstr; } +static char *GetRustV0DemangledStr(const char *M) { + char *demangled_cstr = llvm::rustDemangle(M, nullptr, nullptr, nullptr); + + if (Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DEMANGLE)) { + if (demangled_cstr && demangled_cstr[0]) + LLDB_LOG(log, "demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr); + else + LLDB_LOG(log, "demangled rustv0: {0} -> error: failed to demangle", M); + } + + return demangled_cstr; +} + // Explicit demangling for scheduled requests during batch processing. This // makes use of ItaniumPartialDemangler's rich demangle info bool Mangled::DemangleWithRichManglingInfo( @@ -256,6 +272,10 @@ bool Mangled::DemangleWithRichManglingInfo( return context.FromCxxMethodName(m_demangled); } } + + case eManglingSchemeRustV0: + // Rich demangling scheme is not supported for Rust + return false; } llvm_unreachable("Fully covered switch above!"); } @@ -284,6 +304,9 @@ ConstString Mangled::GetDemangledName() const { demangled_name = GetItaniumDemangledStr(mangled_name); break; } + case eManglingSchemeRustV0: + demangled_name = GetRustV0DemangledStr(mangled_name); + break; case eManglingSchemeNone: llvm_unreachable("eManglingSchemeNone was handled already"); } diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp index 0deefa5dd5c0a3..18152d23dd3797 100644 --- a/lldb/source/Symbol/Symtab.cpp +++ b/lldb/source/Symbol/Symtab.cpp @@ -251,6 +251,10 @@ static bool lldb_skip_name(llvm::StringRef mangled, case Mangled::eManglingSchemeMSVC: return false; + // No filters for this scheme yet. Include all names in indexing. + case Mangled::eManglingSchemeRustV0: + return false; + // Don't try and demangle things we can't categorize. case Mangled::eManglingSchemeNone: return true; diff --git a/lldb/unittests/Core/MangledTest.cpp b/lldb/unittests/Core/MangledTest.cpp index 6e1bdd59978d8b..431993fccb1a61 100644 --- a/lldb/unittests/Core/MangledTest.cpp +++ b/lldb/unittests/Core/MangledTest.cpp @@ -55,6 +55,23 @@ TEST(MangledTest, EmptyForInvalidName) { EXPECT_STREQ("", TheDemangled.GetCString()); } +TEST(MangledTest, ResultForValidRustV0Name) { + ConstString mangled_name("_RNvC1a4main"); + Mangled the_mangled(mangled_name); + ConstString the_demangled = the_mangled.GetDemangledName(); + + ConstString expected_result("a::main"); + EXPECT_STREQ(expected_result.GetCString(), the_demangled.GetCString()); +} + +TEST(MangledTest, EmptyForInvalidRustV0Name) { + ConstString mangled_name("_RRR"); + Mangled the_mangled(mangled_name); + ConstString the_demangled = the_mangled.GetDemangledName(); + + EXPECT_STREQ("", the_demangled.GetCString()); +} + TEST(MangledTest, NameIndexes_FindFunctionSymbols) { SubsystemRAII subsystems;