1""" 2Use lldb Python API to make sure the dynamic checkers are doing their jobs. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class ObjCCheckerTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 NO_DEBUG_INFO_TESTCASE = True 18 19 def setUp(self): 20 # Call super's setUp(). 21 TestBase.setUp(self) 22 23 # Find the line number to break for main.c. 24 self.source_name = 'main.m' 25 26 @add_test_categories(['pyapi']) 27 def test_objc_checker(self): 28 """Test that checkers catch unrecognized selectors""" 29 if self.getArchitecture() == 'i386': 30 self.skipTest("requires Objective-C 2.0 runtime") 31 32 self.build() 33 exe = self.getBuildArtifact("a.out") 34 35 # Create a target from the debugger. 36 37 target = self.dbg.CreateTarget(exe) 38 self.assertTrue(target, VALID_TARGET) 39 40 # Set up our breakpoints: 41 42 main_bkpt = target.BreakpointCreateBySourceRegex( 43 "Set a breakpoint here.", lldb.SBFileSpec(self.source_name)) 44 self.assertTrue(main_bkpt and 45 main_bkpt.GetNumLocations() == 1, 46 VALID_BREAKPOINT) 47 48 # Now launch the process, and do not stop at the entry point. 49 process = target.LaunchSimple( 50 None, None, self.get_process_working_directory()) 51 52 self.assertState(process.GetState(), lldb.eStateStopped, 53 PROCESS_STOPPED) 54 55 threads = lldbutil.get_threads_stopped_at_breakpoint( 56 process, main_bkpt) 57 self.assertEqual(len(threads), 1) 58 thread = threads[0] 59 60 # 61 # The class Simple doesn't have a count method. Make sure that we don't 62 # actually try to send count but catch it as an unrecognized selector. 63 64 frame = thread.GetFrameAtIndex(0) 65 expr_value = frame.EvaluateExpression("(int) [my_simple count]", False) 66 expr_error = expr_value.GetError() 67 68 self.assertTrue(expr_error.Fail()) 69 70 # Make sure the call produced no NSLog stdout. 71 stdout = process.GetSTDOUT(100) 72 self.assertTrue(stdout is None or (len(stdout) == 0)) 73 74 # Make sure the error is helpful: 75 err_string = expr_error.GetCString() 76 self.assertIn("selector", err_string) 77 78 # 79 # Check that we correctly insert the checker for an 80 # ObjC method with the struct return convention. 81 # Getting this wrong would cause us to call the checker 82 # with the wrong arguments, and the checker would crash 83 # So I'm just checking "expression runs successfully" here: 84 # 85 expr_value = frame.EvaluateExpression("[my_simple getBigStruct]", False) 86 expr_error = expr_value.GetError() 87 88 self.assertSuccess(expr_error) 89 90