[Lldb-commits] [lldb] r337931 - Use LLVM's new ItaniumPartialDemangler in LLDB
Stefan Granitz via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 25 08:19:04 PDT 2018
Author: stefan.graenitz
Date: Wed Jul 25 08:19:04 2018
New Revision: 337931
URL: http://llvm.org/viewvc/llvm-project?rev=337931&view=rev
Log:
Use LLVM's new ItaniumPartialDemangler in LLDB
Summary:
Replace the existing combination of FastDemangle and the fallback to llvm::itaniumDemangle() with LLVM's new ItaniumPartialDemangler. It slightly reduces complexity and slightly improves performance, but doesn't introduce conceptual changes. This patch is preparing for more fundamental improvements on LLDB's demangling approach.
Reviewers: friss, jingham, erik.pilkington, labath, clayborg, mgorny, davide, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: teemperor, JDevlieghere, labath, clayborg, davide, lldb-commits, mgorny, erik.pilkington
Differential Revision: https://reviews.llvm.org/D49612
Added:
lldb/trunk/unittests/Core/MangledTest.cpp
Modified:
lldb/trunk/cmake/modules/LLDBConfig.cmake
lldb/trunk/lldb.xcodeproj/project.pbxproj
lldb/trunk/source/Core/Mangled.cpp
lldb/trunk/unittests/Core/CMakeLists.txt
Modified: lldb/trunk/cmake/modules/LLDBConfig.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/LLDBConfig.cmake?rev=337931&r1=337930&r2=337931&view=diff
==============================================================================
--- lldb/trunk/cmake/modules/LLDBConfig.cmake (original)
+++ lldb/trunk/cmake/modules/LLDBConfig.cmake Wed Jul 25 08:19:04 2018
@@ -411,15 +411,6 @@ if(LLDB_USING_LIBSTDCXX)
endif()
endif()
-if(MSVC)
- set(LLDB_USE_BUILTIN_DEMANGLER ON)
-else()
- option(LLDB_USE_BUILTIN_DEMANGLER "Use lldb's builtin demangler instead of the system one" ON)
-endif()
-if(LLDB_USE_BUILTIN_DEMANGLER)
- add_definitions(-DLLDB_USE_BUILTIN_DEMANGLER)
-endif()
-
if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND
((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips")))
add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND)
Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=337931&r1=337930&r2=337931&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Wed Jul 25 08:19:04 2018
@@ -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 */; };
@@ -2185,6 +2186,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 = "<group>"; };
26BC7D6910F1B77400F91463 /* Mangled.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Mangled.h; path = include/lldb/Core/Mangled.h; sourceTree = "<group>"; };
+ 4F29D3CD21010F84003B549A /* MangledTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MangledTest.cpp; sourceTree = "<group>"; };
4CD44CF920B37C440003557C /* ManualDWARFIndex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ManualDWARFIndex.cpp; sourceTree = "<group>"; };
4CD44D0020B37C580003557C /* ManualDWARFIndex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ManualDWARFIndex.h; sourceTree = "<group>"; };
2682100C143A59AE004BCF2D /* MappedHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MappedHash.h; path = include/lldb/Core/MappedHash.h; sourceTree = "<group>"; };
@@ -3657,6 +3659,7 @@
23CB14E51D66CBEB00EDDDE1 /* Core */ = {
isa = PBXGroup;
children = (
+ 4F29D3CD21010F84003B549A /* MangledTest.cpp */,
9A3D43E31F3237D500EB767C /* ListenerTest.cpp */,
9A3D43E21F3237D500EB767C /* StateTest.cpp */,
9A3D43E11F3237D500EB767C /* StreamCallbackTest.cpp */,
@@ -7443,6 +7446,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 */,
@@ -9326,14 +9330,12 @@
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = (
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
OTHER_LDFLAGS = "";
@@ -9385,14 +9387,12 @@
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = (
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
OTHER_LDFLAGS = "";
@@ -9444,14 +9444,12 @@
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = (
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
OTHER_LDFLAGS = "";
@@ -10453,14 +10451,12 @@
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*]" = (
"-fno-rtti",
"-Wglobal-constructors",
"$(OTHER_CFLAGS)",
- "-DLLDB_USE_BUILTIN_DEMANGLER",
"-DLIBXML2_DEFINED",
);
OTHER_LDFLAGS = "";
Modified: lldb/trunk/source/Core/Mangled.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Mangled.cpp?rev=337931&r1=337930&r2=337931&view=diff
==============================================================================
--- lldb/trunk/source/Core/Mangled.cpp (original)
+++ lldb/trunk/source/Core/Mangled.cpp Wed Jul 25 08:19:04 2018
@@ -16,34 +16,24 @@
#pragma comment(lib, "dbghelp.lib")
#endif
-#ifdef 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"
-#else
-// FreeBSD9-STABLE requires this to know about size_t in cxxabi.
-#include <cstddef>
-#include <cxxabi.h>
-#endif
-
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Logging.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/Timer.h"
-#include "lldb/lldb-enumerations.h" // for LanguageType
+#include "lldb/lldb-enumerations.h"
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
#include "Plugins/Language/ObjC/ObjCLanguage.h"
-#include "llvm/ADT/StringRef.h" // for StringRef
-#include "llvm/Support/Compiler.h" // for LLVM_PRETT...
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Demangle/Demangle.h"
+#include "llvm/Support/Compiler.h"
-#include <mutex> // for mutex, loc...
-#include <string> // for string
-#include <utility> // for pair
+#include <mutex>
+#include <string>
+#include <utility>
#include <stdlib.h>
#include <string.h>
@@ -295,18 +285,15 @@ Mangled::GetDemangledName(lldb::Language
break;
}
case eManglingSchemeItanium: {
-#ifdef 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,
- // falling back to the full demangler only when necessary
- demangled_name = FastDemangle(mangled_name, m_mangled.GetLength());
- if (!demangled_name)
- demangled_name =
- llvm::itaniumDemangle(mangled_name, NULL, NULL, NULL);
-#else
- demangled_name = abi::__cxa_demangle(mangled_name, NULL, NULL, NULL);
-#endif
+ 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 demangled_size = 80;
+ demangled_name = static_cast<char *>(::malloc(demangled_size));
+ demangled_name = IPD.finishDemangle(demangled_name, &demangled_size);
+ }
+
if (log) {
if (demangled_name)
log->Printf("demangled itanium: %s -> \"%s\"", mangled_name,
Modified: lldb/trunk/unittests/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/CMakeLists.txt?rev=337931&r1=337930&r2=337931&view=diff
==============================================================================
--- lldb/trunk/unittests/Core/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Core/CMakeLists.txt Wed Jul 25 08:19:04 2018
@@ -3,6 +3,7 @@ add_lldb_unittest(LLDBCoreTests
DataExtractorTest.cpp
EventTest.cpp
ListenerTest.cpp
+ MangledTest.cpp
ScalarTest.cpp
StateTest.cpp
StreamCallbackTest.cpp
Added: lldb/trunk/unittests/Core/MangledTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/MangledTest.cpp?rev=337931&view=auto
==============================================================================
--- lldb/trunk/unittests/Core/MangledTest.cpp (added)
+++ lldb/trunk/unittests/Core/MangledTest.cpp Wed Jul 25 08:19:04 2018
@@ -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<int, int, int>(unsigned long)");
+ EXPECT_STREQ(ExpectedResult.GetCString(), TheDemangled.GetCString());
+}
+
+TEST(MangledTest, EmptyForInvalidName) {
+ ConstString MangledName("_ZN1a1b1cmxktpEEvm");
+ bool IsMangled = true;
+
+ Mangled TheMangled(MangledName, IsMangled);
+ const ConstString &TheDemangled =
+ TheMangled.GetDemangledName(eLanguageTypeC_plus_plus);
+
+ EXPECT_STREQ("", TheDemangled.GetCString());
+}
More information about the lldb-commits
mailing list