summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Core')
-rw-r--r--lldb/source/Core/ConstString.cpp72
-rw-r--r--lldb/source/Core/History.cpp25
-rw-r--r--lldb/source/Core/Mangled.cpp30
3 files changed, 92 insertions, 35 deletions
diff --git a/lldb/source/Core/ConstString.cpp b/lldb/source/Core/ConstString.cpp
index e3b0623502d..94dd43da8a0 100644
--- a/lldb/source/Core/ConstString.cpp
+++ b/lldb/source/Core/ConstString.cpp
@@ -32,6 +32,10 @@ using namespace lldb_private;
class Pool
{
public:
+ typedef const char * StringPoolValueType;
+ typedef llvm::StringMap<StringPoolValueType, llvm::BumpPtrAllocator> StringPool;
+ typedef llvm::StringMapEntry<StringPoolValueType> StringPoolEntryType;
+
//------------------------------------------------------------------
// Default constructor
//
@@ -51,24 +55,44 @@ public:
}
- static llvm::StringMapEntry<uint32_t> &
+ static StringPoolEntryType &
GetStringMapEntryFromKeyData (const char *keyData)
{
- char *ptr = const_cast<char*>(keyData) - sizeof (llvm::StringMapEntry<uint32_t>);
- return *reinterpret_cast<llvm::StringMapEntry<uint32_t>*>(ptr);
+ char *ptr = const_cast<char*>(keyData) - sizeof (StringPoolEntryType);
+ return *reinterpret_cast<StringPoolEntryType*>(ptr);
}
size_t
- GetConstCStringLength (const char *ccstr)
+ GetConstCStringLength (const char *ccstr) const
{
if (ccstr)
{
- llvm::StringMapEntry<uint32_t>&entry = GetStringMapEntryFromKeyData (ccstr);
+ const StringPoolEntryType&entry = GetStringMapEntryFromKeyData (ccstr);
return entry.getKey().size();
}
return 0;
}
+ StringPoolValueType
+ GetMangledCounterpart (const char *ccstr) const
+ {
+ if (ccstr)
+ return GetStringMapEntryFromKeyData (ccstr).getValue();
+ return 0;
+ }
+
+ bool
+ SetMangledCounterparts (const char *key_ccstr, const char *value_ccstr)
+ {
+ if (key_ccstr && value_ccstr)
+ {
+ GetStringMapEntryFromKeyData (key_ccstr).setValue(value_ccstr);
+ GetStringMapEntryFromKeyData (value_ccstr).setValue(key_ccstr);
+ return true;
+ }
+ return false;
+ }
+
const char *
GetConstCString (const char *cstr)
{
@@ -84,13 +108,33 @@ public:
{
Mutex::Locker locker (m_mutex);
llvm::StringRef string_ref (cstr, cstr_len);
- llvm::StringMapEntry<uint32_t>& entry = m_string_map.GetOrCreateValue (string_ref);
+ StringPoolEntryType& entry = m_string_map.GetOrCreateValue (string_ref);
return entry.getKeyData();
}
return NULL;
}
const char *
+ GetConstCStringAndSetMangledCounterPart (const char *demangled_cstr, const char *mangled_ccstr)
+ {
+ if (demangled_cstr)
+ {
+ Mutex::Locker locker (m_mutex);
+ // Make string pool entry with the mangled counterpart already set
+ StringPoolEntryType& entry = m_string_map.GetOrCreateValue (llvm::StringRef (demangled_cstr), mangled_ccstr);
+
+ // Extract the const version of the demangled_cstr
+ const char *demangled_ccstr = entry.getKeyData();
+ // Now assign the demangled const string as the counterpart of the
+ // mangled const string...
+ GetStringMapEntryFromKeyData (mangled_ccstr).setValue(demangled_ccstr);
+ // Return the constant demangled C string
+ return demangled_ccstr;
+ }
+ return NULL;
+ }
+
+ const char *
GetConstTrimmedCStringWithLength (const char *cstr, int cstr_len)
{
if (cstr)
@@ -114,7 +158,7 @@ public:
const_iterator end = m_string_map.end();
for (const_iterator pos = m_string_map.begin(); pos != end; ++pos)
{
- mem_size += sizeof(llvm::StringMapEntry<uint32_t>) + pos->getKey().size();
+ mem_size += sizeof(StringPoolEntryType) + pos->getKey().size();
}
return mem_size;
}
@@ -123,7 +167,6 @@ protected:
//------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------
- typedef llvm::StringMap<uint32_t, llvm::BumpPtrAllocator> StringPool;
typedef StringPool::iterator iterator;
typedef StringPool::const_iterator const_iterator;
@@ -320,6 +363,19 @@ ConstString::SetCString (const char *cstr)
m_string = StringPool().GetConstCString (cstr);
}
+void
+ConstString::SetCStringWithMangledCounterpart (const char *demangled, const ConstString &mangled)
+{
+ m_string = StringPool().GetConstCStringAndSetMangledCounterPart (demangled, mangled.m_string);
+}
+
+bool
+ConstString::GetMangledCounterpart (ConstString &counterpart) const
+{
+ counterpart.m_string = StringPool().GetMangledCounterpart(m_string);
+ return counterpart;
+}
+
//----------------------------------------------------------------------
// Set the string value in the object by uniquing "cstr_len" bytes
// starting at the "cstr" string value in our global string pool.
diff --git a/lldb/source/Core/History.cpp b/lldb/source/Core/History.cpp
new file mode 100644
index 00000000000..929c8544798
--- /dev/null
+++ b/lldb/source/Core/History.cpp
@@ -0,0 +1,25 @@
+//===-- History.cpp ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Core/History.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Stream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+void
+HistorySourceUInt::DumpHistoryEvent (Stream &strm, HistoryEvent event)
+{
+ strm.Printf ("%s %llu", m_name.c_str(), (uint64_t)((uintptr_t)event));
+}
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 110fa656281..839154d5914 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -152,29 +152,9 @@ Mangled::GetDemangledName () const
// lets just make sure it isn't empty...
const char * mangled = m_mangled.AsCString();
// Don't bother running anything that doesn't start with _Z through the demangler
- if (mangled[0] != '\0' && mangled[0] == '_' && mangled[1] == 'Z')
+ if (mangled[0] == '_' && mangled[1] == 'Z')
{
- // Since demangling can be a costly, and since all names that go
- // into a ConstString (like our m_mangled and m_demangled members)
- // end up being unique "const char *" values, we can use a DenseMap
- // to speed up our lookup. We do this because often our symbol table
- // and our debug information both have the mangled names which they
- // would each need to demangle. Also, with GCC we end up with the one
- // definition rule where a lot of STL code produces symbols that are
- // in multiple compile units and the mangled names end up being in
- // the same binary multiple times. The performance win isn't huge,
- // but we showed a 20% improvement on darwin.
- typedef llvm::DenseMap<const char *, const char *> MangledToDemangledMap;
- static MangledToDemangledMap g_mangled_to_demangled;
-
- // Check our mangled string pointer to demangled string pointer map first
- MangledToDemangledMap::const_iterator pos = g_mangled_to_demangled.find (mangled);
- if (pos != g_mangled_to_demangled.end())
- {
- // We have already demangled this string, we can just use our saved result!
- m_demangled.SetCString(pos->second);
- }
- else
+ if (!m_mangled.GetMangledCounterpart(m_demangled))
{
// We didn't already mangle this name, demangle it and if all goes well
// add it to our map.
@@ -182,11 +162,7 @@ Mangled::GetDemangledName () const
if (demangled_name)
{
- m_demangled.SetCString (demangled_name);
- // Now that the name has been uniqued, add the uniqued C string
- // pointer from m_mangled as the key to the uniqued C string
- // pointer in m_demangled.
- g_mangled_to_demangled.insert (std::make_pair (mangled, m_demangled.GetCString()));
+ m_demangled.SetCStringWithMangledCounterpart(demangled_name, m_mangled);
free (demangled_name);
}
}
OpenPOWER on IntegriCloud