friss created this revision.
friss added a reviewer: clayborg.
Herald added subscribers: JDevlieghere, aprantl.

The modified test would just crash without the code change. The reason is that
we would try to extend the Foo type imported from the PCH debug info when 
adding the
Foo::Bar definitiion to it. This will crash if the type is not complete.

I pondered moving the CompleteType call inside of CopyType, but CopytType seems
to be used as a lower-level building block in other places so I decided not to.

ClangASTImporter is kinda scary. It has no comments and interacts with the Clang
ASTs which are not exactly easy to deal with. Any insight appreciated.


https://reviews.llvm.org/D43592

Files:
  packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py
  packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp
  packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp


Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -179,10 +179,9 @@
   lldb_private::CompilerType type =
       GetClangASTImporter().CopyType(m_ast, dwo_type);
 
-  // printf ("copied_qual_type: ast = %p, clang_type = %p, name =
-  // '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(),
-  // external_type->GetName().GetCString());
-  if (!type)
+  // The type we retrieve from the PCM debug info needs to be
+  // complete, otherwise we might crash when trying to extend it.
+  if (!type || !GetClangASTImporter().CompleteType(type))
     return TypeSP();
 
   SymbolFileDWARF *dwarf = die.GetDWARF();
Index: packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h
+++ packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h
@@ -10,3 +10,8 @@
 };
 
 typedef GenericContainer<int> IntContainer;
+
+struct Foo {
+  class Bar;
+  Bar *bar;
+};
Index: packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp
+++ packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp
@@ -1,5 +1,8 @@
+class Foo::Bar { int i = 123; };
+
 int main(int argc, const char * argv[])
 {
     IntContainer test(42);
+    Foo::Bar bar;
     return 0; // break here
 }
Index: 
packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py
+++ packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py
@@ -69,3 +69,26 @@
             42,
             memberValue.GetValueAsSigned(),
             "Member value incorrect")
+
+        testValue = frame.EvaluateExpression("bar")
+        self.assertTrue(
+            testValue.GetError().Success(),
+            "Test expression value invalid: %s" %
+            (testValue.GetError().GetCString()))
+        self.assertTrue(
+            testValue.GetTypeName() == "Foo::Bar",
+            "Test expression type incorrect")
+
+        memberValue = testValue.GetChildMemberWithName("i")
+        self.assertTrue(
+            memberValue.GetError().Success(),
+            "Member value missing or invalid: %s" %
+            (testValue.GetError().GetCString()))
+        self.assertTrue(
+            memberValue.GetTypeName() == "int",
+            "Member type incorrect")
+        self.assertEqual(
+            123,
+            memberValue.GetValueAsSigned(),
+            "Member value incorrect")
+


Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -179,10 +179,9 @@
   lldb_private::CompilerType type =
       GetClangASTImporter().CopyType(m_ast, dwo_type);
 
-  // printf ("copied_qual_type: ast = %p, clang_type = %p, name =
-  // '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(),
-  // external_type->GetName().GetCString());
-  if (!type)
+  // The type we retrieve from the PCM debug info needs to be
+  // complete, otherwise we might crash when trying to extend it.
+  if (!type || !GetClangASTImporter().CompleteType(type))
     return TypeSP();
 
   SymbolFileDWARF *dwarf = die.GetDWARF();
Index: packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h
+++ packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h
@@ -10,3 +10,8 @@
 };
 
 typedef GenericContainer<int> IntContainer;
+
+struct Foo {
+  class Bar;
+  Bar *bar;
+};
Index: packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp
+++ packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp
@@ -1,5 +1,8 @@
+class Foo::Bar { int i = 123; };
+
 int main(int argc, const char * argv[])
 {
     IntContainer test(42);
+    Foo::Bar bar;
     return 0; // break here
 }
Index: packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py
+++ packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py
@@ -69,3 +69,26 @@
             42,
             memberValue.GetValueAsSigned(),
             "Member value incorrect")
+
+        testValue = frame.EvaluateExpression("bar")
+        self.assertTrue(
+            testValue.GetError().Success(),
+            "Test expression value invalid: %s" %
+            (testValue.GetError().GetCString()))
+        self.assertTrue(
+            testValue.GetTypeName() == "Foo::Bar",
+            "Test expression type incorrect")
+
+        memberValue = testValue.GetChildMemberWithName("i")
+        self.assertTrue(
+            memberValue.GetError().Success(),
+            "Member value missing or invalid: %s" %
+            (testValue.GetError().GetCString()))
+        self.assertTrue(
+            memberValue.GetTypeName() == "int",
+            "Member type incorrect")
+        self.assertEqual(
+            123,
+            memberValue.GetValueAsSigned(),
+            "Member value incorrect")
+
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to