[Lldb-commits] [PATCH] D83858: [lldb] Desugar template specializations
Jaroslav Sevcik via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 15 00:48:43 PDT 2020
jarin created this revision.
jarin added a reviewer: teemperor.
jarin added a project: LLDB.
Herald added a subscriber: lldb-commits.
Template specializations are not handled in many of the
TypeSystemClang methods. For example, GetNumChildren does not handle
the TemplateSpecialization type class, so template specializations
always look like empty objects.
This patch just desugars template specialization in the existing
RemoveWrappingTypes desugaring helper.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D83858
Files:
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/test/API/lang/cpp/template-specialization/Makefile
lldb/test/API/lang/cpp/template-specialization/TestTemplateSpecialization.py
lldb/test/API/lang/cpp/template-specialization/main.cpp
Index: lldb/test/API/lang/cpp/template-specialization/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization/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/TestTemplateSpecialization.py
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization/TestTemplateSpecialization.py
@@ -0,0 +1,28 @@
+"""
+Test evaluating an expression with a cast to a pointer to a template
+specialization.
+"""
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TemplateSpecializationTestCase(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())
+
+ 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/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/template-specialization/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
@@ -2504,6 +2504,7 @@
case clang::Type::Typedef:
case clang::Type::TypeOf:
case clang::Type::TypeOfExpr:
+ case clang::Type::TemplateSpecialization:
type = type->getLocallyUnqualifiedSingleStepDesugaredType();
break;
default:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83858.278097.patch
Type: text/x-patch
Size: 2434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200715/7c389ccb/attachment.bin>
More information about the lldb-commits
mailing list