1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
| """
Test that C++ template classes that have integer parameters work correctly.
We must reconstruct the types correctly so the template types are correct
and display correctly, and also make sure the expression parser works and
is able the find all needed functions when evaluating expressions
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TemplateArgsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def prepareProcess(self):
self.build()
# Create a target by the debugger.
exe = self.getBuildArtifact("a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Set breakpoints inside and outside methods that take pointers to the
# containing struct.
line = line_number('main.cpp', '// Breakpoint 1')
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", line, num_expected_locations=1, loc_exact=True)
arguments = None
environment = None
# Now launch the process, and do not stop at entry point.
process = target.LaunchSimple(
arguments, environment, self.get_process_working_directory())
self.assertTrue(process, PROCESS_IS_VALID)
# Get the thread of the process
self.assertTrue(
process.GetState() == lldb.eStateStopped,
PROCESS_STOPPED)
thread = lldbutil.get_stopped_thread(
process, lldb.eStopReasonBreakpoint)
# Get frame for current thread
return thread.GetSelectedFrame()
def test_integer_args(self):
frame = self.prepareProcess()
testpos = frame.FindVariable('testpos')
self.assertTrue(
testpos.IsValid(),
'make sure we find a local variabble named "testpos"')
self.assertTrue(testpos.GetType().GetName() == 'TestObj<1>')
expr_result = frame.EvaluateExpression("testpos.getArg()")
self.assertTrue(
expr_result.IsValid(),
'got a valid expression result from expression "testpos.getArg()"')
self.assertTrue(expr_result.GetValue() == "1", "testpos.getArg() == 1")
self.assertTrue(
expr_result.GetType().GetName() == "int",
'expr_result.GetType().GetName() == "int"')
testneg = frame.FindVariable('testneg')
self.assertTrue(
testneg.IsValid(),
'make sure we find a local variabble named "testneg"')
self.assertTrue(testneg.GetType().GetName() == 'TestObj<-1>')
expr_result = frame.EvaluateExpression("testneg.getArg()")
self.assertTrue(
expr_result.IsValid(),
'got a valid expression result from expression "testneg.getArg()"')
self.assertTrue(
expr_result.GetValue() == "-1",
"testneg.getArg() == -1")
self.assertTrue(
expr_result.GetType().GetName() == "int",
'expr_result.GetType().GetName() == "int"')
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489")
def test_template_template_args(self):
frame = self.prepareProcess()
c1 = frame.FindVariable('c1')
self.assertTrue(
c1.IsValid(),
'make sure we find a local variabble named "c1"')
self.assertTrue(c1.GetType().GetName() == 'C<float, T1>')
f1 = c1.GetChildMemberWithName("V").GetChildAtIndex(0).GetChildMemberWithName("f")
self.assertTrue(f1.GetType().GetName() == 'float')
self.assertTrue(f1.GetValue() == '1.5')
c2 = frame.FindVariable('c2')
self.assertTrue(
c2.IsValid(),
'make sure we find a local variabble named "c2"')
self.assertTrue(c2.GetType().GetName() == 'C<double, T1, T2>')
f2 = c2.GetChildMemberWithName("V").GetChildAtIndex(0).GetChildMemberWithName("f")
self.assertTrue(f2.GetType().GetName() == 'double')
self.assertTrue(f2.GetValue() == '1.5')
f3 = c2.GetChildMemberWithName("V").GetChildAtIndex(1).GetChildMemberWithName("f")
self.assertTrue(f3.GetType().GetName() == 'double')
self.assertTrue(f3.GetValue() == '2.5')
f4 = c2.GetChildMemberWithName("V").GetChildAtIndex(1).GetChildMemberWithName("i")
self.assertTrue(f4.GetType().GetName() == 'int')
self.assertTrue(f4.GetValue() == '42')
# Gcc does not generate the necessary DWARF attribute for enum template
# parameters.
@expectedFailureAll(bugnumber="llvm.org/pr28354", compiler="gcc")
@skipIf(dwarf_version=['<', '4'])
def test_enum_args(self):
frame = self.prepareProcess()
# Make sure "member" can be displayed and also used in an expression
# correctly
member = frame.FindVariable('member')
self.assertTrue(
member.IsValid(),
'make sure we find a local variabble named "member"')
self.assertTrue(member.GetType().GetName() ==
'EnumTemplate<EnumType::Member>')
expr_result = frame.EvaluateExpression("member.getMember()")
self.assertTrue(
expr_result.IsValid(),
'got a valid expression result from expression "member.getMember()"')
self.assertTrue(
expr_result.GetValue() == "123",
"member.getMember() == 123")
self.assertTrue(
expr_result.GetType().GetName() == "int",
'expr_result.GetType().GetName() == "int"')
# Make sure "subclass" can be displayed and also used in an expression
# correctly
subclass = frame.FindVariable('subclass')
self.assertTrue(
subclass.IsValid(),
'make sure we find a local variabble named "subclass"')
self.assertTrue(subclass.GetType().GetName() ==
'EnumTemplate<EnumType::Subclass>')
expr_result = frame.EvaluateExpression("subclass.getMember()")
self.assertTrue(
expr_result.IsValid(),
'got a valid expression result from expression "subclass.getMember()"')
self.assertTrue(
expr_result.GetValue() == "246",
"subclass.getMember() == 246")
self.assertTrue(
expr_result.GetType().GetName() == "int",
'expr_result.GetType().GetName() == "int"')
|