jarin updated this revision to Diff 278173.
jarin marked 3 inline comments as done.
jarin added a comment.

Addressed review comments.


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

https://reviews.llvm.org/D83858

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/test/API/lang/cpp/template-specialization-type/Makefile
  
lldb/test/API/lang/cpp/template-specialization-type/TestTemplateSpecializationType.py
  lldb/test/API/lang/cpp/template-specialization-type/main.cpp


Index: lldb/test/API/lang/cpp/template-specialization-type/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization-type/main.cpp
@@ -0,0 +1,9 @@
+template <typename T> struct TestObj {
+  int f;
+  T g;
+};
+
+int main() {
+  TestObj<int> t{42, 21};
+  return t.f + t.g; // break here
+}
Index: 
lldb/test/API/lang/cpp/template-specialization-type/TestTemplateSpecializationType.py
===================================================================
--- /dev/null
+++ 
lldb/test/API/lang/cpp/template-specialization-type/TestTemplateSpecializationType.py
@@ -0,0 +1,30 @@
+"""
+Test value with a template specialization type.
+"""
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TemplateSpecializationTypeTestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_template_specialization_cast_children(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, '// break here',
+                lldb.SBFileSpec("main.cpp", False))
+
+        v = self.frame().EvaluateExpression("t")
+        self.assertEquals(2, v.GetNumChildren())
+        self.assertEquals("42", v.GetChildAtIndex(0).GetValue())
+        self.assertEquals("21", v.GetChildAtIndex(1).GetValue())
+
+        # Test a value of the TemplateSpecialization type. We turn
+        # RecordType into TemplateSpecializationType by casting and
+        # dereferencing a pointer to a record.
+        v = self.frame().EvaluateExpression("*((TestObj<int>*)&t)")
+        self.assertEquals(2, v.GetNumChildren())
+        self.assertEquals("42", v.GetChildAtIndex(0).GetValue())
+        self.assertEquals("21", v.GetChildAtIndex(1).GetValue())
Index: lldb/test/API/lang/cpp/template-specialization-type/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization-type/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2506,6 +2506,13 @@
     case clang::Type::TypeOfExpr:
       type = type->getLocallyUnqualifiedSingleStepDesugaredType();
       break;
+    case clang::Type::TemplateSpecialization: {
+      auto ty = cast<clang::TemplateSpecializationType>(type);
+      if (!ty->isSugared())
+        return type;
+      type = ty->desugar();
+      break;
+    }
     default:
       return type;
     }


Index: lldb/test/API/lang/cpp/template-specialization-type/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization-type/main.cpp
@@ -0,0 +1,9 @@
+template <typename T> struct TestObj {
+  int f;
+  T g;
+};
+
+int main() {
+  TestObj<int> t{42, 21};
+  return t.f + t.g; // break here
+}
Index: lldb/test/API/lang/cpp/template-specialization-type/TestTemplateSpecializationType.py
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization-type/TestTemplateSpecializationType.py
@@ -0,0 +1,30 @@
+"""
+Test value with a template specialization type.
+"""
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TemplateSpecializationTypeTestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_template_specialization_cast_children(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, '// break here',
+                lldb.SBFileSpec("main.cpp", False))
+
+        v = self.frame().EvaluateExpression("t")
+        self.assertEquals(2, v.GetNumChildren())
+        self.assertEquals("42", v.GetChildAtIndex(0).GetValue())
+        self.assertEquals("21", v.GetChildAtIndex(1).GetValue())
+
+        # Test a value of the TemplateSpecialization type. We turn
+        # RecordType into TemplateSpecializationType by casting and
+        # dereferencing a pointer to a record.
+        v = self.frame().EvaluateExpression("*((TestObj<int>*)&t)")
+        self.assertEquals(2, v.GetNumChildren())
+        self.assertEquals("42", v.GetChildAtIndex(0).GetValue())
+        self.assertEquals("21", v.GetChildAtIndex(1).GetValue())
Index: lldb/test/API/lang/cpp/template-specialization-type/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization-type/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2506,6 +2506,13 @@
     case clang::Type::TypeOfExpr:
       type = type->getLocallyUnqualifiedSingleStepDesugaredType();
       break;
+    case clang::Type::TemplateSpecialization: {
+      auto ty = cast<clang::TemplateSpecializationType>(type);
+      if (!ty->isSugared())
+        return type;
+      type = ty->desugar();
+      break;
+    }
     default:
       return type;
     }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to