bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, clayborg, jingham, labath.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Module::LookupInfo::Prune tries to prune results from lookups that don't
match the user-provided lookup information. If we're trying to match a
name with type eFunctionNameTypeFull, we want to match what the user
provided exactly. Currently, we try to see if what the user provided is
matches exactly assuming that a C++ name was provided. However, this is
specific to the C++ debugging path. LLDB supports more languages than
C++, so it is important that this codepath be language-agnostic.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128366
Files:
lldb/include/lldb/Target/Language.h
lldb/source/Core/Module.cpp
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp
lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
Index: lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
===================================================================
--- lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
+++ lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
@@ -42,6 +42,10 @@
static llvm::StringRef GetPluginNameStatic() { return "objcplusplus"; }
+ bool NamesAreEquivalentWithContext(
+ const ConstString &user_provided_name,
+ const ConstString &full_name_with_context) const override;
+
// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
Index: lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp
@@ -43,3 +43,18 @@
return nullptr;
}
}
+
+bool ObjCPlusPlusLanguage::NamesAreEquivalentWithContext(
+ const ConstString &user_provided_name,
+ const ConstString &full_name_with_context) const {
+ if (const auto *cpp_lang = Language::FindPlugin(eLanguageTypeC_plus_plus)) {
+ if (!cpp_lang->NamesAreEquivalentWithContext(user_provided_name,
+ full_name_with_context))
+ return false;
+ } else if (const auto *objc_lang = Language::FindPlugin(eLanguageTypeObjC)) {
+ if (!objc_lang->NamesAreEquivalentWithContext(user_provided_name,
+ full_name_with_context))
+ return false;
+ }
+ return true;
+}
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
===================================================================
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -155,6 +155,10 @@
return false;
}
+ bool NamesAreEquivalentWithContext(
+ const ConstString &user_provided_name,
+ const ConstString &full_name_with_context) const override;
+
// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -1147,6 +1147,19 @@
return canReadValue && isZero;
}
+bool ObjCLanguage::NamesAreEquivalentWithContext(
+ const ConstString &user_provided_name,
+ const ConstString &full_name_with_context) const {
+ ObjCLanguage::MethodName user_method(user_provided_name.GetCString(), false);
+ ObjCLanguage::MethodName full_method(full_name_with_context.GetCString(),
+ false);
+
+ if (!user_method.IsValid() || !full_method.IsValid())
+ return true;
+ return user_method.GetClassName() == full_method.GetClassName() &&
+ user_method.GetSelector() == full_method.GetSelector();
+}
+
bool ObjCLanguage::IsSourceFile(llvm::StringRef file_path) const {
const auto suffixes = {".h", ".m", ".M"};
for (auto suffix : suffixes) {
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -138,6 +138,10 @@
ConstString FindBestAlternateFunctionMangledName(
const Mangled mangled, const SymbolContext &sym_ctx) const override;
+ bool NamesAreEquivalentWithContext(
+ const ConstString &user_provided_name,
+ const ConstString &full_name_with_context) const override;
+
// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1397,3 +1397,28 @@
// that we could check for.
return file_path.contains("/usr/include/c++/");
}
+
+bool CPlusPlusLanguage::NamesAreEquivalentWithContext(
+ const ConstString &user_provided_name,
+ const ConstString &full_name_with_context) const {
+ MethodName method(full_name_with_context);
+ if (!method.IsValid())
+ return true;
+
+ if (method.GetContext().empty()) {
+ if (method.GetBasename().compare(user_provided_name.GetStringRef()) != 0)
+ return false;
+ } else {
+ std::string qualified_name;
+ llvm::StringRef anon_prefix("(anonymous namespace)");
+ if (method.GetContext() == anon_prefix)
+ qualified_name = method.GetBasename().str();
+ else
+ qualified_name = method.GetScopeQualifiedName();
+ if (qualified_name != user_provided_name.GetCString()) {
+ return false;
+ }
+ }
+
+ return true;
+}
Index: lldb/source/Core/Module.cpp
===================================================================
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -766,6 +766,17 @@
// "a::func()", "a::b::func()", "c::func()", "func()" and "func". Only
// "func()" and "func" should end up matching.
if (m_name_type_mask == eFunctionNameTypeFull) {
+ std::vector<Language *> languages;
+ if (m_language != eLanguageTypeUnknown) {
+ if (auto *lang = Language::FindPlugin(m_language))
+ languages.push_back(lang);
+ } else {
+ Language::ForEach([&languages](Language *l) {
+ languages.push_back(l);
+ return true;
+ });
+ }
+
SymbolContext sc;
size_t i = start_idx;
while (i < sc_list.GetSize()) {
@@ -776,26 +787,16 @@
ConstString mangled_name(sc.GetFunctionName(Mangled::ePreferMangled));
ConstString full_name(sc.GetFunctionName());
if (mangled_name != m_name && full_name != m_name) {
- CPlusPlusLanguage::MethodName cpp_method(full_name);
- if (cpp_method.IsValid()) {
- if (cpp_method.GetContext().empty()) {
- if (cpp_method.GetBasename().compare(m_name.GetStringRef()) != 0) {
- sc_list.RemoveContextAtIndex(i);
- continue;
- }
- } else {
- std::string qualified_name;
- llvm::StringRef anon_prefix("(anonymous namespace)");
- if (cpp_method.GetContext() == anon_prefix)
- qualified_name = cpp_method.GetBasename().str();
- else
- qualified_name = cpp_method.GetScopeQualifiedName();
- if (qualified_name != m_name.GetCString()) {
- sc_list.RemoveContextAtIndex(i);
- continue;
- }
+ bool removed = false;
+ for (const auto *lang : languages) {
+ if (!lang->NamesAreEquivalentWithContext(m_name, full_name)) {
+ sc_list.RemoveContextAtIndex(i);
+ removed = true;
+ break;
}
}
+ if (removed)
+ continue;
}
++i;
}
Index: lldb/include/lldb/Target/Language.h
===================================================================
--- lldb/include/lldb/Target/Language.h
+++ lldb/include/lldb/Target/Language.h
@@ -316,6 +316,12 @@
return ConstString();
}
+ virtual bool NamesAreEquivalentWithContext(
+ const ConstString &user_provided_name,
+ const ConstString &full_name_with_context) const {
+ return user_provided_name == full_name_with_context;
+ }
+
protected:
// Classes that inherit from Language can see and modify these
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits