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 @skipUnlessDarwin 27 @add_test_categories(['pyapi']) 28 def test_objc_checker(self): 29 """Test that checkers catch unrecognized selectors""" 30 if self.getArchitecture() == 'i386': 31 self.skipTest("requires Objective-C 2.0 runtime") 32 33 self.build() 34 exe = self.getBuildArtifact("a.out") 35 36 # Create a target from the debugger. 37 38 target = self.dbg.CreateTarget(exe) 39 self.assertTrue(target, VALID_TARGET) 40 41 # Set up our breakpoints: 42 43 main_bkpt = target.BreakpointCreateBySourceRegex( 44 "Set a breakpoint here.", lldb.SBFileSpec(self.source_name)) 45 self.assertTrue(main_bkpt and 46 main_bkpt.GetNumLocations() == 1, 47 VALID_BREAKPOINT) 48 49 # Now launch the process, and do not stop at the entry point. 50 process = target.LaunchSimple( 51 None, None, self.get_process_working_directory()) 52 53 self.assertTrue(process.GetState() == lldb.eStateStopped, 54 PROCESS_STOPPED) 55 56 threads = lldbutil.get_threads_stopped_at_breakpoint( 57 process, main_bkpt) 58 self.assertTrue(len(threads) == 1) 59 thread = threads[0] 60 61 # 62 # The class Simple doesn't have a count method. Make sure that we don't 63 # actually try to send count but catch it as an unrecognized selector. 64 65 frame = thread.GetFrameAtIndex(0) 66 expr_value = frame.EvaluateExpression("(int) [my_simple count]", False) 67 expr_error = expr_value.GetError() 68 69 self.assertTrue(expr_error.Fail()) 70 71 # Make sure the call produced no NSLog stdout. 72 stdout = process.GetSTDOUT(100) 73 self.assertTrue(stdout is None or (len(stdout) == 0)) 74 75 # Make sure the error is helpful: 76 err_string = expr_error.GetCString() 77 self.assertTrue("selector" in err_string) 78 79 # 80 # Check that we correctly insert the checker for an 81 # ObjC method with the struct return convention. 82 # Getting this wrong would cause us to call the checker 83 # with the wrong arguments, and the checker would crash 84 # So I'm just checking "expression runs successfully" here: 85 # 86 expr_value = frame.EvaluateExpression("[my_simple getBigStruct]", False) 87 expr_error = expr_value.GetError() 88 89 self.assertTrue(expr_error.Success()) 90 91