[Lldb-commits] [PATCH] D85904: [lldb] Check Decl kind when completing -flimit-debug-info types

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 13 06:12:00 PDT 2020


labath created this revision.
labath added a reviewer: teemperor.
Herald added a reviewer: shafik.
Herald added a project: LLDB.
labath requested review of this revision.
Herald added a subscriber: JDevlieghere.

The search for the complete class definition can also produce entries
which are not of the expected type. This can happen for instance when
there is a function with the same name as the class we're looking up
(which means that the class needs to be disambiguated with the
struct/class tag in most contexts).

Previously we were just picking the first Decl that the lookup returned,
which later caused crashes or assertion failures if it was not of the
correct type. This patch changes that to search for an entry of the
correct type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85904

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
  lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
  lldb/test/API/functionalities/limit-debug-info/main.cpp
  lldb/test/API/functionalities/limit-debug-info/one.cpp
  lldb/test/API/functionalities/limit-debug-info/onetwo.h


Index: lldb/test/API/functionalities/limit-debug-info/onetwo.h
===================================================================
--- lldb/test/API/functionalities/limit-debug-info/onetwo.h
+++ lldb/test/API/functionalities/limit-debug-info/onetwo.h
@@ -54,3 +54,13 @@
   virtual ~Two();
 };
 } // namespace result
+
+namespace func_shadow {
+void One(int);
+struct One {
+  int one = 142;
+  constexpr One() = default;
+  virtual ~One();
+};
+void One(float);
+} // namespace func_shadow
Index: lldb/test/API/functionalities/limit-debug-info/one.cpp
===================================================================
--- lldb/test/API/functionalities/limit-debug-info/one.cpp
+++ lldb/test/API/functionalities/limit-debug-info/one.cpp
@@ -6,3 +6,7 @@
 
 result::One::One(int member) : member(member) {}
 result::One::~One() = default;
+
+void func_shadow::One(int) {}
+func_shadow::One::~One() = default;
+void func_shadow::One(float) {}
Index: lldb/test/API/functionalities/limit-debug-info/main.cpp
===================================================================
--- lldb/test/API/functionalities/limit-debug-info/main.cpp
+++ lldb/test/API/functionalities/limit-debug-info/main.cpp
@@ -28,4 +28,9 @@
 result::One get_one() { return result::One(124); }
 result::Two get_two() { return result::Two(224); }
 
+struct ShadowedOne : public func_shadow::One {
+  constexpr ShadowedOne() = default;
+  int member = 47;
+} shadowed_one;
+
 int main() { return get_one().member; }
Index: lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
===================================================================
--- lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
+++ lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
@@ -63,6 +63,9 @@
         self.expect_expr("get_two().one().member", result_value="124")
         self.expect_expr("get_two().member", result_value="224")
 
+        self.expect_expr("shadowed_one.member", result_value="47")
+        self.expect_expr("shadowed_one.one", result_value="142")
+
     @skipIf(bugnumber="pr46284", debug_info="gmodules")
     @skipIfWindows # Clang emits type info even with -flimit-debug-info
     def test_two_debug(self):
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -870,13 +870,14 @@
       return dn_or_err.takeError();
     DeclContext *dc = *dc_or_err;
     DeclContext::lookup_result lr = dc->lookup(*dn_or_err);
-    if (lr.size()) {
-      clang::Decl *lookup_found = lr.front();
-      RegisterImportedDecl(From, lookup_found);
-      m_decls_to_ignore.insert(lookup_found);
-      return lookup_found;
-    } else
-      LLDB_LOG(log, "[ClangASTImporter] Complete definition not found");
+    for (clang::Decl *candidate : lr) {
+      if (candidate->getKind() == From->getKind()) {
+        RegisterImportedDecl(From, candidate);
+        m_decls_to_ignore.insert(candidate);
+        return candidate;
+      }
+    }
+    LLDB_LOG(log, "[ClangASTImporter] Complete definition not found");
   }
 
   return ASTImporter::ImportImpl(From);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85904.285352.patch
Type: text/x-patch
Size: 3288 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200813/aa8add6d/attachment-0001.bin>


More information about the lldb-commits mailing list