1"""
2Test symbol table access for main.m.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class FoundationSymtabTestCase(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
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    @add_test_categories(['pyapi'])
28    def test_with_python_api(self):
29        """Test symbol table access with Python APIs."""
30        self.build()
31        exe = self.getBuildArtifact("a.out")
32        target = self.dbg.CreateTarget(exe)
33        self.assertTrue(target, VALID_TARGET)
34
35        # Launch the process, and do not stop at the entry point.
36        process = target.LaunchSimple(
37            None, None, self.get_process_working_directory())
38        self.assertTrue(process, PROCESS_IS_VALID)
39
40        # Create the filespec by which to locate our a.out module. Use the
41        # absolute path to get the module for the current variant.
42        filespec = lldb.SBFileSpec(exe, False)
43
44        module = target.FindModule(filespec)
45        self.assertTrue(module, VALID_MODULE)
46
47        # Create the set of known symbols.  As we iterate through the symbol
48        # table, remove the symbol from the set if it is a known symbol.
49        expected_symbols = set(self.symbols_list)
50        for symbol in module:
51            self.assertTrue(symbol, VALID_SYMBOL)
52            self.trace("symbol:", symbol)
53            name = symbol.GetName()
54            if name in expected_symbols:
55                self.trace("Removing %s from known_symbols %s" % (name, expected_symbols))
56                expected_symbols.remove(name)
57
58        # At this point, the known_symbols set should have become an empty set.
59        # If not, raise an error.
60        self.trace("symbols unaccounted for:", expected_symbols)
61        self.assertEqual(len(expected_symbols), 0,
62                        "All the known symbols are accounted for")
63