1"""Test calling functions in static methods.""" 2 3import os, time 4import unittest2 5import lldb 6import lldbutil 7from lldbtest import * 8 9class TestObjCStaticMethod(TestBase): 10 11 mydir = os.path.join("lang", "objc", "objc-static-method") 12 13 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 14 @python_api_test 15 #<rdar://problem/9745789> "expression" can't call functions in class methods 16 @dsym_test 17 def test_with_dsym_and_python_api(self): 18 """Test calling functions in static methods.""" 19 self.buildDsym() 20 self.objc_static_method() 21 22 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 23 @python_api_test 24 #<rdar://problem/9745789> "expression" can't call functions in class methods 25 @dwarf_test 26 def test_with_dwarf_and_python_api(self): 27 """Test calling functions in static methods.""" 28 self.buildDwarf() 29 self.objc_static_method() 30 31 def setUp(self): 32 # Call super's setUp(). 33 TestBase.setUp(self) 34 # Find the line numbers to break inside main(). 35 self.main_source = "static.m" 36 self.break_line = line_number(self.main_source, '// Set breakpoint here.') 37 38 #rdar://problem/9745789 "expression" can't call functions in class methods 39 def objc_static_method(self): 40 """Test calling functions in static methods.""" 41 exe = os.path.join(os.getcwd(), "a.out") 42 43 target = self.dbg.CreateTarget(exe) 44 self.assertTrue(target, VALID_TARGET) 45 46 bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) 47 self.assertTrue(bpt, VALID_BREAKPOINT) 48 49 # Now launch the process, and do not stop at entry point. 50 process = target.LaunchSimple (None, None, os.getcwd()) 51 52 self.assertTrue(process, PROCESS_IS_VALID) 53 54 # The stop reason of the thread should be breakpoint. 55 thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt) 56 57 # Make sure we stopped at the first breakpoint. 58 self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.") 59 self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.") 60 61 # Now make sure we can call a function in the static method we've stopped in. 62 frame = thread_list[0].GetFrameAtIndex(0) 63 self.assertTrue (frame, "Got a valid frame 0 frame.") 64 65 cmd_value = frame.EvaluateExpression ("(char *) sel_getName (_cmd)") 66 self.assertTrue (cmd_value.IsValid()) 67 sel_name = cmd_value.GetSummary() 68 self.assertTrue (sel_name == "\"doSomethingWithString:\"", "Got the right value for the selector as string.") 69 70 cmd_value = frame.EvaluateExpression ("[self doSomethingElseWithString:string]") 71 self.assertTrue (cmd_value.IsValid()) 72 string_length = cmd_value.GetValueAsUnsigned() 73 self.assertTrue (string_length == 27, "Got the right value from another class method on the same class.") 74 75if __name__ == '__main__': 76 import atexit 77 lldb.SBDebugger.Initialize() 78 atexit.register(lambda: lldb.SBDebugger.Terminate()) 79 unittest2.main() 80