Index: cmake/modules/LLDBConfig.cmake =================================================================== --- cmake/modules/LLDBConfig.cmake +++ cmake/modules/LLDBConfig.cmake @@ -412,12 +412,16 @@ endif() if(MSVC) - set(LLDB_USE_BUILTIN_DEMANGLER ON) + set(LLDB_USE_BUILTIN_DEMANGLER OFF) + set(LLDB_USE_LLVM_DEMANGLER ON) else() - option(LLDB_USE_BUILTIN_DEMANGLER "Use lldb's builtin demangler instead of the system one" ON) + option(LLDB_USE_BUILTIN_DEMANGLER "Use lldb's builtin demangler" OFF) + option(LLDB_USE_LLVM_DEMANGLER "Use llvm's new partial demangler" ON) endif() if(LLDB_USE_BUILTIN_DEMANGLER) add_definitions(-DLLDB_USE_BUILTIN_DEMANGLER) +elseif(LLDB_USE_LLVM_DEMANGLER) + add_definitions(-DLLDB_USE_LLVM_DEMANGLER) endif() if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND Index: lldb.xcodeproj/project.pbxproj =================================================================== --- lldb.xcodeproj/project.pbxproj +++ lldb.xcodeproj/project.pbxproj @@ -483,6 +483,7 @@ 9A20573A1F3B8E7E00F6C293 /* MainLoopTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A2057301F3B8E7600F6C293 /* MainLoopTest.cpp */; }; 8C3BD9961EF45DA50016C343 /* MainThreadCheckerRuntime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C3BD9951EF45D9B0016C343 /* MainThreadCheckerRuntime.cpp */; }; 2689004313353E0400698AC0 /* Mangled.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E8010F1B85900F91463 /* Mangled.cpp */; }; + 4F29D3CF21010FA3003B549A /* MangledTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4F29D3CD21010F84003B549A /* MangledTest.cpp */; }; 4CD44CFC20B37C440003557C /* ManualDWARFIndex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CD44CF920B37C440003557C /* ManualDWARFIndex.cpp */; }; 49DCF702170E70120092F75E /* Materializer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49DCF700170E70120092F75E /* Materializer.cpp */; }; 2690B3711381D5C300ECFBAE /* Memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2690B3701381D5C300ECFBAE /* Memory.cpp */; }; @@ -2186,6 +2187,7 @@ 2669415F1A6DC2AB0063BE93 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = "tools/lldb-mi/Makefile"; sourceTree = SOURCE_ROOT; }; 26BC7E8010F1B85900F91463 /* Mangled.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mangled.cpp; path = source/Core/Mangled.cpp; sourceTree = ""; }; 26BC7D6910F1B77400F91463 /* Mangled.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Mangled.h; path = include/lldb/Core/Mangled.h; sourceTree = ""; }; + 4F29D3CD21010F84003B549A /* MangledTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MangledTest.cpp; sourceTree = ""; }; 4CD44CF920B37C440003557C /* ManualDWARFIndex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ManualDWARFIndex.cpp; sourceTree = ""; }; 4CD44D0020B37C580003557C /* ManualDWARFIndex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ManualDWARFIndex.h; sourceTree = ""; }; 2682100C143A59AE004BCF2D /* MappedHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MappedHash.h; path = include/lldb/Core/MappedHash.h; sourceTree = ""; }; @@ -3657,6 +3659,7 @@ 23CB14E51D66CBEB00EDDDE1 /* Core */ = { isa = PBXGroup; children = ( + 4F29D3CD21010F84003B549A /* MangledTest.cpp */, 9A3D43E31F3237D500EB767C /* ListenerTest.cpp */, 9A3D43E21F3237D500EB767C /* StateTest.cpp */, 9A3D43E11F3237D500EB767C /* StreamCallbackTest.cpp */, @@ -7445,6 +7448,7 @@ 9A3D43D71F3151C400EB767C /* LogTest.cpp in Sources */, 9A2057181F3B861400F6C293 /* TestType.cpp in Sources */, 9A2057171F3B861400F6C293 /* TestDWARFCallFrameInfo.cpp in Sources */, + 4F29D3CF21010FA3003B549A /* MangledTest.cpp in Sources */, 9A3D43EC1F3237F900EB767C /* ListenerTest.cpp in Sources */, 9A3D43DC1F3151C400EB767C /* TimeoutTest.cpp in Sources */, 9A3D43D61F3151C400EB767C /* ConstStringTest.cpp in Sources */, @@ -9328,14 +9332,14 @@ "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = ( "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); OTHER_LDFLAGS = ""; @@ -9387,14 +9391,14 @@ "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = ( "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); OTHER_LDFLAGS = ""; @@ -9446,14 +9450,14 @@ "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = ( "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); OTHER_LDFLAGS = ""; @@ -10455,14 +10459,14 @@ "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = ( "-fno-rtti", "-Wglobal-constructors", "$(OTHER_CFLAGS)", - "-DLLDB_USE_BUILTIN_DEMANGLER", + "-DLLDB_USE_LLVM_DEMANGLER", "-DLIBXML2_DEFINED", ); OTHER_LDFLAGS = ""; Index: source/Core/Mangled.cpp =================================================================== --- source/Core/Mangled.cpp +++ source/Core/Mangled.cpp @@ -16,11 +16,13 @@ #pragma comment(lib, "dbghelp.lib") #endif -#ifdef LLDB_USE_BUILTIN_DEMANGLER +#if defined(LLDB_USE_BUILTIN_DEMANGLER) // Provide a fast-path demangler implemented in FastDemangle.cpp until it can // replace the existing C++ demangler with a complete implementation #include "lldb/Utility/FastDemangle.h" #include "llvm/Demangle/Demangle.h" +#elif defined(LLDB_USE_LLVM_DEMANGLER) +#include "llvm/Demangle/Demangle.h" #else // FreeBSD9-STABLE requires this to know about size_t in cxxabi. #include @@ -295,7 +297,7 @@ break; } case eManglingSchemeItanium: { -#ifdef LLDB_USE_BUILTIN_DEMANGLER +#if defined(LLDB_USE_BUILTIN_DEMANGLER) if (log) log->Printf("demangle itanium: %s", mangled_name); // Try to use the fast-path demangler first for the performance win, @@ -304,6 +306,15 @@ if (!demangled_name) demangled_name = llvm::itaniumDemangle(mangled_name, NULL, NULL, NULL); +#elif defined(LLDB_USE_LLVM_DEMANGLER) + llvm::ItaniumPartialDemangler IPD; + bool demangle_err = IPD.partialDemangle(mangled_name); + if (!demangle_err) { + // Default buffer and size (realloc is used in case it's too small). + size_t default_size = 80; + demangled_name = static_cast(::malloc(default_size)); + demangled_name = IPD.finishDemangle(demangled_name, &default_size); + } #else demangled_name = abi::__cxa_demangle(mangled_name, NULL, NULL, NULL); #endif Index: unittests/Core/CMakeLists.txt =================================================================== --- unittests/Core/CMakeLists.txt +++ unittests/Core/CMakeLists.txt @@ -1,6 +1,7 @@ add_lldb_unittest(LLDBCoreTests BroadcasterTest.cpp DataExtractorTest.cpp + MangledTest.cpp ListenerTest.cpp ScalarTest.cpp StateTest.cpp Index: unittests/Core/MangledTest.cpp =================================================================== --- /dev/null +++ unittests/Core/MangledTest.cpp @@ -0,0 +1,38 @@ +//===-- MangledTest.cpp -----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" + +#include "lldb/Core/Mangled.h" + +using namespace lldb; +using namespace lldb_private; + +TEST(MangledTest, ResultForValidName) { + ConstString MangledName("_ZN1a1b1cIiiiEEvm"); + bool IsMangled = true; + + Mangled TheMangled(MangledName, IsMangled); + const ConstString &TheDemangled = + TheMangled.GetDemangledName(eLanguageTypeC_plus_plus); + + ConstString ExpectedResult("void a::b::c(unsigned long)"); + EXPECT_EQ(ExpectedResult, TheDemangled); +} + +TEST(MangledTest, EmptyForInvalidName) { + ConstString MangledName("_ZN1a1b1cmxktpEEvm"); + bool IsMangled = true; + + Mangled TheMangled(MangledName, IsMangled); + const ConstString &TheDemangled = + TheMangled.GetDemangledName(eLanguageTypeC_plus_plus); + + EXPECT_EQ(ConstString(""), TheDemangled); +}