lassefolger updated this revision to Diff 401947.
lassefolger added a comment.

rebase patch


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114627/new/

https://reviews.llvm.org/D114627

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===================================================================
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -133,6 +133,19 @@
     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
     TypeMap &types) {}
 
+void SymbolFile::FindTypes(
+    ConstString basename, ConstString scope,
+    const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+    llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+    TypeMap &types) {
+  FindTypes(basename, parent_decl_ctx, max_matches, searched_symbol_files,
+            types);
+  TypeClass type_class = eTypeClassAny;
+  types.RemoveMismatchedTypes(std::string(basename.GetCString()),
+                              std::string(scope.GetCString()), type_class,
+                              scope.GetStringRef().startswith("::"));
+}
+
 void SymbolFile::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
                            LanguageSet languages,
                            llvm::DenseSet<SymbolFile *> &searched_symbol_files,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -191,6 +191,13 @@
       const std::string &scope_qualified_name,
       std::vector<lldb_private::ConstString> &mangled_names) override;
 
+  void
+  FindTypes(lldb_private::ConstString name, lldb_private::ConstString scope,
+            const lldb_private::CompilerDeclContext &parent_decl_ctx,
+            uint32_t max_matches,
+            llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+            lldb_private::TypeMap &types) override;
+
   void
   FindTypes(lldb_private::ConstString name,
             const lldb_private::CompilerDeclContext &parent_decl_ctx,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -9,6 +9,7 @@
 #include "SymbolFileDWARF.h"
 
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Threading.h"
 
@@ -21,6 +22,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/StreamString.h"
@@ -2409,6 +2411,15 @@
     uint32_t max_matches,
     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
     TypeMap &types) {
+  FindTypes(name, ConstString(), parent_decl_ctx, max_matches,
+            searched_symbol_files, types);
+}
+
+void SymbolFileDWARF::FindTypes(
+    ConstString name, ConstString scope,
+    const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+    llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+    TypeMap &types) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   // Make sure we haven't already searched this SymbolFile before.
   if (!searched_symbol_files.insert(this).second)
@@ -2435,10 +2446,25 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
     return;
 
+  // prepare string to check against in case this is a fully qualified search
+  bool has_scope = !scope.IsEmpty();
+  llvm::StringRef scope_ref(scope.GetStringRef());
+  if (scope_ref.size() != 2) {
+    // DWARFDIE prefixes only variables in global scope with '::'
+    scope_ref.consume_front("::");
+  }
+  std::string storage;
+
   m_index->GetTypes(name, [&](DWARFDIE die) {
     if (!DIEInDeclContext(parent_decl_ctx, die))
       return true; // The containing decl contexts don't match
 
+    if (has_scope) {
+      die.GetQualifiedName(storage);
+      if (!storage.empty() && !llvm::StringRef(storage).startswith(scope_ref))
+        return true;
+    }
+
     Type *matching_type = ResolveType(die, true, true);
     if (!matching_type)
       return true;
Index: lldb/source/Core/Module.cpp
===================================================================
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -947,6 +947,17 @@
                        searched_symbol_files, types);
 }
 
+void Module::FindTypes_Impl(
+    ConstString name, ConstString scope,
+    const CompilerDeclContext &parent_decl_ctx, size_t max_matches,
+    llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+    TypeMap &types) {
+  LLDB_SCOPED_TIMER();
+  if (SymbolFile *symbols = GetSymbolFile())
+    symbols->FindTypes(name, scope, parent_decl_ctx, max_matches,
+                       searched_symbol_files, types);
+}
+
 void Module::FindTypesInNamespace(ConstString type_name,
                                   const CompilerDeclContext &parent_decl_ctx,
                                   size_t max_matches, TypeList &type_list) {
@@ -983,15 +994,18 @@
 
   if (Type::GetTypeScopeAndBasename(type_name_cstr, type_scope, type_basename,
                                     type_class)) {
+
+    ConstString type_basename_const_str(type_basename);
+    ConstString type_scope_const_str(type_scope);
+    FindTypes_Impl(type_basename_const_str, type_scope_const_str,
+                   CompilerDeclContext(), max_matches, searched_symbol_files,
+                   typesmap);
+
     // Check if "name" starts with "::" which means the qualified type starts
     // from the root namespace and implies and exact match. The typenames we
     // get back from clang do not start with "::" so we need to strip this off
     // in order to get the qualified names to match
     exact_match = type_scope.consume_front("::");
-
-    ConstString type_basename_const_str(type_basename);
-    FindTypes_Impl(type_basename_const_str, CompilerDeclContext(), max_matches,
-                   searched_symbol_files, typesmap);
     if (typesmap.GetSize())
       typesmap.RemoveMismatchedTypes(std::string(type_scope),
                                      std::string(type_basename), type_class,
Index: lldb/include/lldb/Symbol/SymbolFile.h
===================================================================
--- lldb/include/lldb/Symbol/SymbolFile.h
+++ lldb/include/lldb/Symbol/SymbolFile.h
@@ -234,6 +234,15 @@
             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
             TypeMap &types);
 
+  // Find types in a specific scope.
+  // \param scope
+  //     Must be either the scope prefix (with leading ::) or empty
+  virtual void
+  FindTypes(ConstString name, ConstString scope,
+            const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+            llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+            TypeMap &types);
+
   /// Find types specified by a CompilerContextPattern.
   /// \param languages
   ///     Only return results in these languages.
Index: lldb/include/lldb/Core/Module.h
===================================================================
--- lldb/include/lldb/Core/Module.h
+++ lldb/include/lldb/Core/Module.h
@@ -1113,6 +1113,12 @@
       llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
       TypeMap &types);
 
+  void FindTypes_Impl(
+      ConstString name, ConstString scope,
+      const CompilerDeclContext &parent_decl_ctx, size_t max_matches,
+      llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+      TypeMap &types);
+
   Module(const Module &) = delete;
   const Module &operator=(const Module &) = delete;
 };
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to