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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
"""
Test lldb data formatter subsystem.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
class DataFormatterTestCase(TestBase):
mydir = os.path.join("functionalities", "data-formatter", "data-formatter-objc")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
def test_with_dsym_and_run_command(self):
"""Test data formatter commands."""
self.buildDsym()
self.data_formatter_commands()
def test_with_dwarf_and_run_command(self):
"""Test data formatter commands."""
self.buildDwarf()
self.data_formatter_commands()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break at.
self.line = line_number('main.m', '// Set break point at this line.')
def data_formatter_commands(self):
"""Test that that file and class static variables display correctly."""
self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
self.expect("breakpoint set -f main.m -l %d" % self.line,
BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.m', line = %d, locations = 1" %
self.line)
self.runCmd("run", RUN_SUCCEEDED)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
'stop reason = breakpoint'])
# This is the function to remove the custom formats in order to have a
# clean slate for the next test case.
def cleanup():
self.runCmd('type format clear', check=False)
self.runCmd('type summary clear', check=False)
self.runCmd('type synth clear', check=False)
# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)
self.runCmd("type summary add -f \"${var%@}\" MyClass")
self.expect("frame variable object2",
substrs = ['MyOtherClass']);
self.expect("frame variable *object2",
substrs = ['MyOtherClass']);
# Now let's delete the 'MyClass' custom summary.
self.runCmd("type summary delete MyClass")
# The type format list should not show 'MyClass' at this point.
self.expect("type summary list", matching=False,
substrs = ['MyClass'])
self.runCmd("type summary add -f \"a test\" MyClass")
self.expect("frame variable object2",
substrs = ['a test']);
self.expect("frame variable *object2",
substrs = ['a test']);
self.expect("frame variable object",
substrs = ['a test']);
self.expect("frame variable *object",
substrs = ['a test']);
self.runCmd("type summary add -f \"a test\" MyClass -C no")
self.expect("frame variable *object2",
substrs = ['*object2 = {',
'MyClass = a test',
'backup = ']);
self.expect("frame variable object2", matching=False,
substrs = ['a test']);
self.expect("frame variable object",
substrs = ['a test']);
self.expect("frame variable *object",
substrs = ['a test']);
# Now check that the synth for CFString works
self.runCmd("script from CFString import *")
self.runCmd("type synth add -l CFStringSynthProvider NSString")
self.expect('frame variable str -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'A rather short ASCII NSString object is here'])
self.expect('frame variable str2 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'A rather short UTF8 NSString object is here'])
self.expect('frame variable str3 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'A string made with the at sign is here'])
self.expect('frame variable str4 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'This is string number 4 right here'])
self.expect('frame variable str5 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'{{1, 1}, {5, 5}}'])
self.expect('frame variable str6 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'1ST'])
self.expect('frame variable str7 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'\\xcf\\x83xx'])
self.expect('frame variable str8 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'hasVeryLongExtensionThisTime'])
self.expect('frame variable str9 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'a very much boring task to write a string this way!!\\xe4\\x8c\\xb3'])
self.expect('frame variable str10 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'This is a Unicode string \\xcf\\x83 number 4 right here'])
self.expect('frame variable str11 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'__NSCFString'])
self.expect('frame variable processName -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'a.out'])
self.expect('frame variable str12 -P 1 -Y',
substrs = ['mutable =',
'inline = ',
'explicit = ',
'content = ',
'Process Name: a.out Process Id:'])
# delete the synth and set a summary
self.runCmd("type synth delete NSString")
self.runCmd("type summary add -F CFString_SummaryProvider NSString")
self.expect('frame variable str',
substrs = ['A rather short ASCII NSString object is here'])
self.expect('frame variable str2',
substrs = ['A rather short UTF8 NSString object is here'])
self.expect('frame variable str3',
substrs = ['A string made with the at sign is here'])
self.expect('frame variable str4',
substrs = ['This is string number 4 right here'])
self.expect('frame variable str5',
substrs = ['{{1, 1}, {5, 5}}'])
self.expect('frame variable str6',
substrs = ['1ST'])
self.expect('frame variable str7',
substrs = ['\\xcf\\x83xx'])
self.expect('frame variable str8',
substrs = ['hasVeryLongExtensionThisTime'])
self.expect('frame variable str9',
substrs = ['a very much boring task to write a string this way!!\\xe4\\x8c\\xb3'])
self.expect('frame variable str10',
substrs = ['This is a Unicode string \\xcf\\x83 number 4 right here'])
self.expect('frame variable str11',
substrs = ['__NSCFString'])
self.expect('frame variable processName',
substrs = ['a.out'])
self.expect('frame variable str12',
substrs = ['Process Name: a.out Process Id:'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()
|