bulbazord created this revision.
bulbazord added a reviewer: teemperor.
Herald added a subscriber: mgorny.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

We can extend/modify `GetMethodNameVariants` to suit our purposes here.
What symtab is looking for is alternate names we may want to use to
search for a specific symbol, and asking for variants of a name makes
the most sense here.

It might make more sense to wrap the ConstString and FunctionNameType
into a struct with a name, but for now I think a pair suffices.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104067

Files:
  lldb/include/lldb/Target/Language.h
  lldb/source/Breakpoint/BreakpointResolverName.cpp
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
  lldb/source/Symbol/CMakeLists.txt
  lldb/source/Symbol/Symtab.cpp

Index: lldb/source/Symbol/Symtab.cpp
===================================================================
--- lldb/source/Symbol/Symtab.cpp
+++ lldb/source/Symbol/Symtab.cpp
@@ -9,8 +9,6 @@
 #include <map>
 #include <set>
 
-#include "Plugins/Language/ObjC/ObjCLanguage.h"
-
 #include "lldb/Core/Module.h"
 #include "lldb/Core/RichManglingContext.h"
 #include "lldb/Core/Section.h"
@@ -18,6 +16,7 @@
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Symtab.h"
+#include "lldb/Target/Language.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/Timer.h"
@@ -330,13 +329,14 @@
 
         // If the demangled name turns out to be an ObjC name, and is a category
         // name, add the version without categories to the index too.
-        ObjCLanguage::MethodName objc_method(name.GetStringRef(), true);
-        if (objc_method.IsValid(true)) {
-          selector_to_index.Append(objc_method.GetSelector(), value);
-
-          if (ConstString objc_method_no_category =
-                  objc_method.GetFullNameWithoutCategory(true))
-            name_to_index.Append(objc_method_no_category, value);
+        if (auto *objc_lang = Language::FindPlugin(lldb::eLanguageTypeObjC)) {
+          for (auto variant_name_and_type :
+               objc_lang->GetMethodNameVariants(name)) {
+            if (variant_name_and_type.second & lldb::eFunctionNameTypeSelector)
+              selector_to_index.Append(variant_name_and_type.first, value);
+            else if (variant_name_and_type.second & lldb::eFunctionNameTypeFull)
+              name_to_index.Append(variant_name_and_type.first, value);
+          }
         }
       }
     }
Index: lldb/source/Symbol/CMakeLists.txt
===================================================================
--- lldb/source/Symbol/CMakeLists.txt
+++ lldb/source/Symbol/CMakeLists.txt
@@ -44,7 +44,6 @@
     lldbHost
     lldbTarget
     lldbUtility
-    lldbPluginObjCLanguage
 
   LINK_COMPONENTS
     Support
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
===================================================================
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -100,7 +100,8 @@
   //  variant_names[1] => "-[NSString(my_additions) myStringWithCString:]"
   //  variant_names[2] => "+[NSString myStringWithCString:]"
   //  variant_names[3] => "-[NSString myStringWithCString:]"
-  std::vector<ConstString>
+  // We also return the FunctionNameType of each possible name.
+  std::vector<std::pair<ConstString, lldb::FunctionNameType>>
   GetMethodNameVariants(ConstString method_name) const override;
 
   bool SymbolNameFitsToLanguage(Mangled mangled) const override;
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -225,14 +225,17 @@
   return ConstString();
 }
 
-std::vector<ConstString>
+std::vector<std::pair<ConstString, lldb::FunctionNameType>>
 ObjCLanguage::GetMethodNameVariants(ConstString method_name) const {
-  std::vector<ConstString> variant_names;
+  std::vector<std::pair<ConstString, lldb::FunctionNameType>> variant_names;
   ObjCLanguage::MethodName objc_method(method_name.GetCString(), false);
   if (!objc_method.IsValid(false)) {
     return variant_names;
   }
 
+  variant_names.emplace_back(std::make_pair(objc_method.GetSelector(),
+                                            lldb::eFunctionNameTypeSelector));
+
   const bool is_class_method =
       objc_method.GetType() == MethodName::eTypeClassMethod;
   const bool is_instance_method =
@@ -242,25 +245,30 @@
 
   if (is_class_method || is_instance_method) {
     if (name_sans_category)
-      variant_names.emplace_back(name_sans_category);
+      variant_names.emplace_back(
+          std::make_pair(name_sans_category, lldb::eFunctionNameTypeFull));
   } else {
     StreamString strm;
 
     strm.Printf("+%s", objc_method.GetFullName().GetCString());
-    variant_names.emplace_back(strm.GetString());
+    variant_names.emplace_back(
+        std::make_pair(strm.GetString(), lldb::eFunctionNameTypeFull));
     strm.Clear();
 
     strm.Printf("-%s", objc_method.GetFullName().GetCString());
-    variant_names.emplace_back(strm.GetString());
+    variant_names.emplace_back(
+        std::make_pair(strm.GetString(), lldb::eFunctionNameTypeFull));
     strm.Clear();
 
     if (name_sans_category) {
       strm.Printf("+%s", name_sans_category.GetCString());
-      variant_names.emplace_back(strm.GetString());
+      variant_names.emplace_back(
+          std::make_pair(strm.GetString(), lldb::eFunctionNameTypeFull));
       strm.Clear();
 
       strm.Printf("-%s", name_sans_category.GetCString());
-      variant_names.emplace_back(strm.GetString());
+      variant_names.emplace_back(
+          std::make_pair(strm.GetString(), lldb::eFunctionNameTypeFull));
     }
   }
 
Index: lldb/source/Breakpoint/BreakpointResolverName.cpp
===================================================================
--- lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -220,7 +220,8 @@
   m_lookups.emplace_back(lookup);
 
   auto add_variant_funcs = [&](Language *lang) {
-    for (ConstString variant_name : lang->GetMethodNameVariants(name)) {
+    for (auto variant_name_and_type : lang->GetMethodNameVariants(name)) {
+      auto variant_name = variant_name_and_type.first;
       Module::LookupInfo variant_lookup(name, name_type_mask,
                                         lang->GetLanguageType());
       variant_lookup.SetLookupName(variant_name);
Index: lldb/include/lldb/Target/Language.h
===================================================================
--- lldb/include/lldb/Target/Language.h
+++ lldb/include/lldb/Target/Language.h
@@ -187,9 +187,9 @@
   // If a language can have more than one possible name for a method, this
   // function can be used to enumerate them. This is useful when doing name
   // lookups.
-  virtual std::vector<ConstString>
+  virtual std::vector<std::pair<ConstString, lldb::FunctionNameType>>
   GetMethodNameVariants(ConstString method_name) const {
-    return std::vector<ConstString>();
+    return std::vector<std::pair<ConstString, lldb::FunctionNameType>>();
   };
 
   /// Returns true iff the given symbol name is compatible with the mangling
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to