Skip to content

Commit 950f1bf

Browse files
committed
[lldb] Add SubstTemplateTypeParm to RemoveWrappingTypes
Like the other type sugar removed by RemoveWrappingTypes, SubstTemplateTypeParm is just pure sugar that should be ignored. If we don't ignore it (as we do now), LLDB will fail to read values from record fields that have a SubstTemplateTypeParm type. Only way to produce such a type in LLDB is to either use the `import-std-module` setting to get a template into the expression parser or just create your own template directly in the expression parser which is what we do in the test. Reviewed By: jarin Differential Revision: https://reviews.llvm.org/D85132
1 parent 4f3559d commit 950f1bf

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,7 @@ RemoveWrappingTypes(QualType type, ArrayRef<clang::Type::TypeClass> mask = {}) {
24992499
case clang::Type::Decltype:
25002500
case clang::Type::Elaborated:
25012501
case clang::Type::Paren:
2502+
case clang::Type::SubstTemplateTypeParm:
25022503
case clang::Type::TemplateSpecialization:
25032504
case clang::Type::Typedef:
25042505
case clang::Type::TypeOf:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Test SubstTemplateTypeParam types which are produced as type sugar
3+
when template type parameters are used for example as field types.
4+
"""
5+
6+
import lldb
7+
import lldbsuite.test.lldbutil as lldbutil
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import decorators
10+
11+
class TestCase(TestBase):
12+
13+
mydir = TestBase.compute_mydir(__file__)
14+
15+
def test_typedef(self):
16+
target = self.dbg.GetDummyTarget()
17+
18+
# Declare a template class with a field that uses the template type
19+
# parameter.
20+
opts = lldb.SBExpressionOptions()
21+
opts.SetTopLevel(True)
22+
result = target.EvaluateExpression("template <typename T> struct X { T f; };", opts)
23+
# FIXME: This fails with "Couldn't find $__lldb_expr() in the module"
24+
# but it should succeed. The fact that this code has nothing to run
25+
# shouldn't be an error.
26+
# self.assertSuccess(result.GetError())
27+
28+
# Instantiate and produce a value with that template as the type.
29+
# The field in the value will have a SubstTemplateTypeParam that
30+
# should behave like a normal field.
31+
result = target.EvaluateExpression("X<int> x; x.f = 123; x")
32+
self.assertEqual(result.GetNumChildren(), 1)
33+
self.assertEqual(result.GetChildAtIndex(0).GetTypeName(), "int")
34+
self.assertEqual(result.GetChildAtIndex(0).GetValue(), "123")

0 commit comments

Comments
 (0)