2 Test that C++ template classes that have integer parameters work correctly.
4 We must reconstruct the types correctly so the template types are correct
5 and display correctly, and also make sure the expression parser works and
6 is able the find all needed functions when evaluating expressions
9 from lldbsuite
.test
.decorators
import *
10 from lldbsuite
.test
.lldbtest
import *
11 from lldbsuite
.test
import lldbutil
14 class TemplateArgsTestCase(TestBase
):
15 def prepareProcess(self
):
18 # Create a target by the debugger.
19 exe
= self
.getBuildArtifact("a.out")
20 target
= self
.dbg
.CreateTarget(exe
)
21 self
.assertTrue(target
, VALID_TARGET
)
23 # Set breakpoints inside and outside methods that take pointers to the
25 line
= line_number("main.cpp", "// Breakpoint 1")
26 lldbutil
.run_break_set_by_file_and_line(
27 self
, "main.cpp", line
, num_expected_locations
=1, loc_exact
=True
33 # Now launch the process, and do not stop at entry point.
34 process
= target
.LaunchSimple(
35 arguments
, environment
, self
.get_process_working_directory()
37 self
.assertTrue(process
, PROCESS_IS_VALID
)
39 # Get the thread of the process
40 self
.assertEqual(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
41 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
43 # Get frame for current thread
44 return thread
.GetSelectedFrame()
46 def test_integer_args(self
):
47 frame
= self
.prepareProcess()
49 testpos
= frame
.FindVariable("testpos")
51 testpos
.IsValid(), 'make sure we find a local variabble named "testpos"'
53 self
.assertEqual(testpos
.GetType().GetName(), "TestObj<1>")
55 expr_result
= frame
.EvaluateExpression("testpos.getArg()")
57 expr_result
.IsValid(),
58 'got a valid expression result from expression "testpos.getArg()"',
60 self
.assertEqual(expr_result
.GetValue(), "1", "testpos.getArg() == 1")
62 expr_result
.GetType().GetName(),
64 'expr_result.GetType().GetName() == "int"',
67 testneg
= frame
.FindVariable("testneg")
69 testneg
.IsValid(), 'make sure we find a local variabble named "testneg"'
71 self
.assertEqual(testneg
.GetType().GetName(), "TestObj<-1>")
73 expr_result
= frame
.EvaluateExpression("testneg.getArg()")
75 expr_result
.IsValid(),
76 'got a valid expression result from expression "testneg.getArg()"',
78 self
.assertEqual(expr_result
.GetValue(), "-1", "testneg.getArg() == -1")
80 expr_result
.GetType().GetName(),
82 'expr_result.GetType().GetName() == "int"',
85 @expectedFailureAll(oslist
=["windows"], bugnumber
="llvm.org/pr24489")
86 def test_template_template_args(self
):
87 frame
= self
.prepareProcess()
89 c1
= frame
.FindVariable("c1")
90 self
.assertTrue(c1
.IsValid(), 'make sure we find a local variabble named "c1"')
91 self
.assertEqual(c1
.GetType().GetName(), "C<float, T1>")
93 c1
.GetChildMemberWithName("V")
95 .GetChildMemberWithName("f")
97 self
.assertEqual(f1
.GetType().GetName(), "float")
98 self
.assertEqual(f1
.GetValue(), "1.5")
100 c2
= frame
.FindVariable("c2")
101 self
.assertTrue(c2
.IsValid(), 'make sure we find a local variabble named "c2"')
102 self
.assertEqual(c2
.GetType().GetName(), "C<double, T1, T2>")
104 c2
.GetChildMemberWithName("V")
106 .GetChildMemberWithName("f")
108 self
.assertEqual(f2
.GetType().GetName(), "double")
109 self
.assertEqual(f2
.GetValue(), "1.5")
111 c2
.GetChildMemberWithName("V")
113 .GetChildMemberWithName("f")
115 self
.assertEqual(f3
.GetType().GetName(), "double")
116 self
.assertEqual(f3
.GetValue(), "2.5")
118 c2
.GetChildMemberWithName("V")
120 .GetChildMemberWithName("i")
122 self
.assertEqual(f4
.GetType().GetName(), "int")
123 self
.assertEqual(f4
.GetValue(), "42")
125 # Gcc does not generate the necessary DWARF attribute for enum template
127 @expectedFailureAll(bugnumber
="llvm.org/pr28354", compiler
="gcc")
128 @skipIf(dwarf_version
=["<", "4"])
129 def test_enum_args(self
):
130 frame
= self
.prepareProcess()
132 # Make sure "member" can be displayed and also used in an expression
134 member
= frame
.FindVariable("member")
136 member
.IsValid(), 'make sure we find a local variabble named "member"'
138 self
.assertEqual(member
.GetType().GetName(), "EnumTemplate<EnumType::Member>")
140 expr_result
= frame
.EvaluateExpression("member.getMember()")
142 expr_result
.IsValid(),
143 'got a valid expression result from expression "member.getMember()"',
145 self
.assertEqual(expr_result
.GetValue(), "123", "member.getMember() == 123")
147 expr_result
.GetType().GetName(),
149 'expr_result.GetType().GetName() == "int"',
152 # Make sure "subclass" can be displayed and also used in an expression
154 subclass
= frame
.FindVariable("subclass")
156 subclass
.IsValid(), 'make sure we find a local variabble named "subclass"'
159 subclass
.GetType().GetName(), "EnumTemplate<EnumType::Subclass>"
162 expr_result
= frame
.EvaluateExpression("subclass.getMember()")
164 expr_result
.IsValid(),
165 'got a valid expression result from expression "subclass.getMember()"',
167 self
.assertEqual(expr_result
.GetValue(), "246", "subclass.getMember() == 246")
169 expr_result
.GetType().GetName(),
171 'expr_result.GetType().GetName() == "int"',