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
233
234
235
236
237
238
239
|
"""
Test more expression command sequences with objective-c.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
import lldbutil
@skipUnlessDarwin
class FoundationTestCase2(TestBase):
mydir = TestBase.compute_mydir(__file__)
@dsym_test
def test_more_expr_commands_with_dsym(self):
"""More expression commands for objective-c."""
self.buildDsym()
self.more_expr_objc()
@dwarf_test
def test_more_expr_commands_with_dwarf(self):
"""More expression commands for objective-c."""
self.buildDwarf()
self.more_expr_objc()
@dsym_test
def test_NSArray_expr_commands_with_dsym(self):
"""Test expression commands for NSArray."""
self.buildDsym()
self.NSArray_expr()
@dwarf_test
def test_NSArray_expr_commands_with_dwarf(self):
"""Test expression commands for NSArray."""
self.buildDwarf()
self.NSArray_expr()
@dsym_test
def test_NSString_expr_commands_with_dsym(self):
"""Test expression commands for NSString."""
self.buildDsym()
self.NSString_expr()
@dwarf_test
def test_NSString_expr_commands_with_dwarf(self):
"""Test expression commands for NSString."""
self.buildDwarf()
self.NSString_expr()
@dsym_test
def test_MyString_dump_with_dsym(self):
"""Test dump of a known Objective-C object by dereferencing it."""
self.buildDsym()
self.MyString_dump()
@dwarf_test
def test_MyString_dump_with_dwarf(self):
"""Test dump of a known Objective-C object by dereferencing it."""
self.buildDwarf()
self.MyString_dump()
@expectedFailurei386
@dsym_test
def test_NSError_po_with_dsym(self):
"""Test that po of the result of an unknown method doesn't require a cast."""
self.buildDsym()
self.NSError_po()
@expectedFailurei386
@dwarf_test
def test_NSError_po_with_dwarf(self):
"""Test that po of the result of an unknown method doesn't require a cast."""
self.buildDsym()
self.NSError_po()
@dsym_test
def test_NSError_p_with_dsym(self):
"""Test that p of the result of an unknown method does require a cast."""
self.buildDsym()
self.NSError_p()
@dwarf_test
def test_NSError_p_with_dwarf(self):
"""Test that p of the result of an unknown method does require a cast."""
self.buildDsym()
self.NSError_p()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line numbers to break at.
self.lines = []
self.lines.append(line_number('main.m', '// Break here for selector: tests'))
self.lines.append(line_number('main.m', '// Break here for NSArray tests'))
self.lines.append(line_number('main.m', '// Break here for NSString tests'))
self.lines.append(line_number('main.m', '// Break here for description test'))
self.lines.append(line_number('main.m', '// Set break point at this line'))
def more_expr_objc(self):
"""More expression commands for objective-c."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Create a bunch of breakpoints.
for line in self.lines:
lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_FAILED)
# Test_Selector:
self.runCmd("thread backtrace")
self.expect("expression (char *)sel_getName(sel)",
substrs = ["(char *)",
"length"])
self.runCmd("process continue")
# Test_NSArray:
self.runCmd("thread backtrace")
self.runCmd("process continue")
# Test_NSString:
self.runCmd("thread backtrace")
self.runCmd("process continue")
# Test_MyString:
self.runCmd("thread backtrace")
self.expect("expression (char *)sel_getName(_cmd)",
substrs = ["(char *)",
"description"])
self.runCmd("process continue")
def NSArray_expr(self):
"""Test expression commands for NSArray."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break inside Test_NSArray:
line = self.lines[1]
lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_FAILED)
# Test_NSArray:
self.runCmd("thread backtrace")
self.expect("expression (int)[nil_mutable_array count]",
patterns = ["\(int\) \$.* = 0"])
self.expect("expression (int)[array1 count]",
patterns = ["\(int\) \$.* = 3"])
self.expect("expression (int)[array2 count]",
patterns = ["\(int\) \$.* = 3"])
self.expect("expression (int)array1.count",
patterns = ["\(int\) \$.* = 3"])
self.expect("expression (int)array2.count",
patterns = ["\(int\) \$.* = 3"])
self.runCmd("process continue")
def NSString_expr(self):
"""Test expression commands for NSString."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break inside Test_NSString:
line = self.lines[2]
lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_FAILED)
# Test_NSString:
self.runCmd("thread backtrace")
self.expect("expression (int)[str length]",
patterns = ["\(int\) \$.* ="])
self.expect("expression (int)[str_id length]",
patterns = ["\(int\) \$.* ="])
self.expect("expression [str description]",
patterns = ["\(id\) \$.* = 0x"])
self.expect("expression (id)[str_id description]",
patterns = ["\(id\) \$.* = 0x"])
self.expect("expression str.length")
self.expect("expression str.description")
self.expect('expression str = @"new"')
self.runCmd("image lookup -t NSString")
self.expect('expression str = [NSString stringWithCString: "new"]')
self.runCmd("process continue")
def MyString_dump(self):
"""Test dump of a known Objective-C object by dereferencing it."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
line = self.lines[4]
lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_FAILED)
self.expect("expression --show-types -- *my",
patterns = ["\(MyString\) \$.* = ", "\(MyBase\)", "\(NSObject\)", "\(Class\)"])
self.runCmd("process continue")
def NSError_po(self):
"""Test that po of the result of an unknown method doesn't require a cast."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
line = self.lines[4]
lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_FAILED)
self.expect("po [NSError errorWithDomain:@\"Hello\" code:35 userInfo:nil]",
substrs = ["Error Domain=Hello", "Code=35", "be completed."])
self.runCmd("process continue")
def NSError_p(self):
"""Test that p of the result of an unknown method does require a cast."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
line = self.lines[4]
lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_FAILED)
self.expect("p [NSError thisMethodIsntImplemented:0]",
error = True,
patterns = ["no known method", "cast the message send to the method's return type"])
self.runCmd("process continue")
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()
|