[Lldb-commits] [lldb] 4355265 - [lldb] Remove IRExecutionUnit::CollectFallbackNames

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 22 11:04:06 PDT 2021


Author: Alex Langford
Date: 2021-09-22T11:01:15-07:00
New Revision: 43552651319e1c39c09ce0f61b588813414cebda

URL: https://github.com/llvm/llvm-project/commit/43552651319e1c39c09ce0f61b588813414cebda
DIFF: https://github.com/llvm/llvm-project/commit/43552651319e1c39c09ce0f61b588813414cebda.diff

LOG: [lldb] Remove IRExecutionUnit::CollectFallbackNames

The work that IRExecutionUnit::CollectFallbackNames is basically the
work that `CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments`
does already. It's also (at time or writing) specific to C++, so it can
be folded into `IRExecutionUnit::CollectCandidateCPlusPlusNames`.

Differential Revision: https://reviews.llvm.org/D109928

Added: 
    

Modified: 
    lldb/include/lldb/Expression/IRExecutionUnit.h
    lldb/source/Expression/IRExecutionUnit.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h
index 29dae4dc50fa..bb43851e17c9 100644
--- a/lldb/include/lldb/Expression/IRExecutionUnit.h
+++ b/lldb/include/lldb/Expression/IRExecutionUnit.h
@@ -221,9 +221,6 @@ class IRExecutionUnit : public std::enable_shared_from_this<IRExecutionUnit>,
                                       const std::vector<ConstString> &C_names,
                                       const SymbolContext &sc);
 
-  void CollectFallbackNames(std::vector<ConstString> &fallback_names,
-                            const std::vector<ConstString> &C_names);
-
   lldb::addr_t FindInSymbols(const std::vector<ConstString> &names,
                              const lldb_private::SymbolContext &sc,
                              bool &symbol_was_missing_weak);

diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index 4306a9c2505c..39ece8308641 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -708,51 +708,27 @@ void IRExecutionUnit::CollectCandidateCNames(std::vector<ConstString> &C_names,
 void IRExecutionUnit::CollectCandidateCPlusPlusNames(
     std::vector<ConstString> &CPP_names,
     const std::vector<ConstString> &C_names, const SymbolContext &sc) {
-  for (const ConstString &name : C_names) {
-    if (CPlusPlusLanguage::IsCPPMangledName(name.GetCString())) {
+  if (auto *cpp_lang = Language::FindPlugin(lldb::eLanguageTypeC_plus_plus)) {
+    for (const ConstString &name : C_names) {
       Mangled mangled(name);
-      ConstString demangled = mangled.GetDemangledName();
-
-      if (demangled) {
-        ConstString best_alternate_mangled_name =
-            FindBestAlternateMangledName(demangled, sc);
-
-        if (best_alternate_mangled_name) {
-          CPP_names.push_back(best_alternate_mangled_name);
+      if (cpp_lang->SymbolNameFitsToLanguage(mangled)) {
+        if (ConstString demangled = mangled.GetDemangledName()) {
+          if (ConstString best_alternate_mangled_name =
+                  FindBestAlternateMangledName(demangled, sc))
+            CPP_names.push_back(best_alternate_mangled_name);
         }
       }
-    }
 
-    if (auto *cpp_lang = Language::FindPlugin(lldb::eLanguageTypeC_plus_plus)) {
       std::vector<ConstString> alternates =
           cpp_lang->GenerateAlternateFunctionManglings(name);
       CPP_names.insert(CPP_names.end(), alternates.begin(), alternates.end());
-    }
-  }
-}
-
-void IRExecutionUnit::CollectFallbackNames(
-    std::vector<ConstString> &fallback_names,
-    const std::vector<ConstString> &C_names) {
-  // 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.
 
-  for (const ConstString &name : C_names) {
-    if (!CPlusPlusLanguage::IsCPPMangledName(name.GetCString()))
-      continue;
-
-    Mangled mangled_name(name);
-    ConstString demangled_name = mangled_name.GetDemangledName();
-    if (demangled_name.IsEmpty())
-      continue;
-
-    const char *demangled_cstr = demangled_name.AsCString();
-    const char *lparen_loc = strchr(demangled_cstr, '(');
-    if (!lparen_loc)
-      continue;
-
-    llvm::StringRef base_name(demangled_cstr, lparen_loc - demangled_cstr);
-    fallback_names.push_back(ConstString(base_name));
+      // 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);
+    }
   }
 }
 
@@ -950,14 +926,6 @@ lldb::addr_t IRExecutionUnit::FindSymbol(lldb_private::ConstString name,
   CollectCandidateCPlusPlusNames(candidate_CPlusPlus_names, candidate_C_names,
                                  m_sym_ctx);
   ret = FindInSymbols(candidate_CPlusPlus_names, m_sym_ctx, missing_weak);
-  if (ret != LLDB_INVALID_ADDRESS)
-    return ret;
-
-  std::vector<ConstString> candidate_fallback_names;
-
-  CollectFallbackNames(candidate_fallback_names, candidate_C_names);
-  ret = FindInSymbols(candidate_fallback_names, m_sym_ctx, missing_weak);
-
   return ret;
 }
 


        


More information about the lldb-commits mailing list