TestObjCMethods2.py revision daa6efe771f5f068e29328a774fa5bf2358ce14a
1""" 2Test more expression command sequences with objective-c. 3""" 4 5import os, time 6import unittest2 7import lldb 8from lldbtest import * 9 10@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 11class FoundationTestCase2(TestBase): 12 13 mydir = os.path.join("lang", "objc", "foundation") 14 15 def test_more_expr_commands_with_dsym(self): 16 """More expression commands for objective-c.""" 17 self.buildDsym() 18 self.more_expr_objc() 19 20 def test_more_expr_commands_with_dwarf(self): 21 """More expression commands for objective-c.""" 22 self.buildDwarf() 23 self.more_expr_objc() 24 25 def test_NSArray_expr_commands_with_dsym(self): 26 """Test expression commands for NSArray.""" 27 self.buildDsym() 28 self.NSArray_expr() 29 30 def test_NSArray_expr_commands_with_dwarf(self): 31 """Test expression commands for NSArray.""" 32 self.buildDwarf() 33 self.NSArray_expr() 34 35 def test_NSString_expr_commands_with_dsym(self): 36 """Test expression commands for NSString.""" 37 self.buildDsym() 38 self.NSString_expr() 39 40 def test_NSString_expr_commands_with_dwarf(self): 41 """Test expression commands for NSString.""" 42 self.buildDwarf() 43 self.NSString_expr() 44 45 def test_MyString_dump_with_dsym(self): 46 """Test dump of a known Objective-C object by dereferencing it.""" 47 self.buildDsym() 48 self.MyString_dump() 49 50 def test_MyString_dump_with_dwarf(self): 51 """Test dump of a known Objective-C object by dereferencing it.""" 52 self.buildDwarf() 53 self.MyString_dump() 54 55 def test_NSError_po_with_dsym(self): 56 """Test that po of the result of an unknown method doesn't require a cast.""" 57 self.buildDsym() 58 self.NSError_po() 59 60 def test_NSError_po_with_dwarf(self): 61 """Test that po of the result of an unknown method doesn't require a cast.""" 62 self.buildDsym() 63 self.NSError_po() 64 65 def test_NSError_p_with_dsym(self): 66 """Test that p of the result of an unknown method does require a cast.""" 67 self.buildDsym() 68 self.NSError_p() 69 70 def test_NSError_p_with_dwarf(self): 71 """Test that p of the result of an unknown method does require a cast.""" 72 self.buildDsym() 73 self.NSError_p() 74 75 def setUp(self): 76 # Call super's setUp(). 77 TestBase.setUp(self) 78 # Find the line numbers to break at. 79 self.lines = [] 80 self.lines.append(line_number('main.m', '// Expressions to test here for selector:')) 81 self.lines.append(line_number('main.m', '// Expressions to test here for NSArray:')) 82 self.lines.append(line_number('main.m', '// Expressions to test here for NSString:')) 83 self.lines.append(line_number('main.m', "// Set a breakpoint on '-[MyString description]' and test expressions:")) 84 self.lines.append(line_number('main.m', '// Set break point at this line')) 85 86 def more_expr_objc(self): 87 """More expression commands for objective-c.""" 88 exe = os.path.join(os.getcwd(), "a.out") 89 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 90 91 # Create a bunch of breakpoints. 92 for line in self.lines: 93 self.expect("breakpoint set -f main.m -l %d" % line, BREAKPOINT_CREATED, 94 substrs = ["Breakpoint created:", 95 "file ='main.m', line = %d, locations = 1" % line]) 96 97 self.runCmd("run", RUN_SUCCEEDED) 98 99 # Test_Selector: 100 self.runCmd("thread backtrace") 101 self.expect("expression (char *)sel_getName(sel)", 102 substrs = ["(char *)", 103 "length"]) 104 105 self.runCmd("process continue") 106 107 # Test_NSArray: 108 self.runCmd("thread backtrace") 109 self.runCmd("process continue") 110 111 # Test_NSString: 112 self.runCmd("thread backtrace") 113 self.runCmd("process continue") 114 115 # Test_MyString: 116 self.runCmd("thread backtrace") 117 self.expect("expression (char *)sel_getName(_cmd)", 118 substrs = ["(char *)", 119 "description"]) 120 121 self.runCmd("process continue") 122 123 @unittest2.expectedFailure 124 # <rdar://problem/8741897> Expressions should support properties 125 def NSArray_expr(self): 126 """Test expression commands for NSArray.""" 127 exe = os.path.join(os.getcwd(), "a.out") 128 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 129 130 # Break inside Test_NSArray: 131 line = self.lines[1] 132 self.expect("breakpoint set -f main.m -l %d" % line, BREAKPOINT_CREATED, 133 substrs = ["Breakpoint created:", 134 "file ='main.m', line = %d, locations = 1" % line]) 135 136 self.runCmd("run", RUN_SUCCEEDED) 137 138 # Test_NSArray: 139 self.runCmd("thread backtrace") 140 self.expect("expression (int)[nil_mutable_array count]", 141 patterns = ["\(int\) \$.* = 0"]) 142 self.expect("expression (int)[array1 count]", 143 patterns = ["\(int\) \$.* = 3"]) 144 self.expect("expression (int)[array2 count]", 145 patterns = ["\(int\) \$.* = 3"]) 146 self.expect("expression (int)array1.count", 147 patterns = ["\(int\) \$.* = 3"]) 148 self.expect("expression (int)array2.count", 149 patterns = ["\(int\) \$.* = 3"]) 150 self.runCmd("process continue") 151 152 @unittest2.expectedFailure 153 # <rdar://problem/8741897> Expressions should support properties 154 def NSString_expr(self): 155 """Test expression commands for NSString.""" 156 exe = os.path.join(os.getcwd(), "a.out") 157 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 158 159 # Break inside Test_NSString: 160 line = self.lines[2] 161 self.expect("breakpoint set -f main.m -l %d" % line, BREAKPOINT_CREATED, 162 substrs = ["Breakpoint created:", 163 "file ='main.m', line = %d, locations = 1" % line]) 164 165 self.runCmd("run", RUN_SUCCEEDED) 166 167 # Test_NSString: 168 self.runCmd("thread backtrace") 169 self.expect("expression (int)[str length]", 170 patterns = ["\(int\) \$.* ="]) 171 self.expect("expression (int)[str_id length]", 172 patterns = ["\(int\) \$.* ="]) 173 self.expect("expression [str description]", 174 patterns = ["\(id\) \$.* = 0x"]) 175 self.expect("expression [str_id description]", 176 patterns = ["\(id\) \$.* = 0x"]) 177 self.expect("expression str.description") 178 self.expect("expression str_id.description") 179 self.expect('expression str = @"new"') 180 self.expect('expression str = [NSString stringWithFormat: @"%cew", \'N\']') 181 self.runCmd("process continue") 182 183 def MyString_dump(self): 184 """Test dump of a known Objective-C object by dereferencing it.""" 185 exe = os.path.join(os.getcwd(), "a.out") 186 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 187 188 line = self.lines[4] 189 190 self.expect("breakpoint set -f main.m -l %d" % line, BREAKPOINT_CREATED, 191 substrs = ["Breakpoint created:", 192 "file ='main.m', line = %d, locations = 1" % line]) 193 194 self.runCmd("run", RUN_SUCCEEDED) 195 196 self.expect("expression *my", 197 patterns = ["\(MyString\) \$.* = ", "\(MyBase\)", "\(NSObject\)", "\(Class\)"]) 198 self.runCmd("process continue") 199 200 def NSError_po(self): 201 """Test that po of the result of an unknown method doesn't require a cast.""" 202 exe = os.path.join(os.getcwd(), "a.out") 203 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 204 205 line = self.lines[4] 206 207 self.expect("breakpoint set -f main.m -l %d" % line, BREAKPOINT_CREATED, 208 substrs = ["Breakpoint created:", 209 "file ='main.m', line = %d, locations = 1" % line]) 210 211 self.runCmd("run", RUN_SUCCEEDED) 212 213 self.expect("po [NSError errorWithDomain:@\"Hello\" code:35 userInfo:nil]", 214 patterns = ["\(id\) \$.* = ", "Error Domain=Hello", "Code=35", "be completed."]) 215 self.runCmd("process continue") 216 217 def NSError_p(self): 218 """Test that p of the result of an unknown method does require a cast.""" 219 exe = os.path.join(os.getcwd(), "a.out") 220 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 221 222 line = self.lines[4] 223 224 self.expect("breakpoint set -f main.m -l %d" % line, BREAKPOINT_CREATED, 225 substrs = ["Breakpoint created:", 226 "file ='main.m', line = %d, locations = 1" % line]) 227 228 self.runCmd("run", RUN_SUCCEEDED) 229 230 self.expect("p [NSError errorWithDomain:@\"Hello\" code:35 userInfo:nil]", 231 error = True, 232 patterns = ["no known method", "cast the message send to the method's return type"]) 233 self.runCmd("process continue") 234 235if __name__ == '__main__': 236 import atexit 237 lldb.SBDebugger.Initialize() 238 atexit.register(lambda: lldb.SBDebugger.Terminate()) 239 unittest2.main() 240