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
11@skipUnlessDarwin
12class FoundationSymtabTestCase(TestBase):
13
14    mydir = TestBase.compute_mydir(__file__)
15
16    symbols_list = ['-[MyString initWithNSString:]',
17                    '-[MyString dealloc]',
18                    '-[MyString description]',
19                    '-[MyString descriptionPauses]',     # synthesized property
20                    # synthesized property
21                    '-[MyString setDescriptionPauses:]',
22                    'Test_Selector',
23                    'Test_NSString',
24                    'Test_MyString',
25                    'Test_NSArray',
26                    'main'
27                    ]
28
29    @add_test_categories(['pyapi'])
30    def test_with_python_api(self):
31        """Test symbol table access with Python APIs."""
32        self.build()
33        exe = self.getBuildArtifact("a.out")
34        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
35
36        target = self.dbg.CreateTarget(exe)
37        self.assertTrue(target, VALID_TARGET)
38
39        # Launch the process, and do not stop at the entry point.
40        process = target.LaunchSimple(
41            None, None, self.get_process_working_directory())
42
43        #
44        # Exercise Python APIs to access the symbol table entries.
45        #
46
47        # Create the filespec by which to locate our a.out module.
48        filespec = lldb.SBFileSpec(exe, False)
49
50        module = target.FindModule(filespec)
51        self.assertTrue(module, VALID_MODULE)
52
53        # Create the set of known symbols.  As we iterate through the symbol
54        # table, remove the symbol from the set if it is a known symbol.
55        expected_symbols = set(self.symbols_list)
56        for symbol in module:
57            self.assertTrue(symbol, VALID_SYMBOL)
58            #print("symbol:", symbol)
59            name = symbol.GetName()
60            if name in expected_symbols:
61                #print("Removing %s from known_symbols %s" % (name, expected_symbols))
62                expected_symbols.remove(name)
63
64        # At this point, the known_symbols set should have become an empty set.
65        # If not, raise an error.
66        #print("symbols unaccounted for:", expected_symbols)
67        self.assertTrue(len(expected_symbols) == 0,
68                        "All the known symbols are accounted for")
69