Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a project: All.
Michael137 updated this revision to Diff 450757.
Michael137 added a comment.
Michael137 updated this revision to Diff 450991.
Michael137 retitled this revision from "[lldb] abi_tag support 2/4 - Make 
FindBestAlternateFunctionMangledName local to the C++ language plugin" to 
"[lldb] abi_tag support 2/3 - Make FindBestAlternateFunctionMangledName local 
to the C++ language plugin".
Michael137 added reviewers: labath, jingham.
Michael137 published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

- Rebase


Michael137 added a comment.

- Reword commit message



================
Comment at: lldb/include/lldb/Target/Language.h:315
+  ///
+  /// \param[out] results Will contain alternative mangled
+  ///                     function names.
----------------
Why not return results? Are we expecting to add more results to an existing 
vector regularly?


This patch makes `CPlusPlusLanguage::FindBestAlternateFunctionMangledName` local
to `CPlusPlusLanguage`. We do so by creating a new API 
`CollectAlternateFunctionNames`.
Both APIs are called only by `IRExecutionUnit`. However, by having
`FindBestAlternateFunctionMangledName` local to the C++ plugin we can
change its implementation in C++-specific ways, which we plan to do
in follow-up commits that add Itanium mangle tree API support to
`FindBestAlternateFunctionMangledName`.

**Testing**

- API tests still pass


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131333

Files:
  lldb/include/lldb/Target/Language.h
  lldb/source/Expression/IRExecutionUnit.cpp
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h

Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -135,8 +135,10 @@
   std::vector<ConstString>
   GenerateAlternateFunctionManglings(const ConstString mangled) const override;
 
-  ConstString FindBestAlternateFunctionMangledName(
-      const Mangled mangled, const SymbolContext &sym_ctx) const override;
+  void
+  CollectAlternateFunctionNames(std::vector<ConstString> &results,
+                                const std::vector<ConstString> &mangled_names,
+                                const SymbolContext &sc) 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
@@ -510,8 +510,8 @@
   return alternates;
 }
 
-ConstString CPlusPlusLanguage::FindBestAlternateFunctionMangledName(
-    const Mangled mangled, const SymbolContext &sym_ctx) const {
+static ConstString FindBestAlternateFunctionMangledName(
+    const Mangled mangled, const SymbolContext &sym_ctx) {
   ConstString demangled = mangled.GetDemangledName();
   if (!demangled)
     return ConstString();
@@ -560,6 +560,7 @@
     return ConstString();
 }
 
+
 static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   if (!cpp_category_sp)
     return;
@@ -1405,3 +1406,28 @@
   // that we could check for.
   return file_path.contains("/usr/include/c++/");
 }
+
+void CPlusPlusLanguage::CollectAlternateFunctionNames(
+    std::vector<ConstString> &results,
+    const std::vector<ConstString> &mangled_names,
+    const SymbolContext &sc) const {
+  for (const ConstString &name : mangled_names) {
+    Mangled mangled(name);
+    if (SymbolNameFitsToLanguage(mangled)) {
+      if (ConstString best_alternate =
+              FindBestAlternateFunctionMangledName(mangled, sc)) {
+        results.push_back(best_alternate);
+      }
+    }
+
+    std::vector<ConstString> alternates =
+        GenerateAlternateFunctionManglings(name);
+    results.insert(results.end(), alternates.begin(), alternates.end());
+
+    // As a last-ditch fallback, try the base name for C++ names.  It's
+    // terrible, but the DWARF doesn't always encode "extern C" correctly.
+    ConstString basename =
+        GetDemangledFunctionNameWithoutArguments(mangled);
+    results.push_back(basename);
+  }
+}
Index: lldb/source/Expression/IRExecutionUnit.cpp
===================================================================
--- lldb/source/Expression/IRExecutionUnit.cpp
+++ lldb/source/Expression/IRExecutionUnit.cpp
@@ -675,25 +675,7 @@
     std::vector<ConstString> &CPP_names,
     const std::vector<ConstString> &C_names, const SymbolContext &sc) {
   if (auto *cpp_lang = Language::FindPlugin(lldb::eLanguageTypeC_plus_plus)) {
-    for (const ConstString &name : C_names) {
-      Mangled mangled(name);
-      if (cpp_lang->SymbolNameFitsToLanguage(mangled)) {
-        if (ConstString best_alternate =
-                cpp_lang->FindBestAlternateFunctionMangledName(mangled, sc)) {
-          CPP_names.push_back(best_alternate);
-        }
-      }
-
-      std::vector<ConstString> alternates =
-          cpp_lang->GenerateAlternateFunctionManglings(name);
-      CPP_names.insert(CPP_names.end(), alternates.begin(), alternates.end());
-
-      // As a last-ditch fallback, try the base name for C++ names.  It's
-      // terrible, but the DWARF doesn't always encode "extern C" correctly.
-      ConstString basename =
-          cpp_lang->GetDemangledFunctionNameWithoutArguments(mangled);
-      CPP_names.push_back(basename);
-    }
+    cpp_lang->CollectAlternateFunctionNames(CPP_names, C_names, sc);
   }
 }
 
Index: lldb/include/lldb/Target/Language.h
===================================================================
--- lldb/include/lldb/Target/Language.h
+++ lldb/include/lldb/Target/Language.h
@@ -310,11 +310,20 @@
     return std::vector<ConstString>();
   }
 
-  virtual ConstString
-  FindBestAlternateFunctionMangledName(const Mangled mangled,
-                                       const SymbolContext &sym_ctx) const {
-    return ConstString();
-  }
+  /// Generates a list of mangled function name alternatives
+  ///
+  /// \param[out] results Will contain alternative mangled
+  ///                     function names.
+  ///
+  /// \param[in] mangled_names List of mangled names to generate
+  ///                          alternatives for.
+  ///
+  /// \param[in] sc SymbolContext used to find approximately matching
+  ///               mangled function names.
+  virtual void
+  CollectAlternateFunctionNames(std::vector<ConstString> &results,
+                                const std::vector<ConstString> &mangled_names,
+                                const SymbolContext &sc) const {}
 
 protected:
   // Classes that inherit from Language can see and modify these
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to