aboutsummaryrefslogtreecommitdiff
path: root/source/Core/Mangled.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:09:23 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:09:23 +0000
commitf73363f1dd94996356cefbf24388f561891acf0b (patch)
treee3c31248bdb36eaec5fd833490d4278162dba2a0 /source/Core/Mangled.cpp
parent160ee69dd7ae18978f4068116777639ea98dc951 (diff)
Notes
Diffstat (limited to 'source/Core/Mangled.cpp')
-rw-r--r--source/Core/Mangled.cpp118
1 files changed, 50 insertions, 68 deletions
diff --git a/source/Core/Mangled.cpp b/source/Core/Mangled.cpp
index 211a0c32cee7f..545ac51c870f2 100644
--- a/source/Core/Mangled.cpp
+++ b/source/Core/Mangled.cpp
@@ -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>
@@ -90,10 +80,8 @@ get_demangled_name_without_arguments(ConstString mangled,
g_most_recent_mangled_to_name_sans_args;
// Need to have the mangled & demangled names we're currently examining as
- // statics
- // so we can return a const ref to them at the end of the func if we don't
- // have
- // anything better.
+ // statics so we can return a const ref to them at the end of the func if we
+ // don't have anything better.
static ConstString g_last_mangled;
static ConstString g_last_demangled;
@@ -142,8 +130,8 @@ get_demangled_name_without_arguments(ConstString mangled,
Mangled::Mangled() : m_mangled(), m_demangled() {}
//----------------------------------------------------------------------
-// Constructor with an optional string and a boolean indicating if it is
-// the mangled version.
+// Constructor with an optional string and a boolean indicating if it is the
+// mangled version.
//----------------------------------------------------------------------
Mangled::Mangled(const ConstString &s, bool mangled)
: m_mangled(), m_demangled() {
@@ -172,8 +160,8 @@ Mangled::Mangled(llvm::StringRef name) {
Mangled::~Mangled() {}
//----------------------------------------------------------------------
-// Convert to pointer operator. This allows code to check any Mangled
-// objects to see if they contain anything valid using code such as:
+// Convert to pointer operator. This allows code to check any Mangled objects
+// to see if they contain anything valid using code such as:
//
// Mangled mangled(...);
// if (mangled)
@@ -184,8 +172,8 @@ Mangled::operator void *() const {
}
//----------------------------------------------------------------------
-// Logical NOT operator. This allows code to check any Mangled
-// objects to see if they are invalid using code such as:
+// Logical NOT operator. This allows code to check any Mangled objects to see
+// if they are invalid using code such as:
//
// Mangled mangled(...);
// if (!file_spec)
@@ -211,9 +199,8 @@ int Mangled::Compare(const Mangled &a, const Mangled &b) {
}
//----------------------------------------------------------------------
-// Set the string value in this objects. If "mangled" is true, then
-// the mangled named is set with the new value in "s", else the
-// demangled name is set.
+// Set the string value in this objects. If "mangled" is true, then the mangled
+// named is set with the new value in "s", else the demangled name is set.
//----------------------------------------------------------------------
void Mangled::SetValue(const ConstString &s, bool mangled) {
if (s) {
@@ -246,16 +233,15 @@ void Mangled::SetValue(const ConstString &name) {
}
//----------------------------------------------------------------------
-// Generate the demangled name on demand using this accessor. Code in
-// this class will need to use this accessor if it wishes to decode
-// the demangled name. The result is cached and will be kept until a
-// new string value is supplied to this object, or until the end of the
-// object's lifetime.
+// Generate the demangled name on demand using this accessor. Code in this
+// class will need to use this accessor if it wishes to decode the demangled
+// name. The result is cached and will be kept until a new string value is
+// supplied to this object, or until the end of the object's lifetime.
//----------------------------------------------------------------------
const ConstString &
Mangled::GetDemangledName(lldb::LanguageType language) const {
- // Check to make sure we have a valid mangled name and that we
- // haven't already decoded our mangled name.
+ // Check to make sure we have a valid mangled name and that we haven't
+ // already decoded our mangled name.
if (m_mangled && !m_demangled) {
// We need to generate and cache the demangled name.
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
@@ -299,19 +285,15 @@ Mangled::GetDemangledName(lldb::LanguageType language) const {
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,
@@ -331,8 +313,8 @@ Mangled::GetDemangledName(lldb::LanguageType language) const {
}
}
if (!m_demangled) {
- // Set the demangled string to the empty string to indicate we
- // tried to parse it once and failed.
+ // Set the demangled string to the empty string to indicate we tried to
+ // parse it once and failed.
m_demangled.SetCString("");
}
}
@@ -370,8 +352,8 @@ ConstString Mangled::GetName(lldb::LanguageType language,
return get_demangled_name_without_arguments(m_mangled, demangled);
}
if (preference == ePreferDemangled) {
- // Call the accessor to make sure we get a demangled name in case
- // it hasn't been demangled yet...
+ // Call the accessor to make sure we get a demangled name in case it hasn't
+ // been demangled yet...
if (demangled)
return demangled;
return m_mangled;
@@ -380,8 +362,8 @@ ConstString Mangled::GetName(lldb::LanguageType language,
}
//----------------------------------------------------------------------
-// Dump a Mangled object to stream "s". We don't force our
-// demangled name to be computed currently (we don't use the accessor).
+// Dump a Mangled object to stream "s". We don't force our demangled name to be
+// computed currently (we don't use the accessor).
//----------------------------------------------------------------------
void Mangled::Dump(Stream *s) const {
if (m_mangled) {
@@ -394,8 +376,8 @@ void Mangled::Dump(Stream *s) const {
}
//----------------------------------------------------------------------
-// Dumps a debug version of this string with extra object and state
-// information to stream "s".
+// Dumps a debug version of this string with extra object and state information
+// to stream "s".
//----------------------------------------------------------------------
void Mangled::DumpDebug(Stream *s) const {
s->Printf("%*p: Mangled mangled = ", static_cast<int>(sizeof(void *) * 2),
@@ -406,21 +388,21 @@ void Mangled::DumpDebug(Stream *s) const {
}
//----------------------------------------------------------------------
-// Return the size in byte that this object takes in memory. The size
-// includes the size of the objects it owns, and not the strings that
-// it references because they are shared strings.
+// Return the size in byte that this object takes in memory. The size includes
+// the size of the objects it owns, and not the strings that it references
+// because they are shared strings.
//----------------------------------------------------------------------
size_t Mangled::MemorySize() const {
return m_mangled.MemorySize() + m_demangled.MemorySize();
}
//----------------------------------------------------------------------
-// We "guess" the language because we can't determine a symbol's language
-// from it's name. For example, a Pascal symbol can be mangled using the
-// C++ Itanium scheme, and defined in a compilation unit within the same
-// module as other C++ units. In addition, different targets could have
-// different ways of mangling names from a given language, likewise the
-// compilation units within those targets.
+// We "guess" the language because we can't determine a symbol's language from
+// it's name. For example, a Pascal symbol can be mangled using the C++
+// Itanium scheme, and defined in a compilation unit within the same module as
+// other C++ units. In addition, different targets could have different ways
+// of mangling names from a given language, likewise the compilation units
+// within those targets.
//----------------------------------------------------------------------
lldb::LanguageType Mangled::GuessLanguage() const {
ConstString mangled = GetMangledName();
@@ -433,7 +415,7 @@ lldb::LanguageType Mangled::GuessLanguage() const {
return lldb::eLanguageTypeObjC;
}
} else {
- // ObjC names aren't really mangled, so they won't necessarily be in the
+ // ObjC names aren't really mangled, so they won't necessarily be in the
// mangled name slot.
ConstString demangled_name = GetDemangledName(lldb::eLanguageTypeUnknown);
if (demangled_name