75 lines · python
1"""2Test more expression command sequences with objective-c.3"""4 5 6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class FoundationTestCaseNSError(TestBase):13 @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>")14 def test_runtime_types(self):15 """Test commands that require runtime types"""16 self.build()17 self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(18 self, "// Break here for NSString tests", lldb.SBFileSpec("main.m", False)19 )20 21 # Test_NSString:22 self.runCmd("thread backtrace")23 self.expect("expression [str length]", patterns=[r"\(NSUInteger\) \$.* ="])24 self.expect("expression str.length")25 self.expect('expression str = [NSString stringWithCString: "new"]')26 self.expect(27 'po [NSError errorWithDomain:@"Hello" code:35 userInfo:@{@"NSDescription" : @"be completed."}]',28 substrs=["Error Domain=Hello", "Code=35", "be completed."],29 )30 self.runCmd("process continue")31 32 @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>")33 def test_NSError_p(self):34 """Test that p of the result of an unknown method does require a cast."""35 self.build()36 self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(37 self, "// Set break point at this line", lldb.SBFileSpec("main.m", False)38 )39 self.expect(40 "expression [NSError thisMethodIsntImplemented:0]",41 error=True,42 patterns=[43 "no known method",44 "cast the message send to the method's return type",45 ],46 )47 self.runCmd("process continue")48 49 @skipIfOutOfTreeDebugserver50 def test_runtime_types_efficient_memreads(self):51 # Test that we use an efficient reading of memory when reading52 # Objective-C method descriptions.53 logfile = os.path.join(self.getBuildDir(), "log.txt")54 self.runCmd(f"log enable -f {logfile} gdb-remote packets process")55 self.addTearDownHook(lambda: self.runCmd("log disable gdb-remote packets"))56 57 self.build()58 self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(59 self, "// Break here for NSString tests", lldb.SBFileSpec("main.m", False)60 )61 62 self.runCmd(f"proc plugin packet send StartTesting", check=False)63 self.expect('expression str = [NSString stringWithCString: "new"]')64 self.runCmd(f"proc plugin packet send EndTesting", check=False)65 66 self.assertTrue(os.path.exists(logfile))67 log_text = open(logfile).read()68 log_text = log_text.split("StartTesting", 1)[-1].split("EndTesting", 1)[0]69 70 # This test is only checking that the packet it used at all (and that71 # no errors are produced). It doesn't check that the packet is being72 # used to solve a problem in an optimal way.73 self.assertIn("MultiMemRead:", log_text)74 self.assertNotIn("MultiMemRead error", log_text)75