Home | History | Annotate | Download | only in foundation
      1 """
      2 Test that Objective-C methods from the runtime work correctly.
      3 """
      4 
      5 import os, time
      6 import unittest2
      7 import lldb
      8 from lldbtest import *
      9 import lldbutil
     10 
     11 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     12 class RuntimeTypesTestCase(TestBase):
     13 
     14     mydir = os.path.join("lang", "objc", "foundation")
     15 
     16     @dsym_test
     17     def test_break_with_dsym(self):
     18         """Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'."""
     19         # This only applies to the v2 runtime
     20         if self.getArchitecture() == 'x86_64':
     21             self.buildDsym()
     22             self.runtime_types()
     23 
     24     @dwarf_test
     25     def test_break_with_dwarf(self):
     26         """Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'."""
     27         # This only applies to the v2 runtime
     28         if self.getArchitecture() == 'x86_64':
     29             self.buildDwarf()
     30             self.runtime_types()
     31 
     32     def runtime_types(self):
     33         exe = os.path.join(os.getcwd(), "a.out")
     34         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
     35 
     36         # Stop at -[MyString description].
     37         lldbutil.run_break_set_by_symbol (self, '-[MyString description]', num_expected_locations=1, sym_exact=True)
     38 
     39         self.runCmd("run", RUN_SUCCEEDED)
     40 
     41         # The backtrace should show we stop at -[MyString description].
     42         self.expect("thread backtrace", "Stop at -[MyString description]",
     43             substrs = ["a.out`-[MyString description]"])
     44 
     45         # Use runtime information about NSString.
     46 
     47         # The length property should be usable.
     48         self.expect("expression str.length", VARIABLES_DISPLAYED_CORRECTLY,
     49             substrs = ["(unsigned long long)"])
     50 
     51         # Static methods on NSString should work.
     52         self.expect("expr [NSString stringWithCString:\"foo\" encoding:1]", VALID_TYPE,
     53             substrs = ["(id)", "$1"])
     54 
     55         self.expect("po $1", VARIABLES_DISPLAYED_CORRECTLY,
     56             substrs = ["foo"])
     57 
     58 if __name__ == '__main__':
     59     import atexit
     60     lldb.SBDebugger.Initialize()
     61     atexit.register(lambda: lldb.SBDebugger.Terminate())
     62     unittest2.main()
     63