forked from OSchip/llvm-project
[lldb] Add support for demangling D symbols
This is part of https://github.com/dlang/projects/issues/81 . This patch enables support for D programming language demangler by using a pretty printed stacktrace with demangled D symbols, when present. Signed-off-by: Luís Ferreira <contact@lsferreira.net> Reviewed By: JDevlieghere, teemperor Differential Revision: https://reviews.llvm.org/D110578
This commit is contained in:
parent
f1a2b50789
commit
96a7359908
|
@ -44,7 +44,8 @@ public:
|
|||
eManglingSchemeNone = 0,
|
||||
eManglingSchemeMSVC,
|
||||
eManglingSchemeItanium,
|
||||
eManglingSchemeRustV0
|
||||
eManglingSchemeRustV0,
|
||||
eManglingSchemeD
|
||||
};
|
||||
|
||||
/// Default constructor.
|
||||
|
|
|
@ -45,6 +45,9 @@ Mangled::ManglingScheme Mangled::GetManglingScheme(llvm::StringRef const name) {
|
|||
if (name.startswith("_R"))
|
||||
return Mangled::eManglingSchemeRustV0;
|
||||
|
||||
if (name.startswith("_D"))
|
||||
return Mangled::eManglingSchemeD;
|
||||
|
||||
if (name.startswith("_Z"))
|
||||
return Mangled::eManglingSchemeItanium;
|
||||
|
||||
|
@ -185,6 +188,19 @@ static char *GetRustV0DemangledStr(const char *M) {
|
|||
return demangled_cstr;
|
||||
}
|
||||
|
||||
static char *GetDLangDemangledStr(const char *M) {
|
||||
char *demangled_cstr = llvm::dlangDemangle(M);
|
||||
|
||||
if (Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DEMANGLE)) {
|
||||
if (demangled_cstr && demangled_cstr[0])
|
||||
LLDB_LOG(log, "demangled dlang: {0} -> \"{1}\"", M, demangled_cstr);
|
||||
else
|
||||
LLDB_LOG(log, "demangled dlang: {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(
|
||||
|
@ -244,7 +260,8 @@ bool Mangled::DemangleWithRichManglingInfo(
|
|||
}
|
||||
|
||||
case eManglingSchemeRustV0:
|
||||
// Rich demangling scheme is not supported for Rust
|
||||
case eManglingSchemeD:
|
||||
// Rich demangling scheme is not supported
|
||||
return false;
|
||||
}
|
||||
llvm_unreachable("Fully covered switch above!");
|
||||
|
@ -278,6 +295,9 @@ ConstString Mangled::GetDemangledName() const {
|
|||
case eManglingSchemeRustV0:
|
||||
demangled_name = GetRustV0DemangledStr(mangled_name);
|
||||
break;
|
||||
case eManglingSchemeD:
|
||||
demangled_name = GetDLangDemangledStr(mangled_name);
|
||||
break;
|
||||
case eManglingSchemeNone:
|
||||
llvm_unreachable("eManglingSchemeNone was handled already");
|
||||
}
|
||||
|
|
|
@ -248,10 +248,8 @@ static bool lldb_skip_name(llvm::StringRef mangled,
|
|||
|
||||
// No filters for this scheme yet. Include all names in indexing.
|
||||
case Mangled::eManglingSchemeMSVC:
|
||||
return false;
|
||||
|
||||
// No filters for this scheme yet. Include all names in indexing.
|
||||
case Mangled::eManglingSchemeRustV0:
|
||||
case Mangled::eManglingSchemeD:
|
||||
return false;
|
||||
|
||||
// Don't try and demangle things we can't categorize.
|
||||
|
|
|
@ -72,6 +72,24 @@ TEST(MangledTest, EmptyForInvalidRustV0Name) {
|
|||
EXPECT_STREQ("", the_demangled.GetCString());
|
||||
}
|
||||
|
||||
TEST(MangledTest, ResultForValidDLangName) {
|
||||
ConstString mangled_name("_Dmain");
|
||||
Mangled the_mangled(mangled_name);
|
||||
ConstString the_demangled = the_mangled.GetDemangledName();
|
||||
|
||||
ConstString expected_result("D main");
|
||||
EXPECT_STREQ(expected_result.GetCString(), the_demangled.GetCString());
|
||||
}
|
||||
|
||||
TEST(MangledTest, EmptyForInvalidDLangName) {
|
||||
ConstString mangled_name("_DDD");
|
||||
Mangled the_mangled(mangled_name);
|
||||
ConstString the_demangled = the_mangled.GetDemangledName();
|
||||
|
||||
EXPECT_STREQ("", the_demangled.GetCString());
|
||||
}
|
||||
|
||||
|
||||
TEST(MangledTest, NameIndexes_FindFunctionSymbols) {
|
||||
SubsystemRAII<FileSystem, HostInfo, ObjectFileELF, SymbolFileSymtab>
|
||||
subsystems;
|
||||
|
|
Loading…
Reference in New Issue