1"""
2Test symbol table access for main.m.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
11class FoundationSymtabTestCase(TestBase):
12
13    mydir = os.path.join("lang", "objc", "foundation")
14
15    symbols_list = ['-[MyString initWithNSString:]',
16                    '-[MyString dealloc]',
17                    '-[MyString description]',
18                    '-[MyString descriptionPauses]',     # synthesized property
19                    '-[MyString setDescriptionPauses:]', # synthesized property
20                    'Test_Selector',
21                    'Test_NSString',
22                    'Test_MyString',
23                    'Test_NSArray',
24                    'main'
25                    ]
26
27    @python_api_test
28    @dsym_test
29    def test_with_dsym_and_python_api(self):
30        """Test symbol table access with Python APIs."""
31        self.buildDsym()
32        self.symtab_access_python()
33
34    @python_api_test
35    @dwarf_test
36    def test_with_dwarf_and_python_api(self):
37        """Test symbol table access with Python APIs."""
38        self.buildDwarf()
39        self.symtab_access_python()
40
41    def symtab_access_python(self):
42        """Test symbol table access with Python APIs."""
43        exe = os.path.join(os.getcwd(), "a.out")
44        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
45
46        target = self.dbg.CreateTarget(exe)
47        self.assertTrue(target, VALID_TARGET)
48
49        # Launch the process, and do not stop at the entry point.
50        process = target.LaunchSimple(None, None, os.getcwd())
51
52        #
53        # Exercise Python APIs to access the symbol table entries.
54        #
55
56        # Create the filespec by which to locate our a.out module.
57        filespec = lldb.SBFileSpec(exe, False)
58
59        module = target.FindModule(filespec)
60        self.assertTrue(module, VALID_MODULE)
61
62        # Create the set of known symbols.  As we iterate through the symbol
63        # table, remove the symbol from the set if it is a known symbol.
64        expected_symbols = set(self.symbols_list)
65        for symbol in module:
66            self.assertTrue(symbol, VALID_SYMBOL)
67            #print "symbol:", symbol
68            name = symbol.GetName()
69            if name in expected_symbols:
70                #print "Removing %s from known_symbols %s" % (name, expected_symbols)
71                expected_symbols.remove(name)
72
73        # At this point, the known_symbols set should have become an empty set.
74        # If not, raise an error.
75        #print "symbols unaccounted for:", expected_symbols
76        self.assertTrue(len(expected_symbols) == 0,
77                        "All the known symbols are accounted for")
78
79
80if __name__ == '__main__':
81    import atexit
82    lldb.SBDebugger.Initialize()
83    atexit.register(lambda: lldb.SBDebugger.Terminate())
84    unittest2.main()
85