summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Utility/ConstString.h7
-rw-r--r--lldb/source/Core/Mangled.cpp2
-rw-r--r--lldb/source/Utility/ConstString.cpp50
-rw-r--r--lldb/unittests/Utility/ConstStringTest.cpp17
4 files changed, 44 insertions, 32 deletions
diff --git a/lldb/include/lldb/Utility/ConstString.h b/lldb/include/lldb/Utility/ConstString.h
index 98b3447abe3..b6169a084d8 100644
--- a/lldb/include/lldb/Utility/ConstString.h
+++ b/lldb/include/lldb/Utility/ConstString.h
@@ -373,15 +373,14 @@ public:
/// them.
///
/// @param[in] demangled
- /// The demangled C string to correlate with the \a mangled
- /// name.
+ /// The demangled string to correlate with the \a mangled name.
///
/// @param[in] mangled
/// The already uniqued mangled ConstString to correlate the
/// soon to be uniqued version of \a demangled.
//------------------------------------------------------------------
- void SetCStringWithMangledCounterpart(const char *demangled,
- const ConstString &mangled);
+ void SetStringWithMangledCounterpart(llvm::StringRef demangled,
+ const ConstString &mangled);
//------------------------------------------------------------------
/// Retrieve the mangled or demangled counterpart for a mangled or demangled
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 545ac51c870..043afe735fd 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -308,7 +308,7 @@ Mangled::GetDemangledName(lldb::LanguageType language) const {
break;
}
if (demangled_name) {
- m_demangled.SetCStringWithMangledCounterpart(demangled_name, m_mangled);
+ m_demangled.SetStringWithMangledCounterpart(demangled_name, m_mangled);
free(demangled_name);
}
}
diff --git a/lldb/source/Utility/ConstString.cpp b/lldb/source/Utility/ConstString.cpp
index 5ef4b2faa3b..e903783df52 100644
--- a/lldb/source/Utility/ConstString.cpp
+++ b/lldb/source/Utility/ConstString.cpp
@@ -111,38 +111,34 @@ public:
}
const char *
- GetConstCStringAndSetMangledCounterPart(const char *demangled_cstr,
+ GetConstCStringAndSetMangledCounterPart(llvm::StringRef demangled,
const char *mangled_ccstr) {
- if (demangled_cstr != nullptr) {
- const char *demangled_ccstr = nullptr;
+ const char *demangled_ccstr = nullptr;
- {
- llvm::StringRef string_ref(demangled_cstr);
- const uint8_t h = hash(string_ref);
- llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
-
- // Make string pool entry with the mangled counterpart already set
- StringPoolEntryType &entry =
- *m_string_pools[h]
- .m_string_map.insert(std::make_pair(string_ref, mangled_ccstr))
- .first;
+ {
+ const uint8_t h = hash(demangled);
+ llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
- // Extract the const version of the demangled_cstr
- demangled_ccstr = entry.getKeyData();
- }
+ // Make string pool entry with the mangled counterpart already set
+ StringPoolEntryType &entry =
+ *m_string_pools[h]
+ .m_string_map.insert(std::make_pair(demangled, mangled_ccstr))
+ .first;
- {
- // Now assign the demangled const string as the counterpart of the
- // mangled const string...
- const uint8_t h = hash(llvm::StringRef(mangled_ccstr));
- llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
- GetStringMapEntryFromKeyData(mangled_ccstr).setValue(demangled_ccstr);
- }
+ // Extract the const version of the demangled_cstr
+ demangled_ccstr = entry.getKeyData();
+ }
- // Return the constant demangled C string
- return demangled_ccstr;
+ {
+ // Now assign the demangled const string as the counterpart of the
+ // mangled const string...
+ const uint8_t h = hash(llvm::StringRef(mangled_ccstr));
+ llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
+ GetStringMapEntryFromKeyData(mangled_ccstr).setValue(demangled_ccstr);
}
- return nullptr;
+
+ // Return the constant demangled C string
+ return demangled_ccstr;
}
const char *GetConstTrimmedCStringWithLength(const char *cstr,
@@ -306,7 +302,7 @@ void ConstString::SetString(const llvm::StringRef &s) {
m_string = StringPool().GetConstCStringWithLength(s.data(), s.size());
}
-void ConstString::SetCStringWithMangledCounterpart(const char *demangled,
+void ConstString::SetStringWithMangledCounterpart(llvm::StringRef demangled,
const ConstString &mangled) {
m_string = StringPool().GetConstCStringAndSetMangledCounterPart(
demangled, mangled.m_string);
diff --git a/lldb/unittests/Utility/ConstStringTest.cpp b/lldb/unittests/Utility/ConstStringTest.cpp
index 454f656760c..2c87f2bc154 100644
--- a/lldb/unittests/Utility/ConstStringTest.cpp
+++ b/lldb/unittests/Utility/ConstStringTest.cpp
@@ -16,3 +16,20 @@ using namespace lldb_private;
TEST(ConstStringTest, format_provider) {
EXPECT_EQ("foo", llvm::formatv("{0}", ConstString("foo")).str());
}
+
+TEST(ConstStringTest, MangledCounterpart) {
+ ConstString foo("foo");
+ ConstString counterpart;
+ EXPECT_FALSE(foo.GetMangledCounterpart(counterpart));
+ EXPECT_EQ("", counterpart.GetStringRef());
+
+ ConstString bar;
+ bar.SetStringWithMangledCounterpart("bar", foo);
+ EXPECT_EQ("bar", bar.GetStringRef());
+
+ EXPECT_TRUE(bar.GetMangledCounterpart(counterpart));
+ EXPECT_EQ("foo", counterpart.GetStringRef());
+
+ EXPECT_TRUE(foo.GetMangledCounterpart(counterpart));
+ EXPECT_EQ("bar", counterpart.GetStringRef());
+}
OpenPOWER on IntegriCloud