1"""Test calling functions in class methods.""" 2 3from __future__ import print_function 4 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class TestObjCClassMethod(TestBase): 13 14 def setUp(self): 15 # Call super's setUp(). 16 TestBase.setUp(self) 17 # Find the line numbers to break inside main(). 18 self.main_source = "class.m" 19 self.break_line = line_number( 20 self.main_source, '// Set breakpoint here.') 21 22 @add_test_categories(['pyapi']) 23 def test_with_python_api(self): 24 """Test calling functions in class methods.""" 25 self.build() 26 exe = self.getBuildArtifact("a.out") 27 28 target = self.dbg.CreateTarget(exe) 29 self.assertTrue(target, VALID_TARGET) 30 31 bpt = target.BreakpointCreateByLocation( 32 self.main_source, self.break_line) 33 self.assertTrue(bpt, VALID_BREAKPOINT) 34 35 # Now launch the process, and do not stop at entry point. 36 process = target.LaunchSimple( 37 None, None, self.get_process_working_directory()) 38 39 self.assertTrue(process, PROCESS_IS_VALID) 40 41 # The stop reason of the thread should be breakpoint. 42 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) 43 44 # Make sure we stopped at the first breakpoint. 45 self.assertTrue( 46 len(thread_list) != 0, 47 "No thread stopped at our breakpoint.") 48 self.assertEqual(len(thread_list), 1, 49 "More than one thread stopped at our breakpoint.") 50 51 # Now make sure we can call a function in the class method we've 52 # stopped in. 53 frame = thread_list[0].GetFrameAtIndex(0) 54 self.assertTrue(frame, "Got a valid frame 0 frame.") 55 56 cmd_value = frame.EvaluateExpression( 57 "(int)[Foo doSomethingWithString:@\"Hello\"]") 58 if self.TraceOn(): 59 if cmd_value.IsValid(): 60 print("cmd_value is valid") 61 print("cmd_value has the value %d" % cmd_value.GetValueAsUnsigned()) 62 self.assertTrue(cmd_value.IsValid()) 63 self.assertEqual(cmd_value.GetValueAsUnsigned(), 5) 64