xref: /llvm-project/lldb/test/API/lang/objc/foundation/TestSymbolTable.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest symbol table access for main.m.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprechtimport lldb
699451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
799451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
899451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprechtclass FoundationSymtabTestCase(TestBase):
12*2238dcc3SJonas Devlieghere    symbols_list = [
13*2238dcc3SJonas Devlieghere        "-[MyString initWithNSString:]",
14*2238dcc3SJonas Devlieghere        "-[MyString dealloc]",
15*2238dcc3SJonas Devlieghere        "-[MyString description]",
16*2238dcc3SJonas Devlieghere        "-[MyString descriptionPauses]",  # synthesized property
17*2238dcc3SJonas Devlieghere        "-[MyString setDescriptionPauses:]",  # synthesized property
18*2238dcc3SJonas Devlieghere        "Test_Selector",
19*2238dcc3SJonas Devlieghere        "Test_NSString",
20*2238dcc3SJonas Devlieghere        "Test_MyString",
21*2238dcc3SJonas Devlieghere        "Test_NSArray",
22*2238dcc3SJonas Devlieghere        "main",
2399451b44SJordan Rupprecht    ]
2499451b44SJordan Rupprecht
25*2238dcc3SJonas Devlieghere    @add_test_categories(["pyapi"])
2699451b44SJordan Rupprecht    def test_with_python_api(self):
2799451b44SJordan Rupprecht        """Test symbol table access with Python APIs."""
2899451b44SJordan Rupprecht        self.build()
2999451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
3099451b44SJordan Rupprecht        target = self.dbg.CreateTarget(exe)
3199451b44SJordan Rupprecht        self.assertTrue(target, VALID_TARGET)
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht        # Launch the process, and do not stop at the entry point.
34*2238dcc3SJonas Devlieghere        process = target.LaunchSimple(None, None, self.get_process_working_directory())
35e1d2ceceSJonas Devlieghere        self.assertTrue(process, PROCESS_IS_VALID)
3699451b44SJordan Rupprecht
37b505ed9dSJonas Devlieghere        # Create the filespec by which to locate our a.out module. Use the
38b505ed9dSJonas Devlieghere        # absolute path to get the module for the current variant.
3999451b44SJordan Rupprecht        filespec = lldb.SBFileSpec(exe, False)
4099451b44SJordan Rupprecht
4199451b44SJordan Rupprecht        module = target.FindModule(filespec)
4299451b44SJordan Rupprecht        self.assertTrue(module, VALID_MODULE)
4399451b44SJordan Rupprecht
44ae903f03SJonas Devlieghere        # Create the set of known symbols.  As we iterate through the symbol
45ae903f03SJonas Devlieghere        # table, remove the symbol from the set if it is a known symbol.
46ae903f03SJonas Devlieghere        expected_symbols = set(self.symbols_list)
47ae903f03SJonas Devlieghere        for symbol in module:
48ae903f03SJonas Devlieghere            self.assertTrue(symbol, VALID_SYMBOL)
49e1d2ceceSJonas Devlieghere            self.trace("symbol:", symbol)
50ae903f03SJonas Devlieghere            name = symbol.GetName()
51ae903f03SJonas Devlieghere            if name in expected_symbols:
52*2238dcc3SJonas Devlieghere                self.trace(
53*2238dcc3SJonas Devlieghere                    "Removing %s from known_symbols %s" % (name, expected_symbols)
54*2238dcc3SJonas Devlieghere                )
55ae903f03SJonas Devlieghere                expected_symbols.remove(name)
56ae903f03SJonas Devlieghere
57ae903f03SJonas Devlieghere        # At this point, the known_symbols set should have become an empty set.
58ae903f03SJonas Devlieghere        # If not, raise an error.
59e1d2ceceSJonas Devlieghere        self.trace("symbols unaccounted for:", expected_symbols)
60*2238dcc3SJonas Devlieghere        self.assertEqual(
61*2238dcc3SJonas Devlieghere            len(expected_symbols), 0, "All the known symbols are accounted for"
62*2238dcc3SJonas Devlieghere        )
63