brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.8 KiB · 788cff9 Raw
104 lines · python
1"""2Test that we read the exported symbols from the dyld trie3"""4 5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11class DyldTrieSymbolsTestCase(TestBase):12    NO_DEBUG_INFO_TESTCASE = True13 14    @skipIfRemote15    @skipUnlessDarwin16    def test_dyld_trie_symbols(self):17        """Test that we make create symbol table entries from the dyld trie data structure."""18        self.build()19        unstripped_exe = self.getBuildArtifact("a.out")20        stripped_exe = self.getBuildArtifact("a.out-stripped")21 22        unstripped_target = self.dbg.CreateTarget(unstripped_exe)23        self.assertTrue(unstripped_target.IsValid(), "Got a vaid stripped target.")24 25        # Verify that the expected symbols are present in an unstripped26        # binary, and that we didn't duplicate the entries in the symbol27        # table.28        unstripped_bazval_symbols = unstripped_target.FindSymbols("bazval")29        self.assertEqual(unstripped_bazval_symbols.GetSize(), 1)30        unstripped_patval_symbols = unstripped_target.FindSymbols("patval")31        self.assertEqual(unstripped_patval_symbols.GetSize(), 1)32        unstripped_Z3foo_symbols = unstripped_target.FindSymbols("_Z3foov")33        self.assertEqual(unstripped_Z3foo_symbols.GetSize(), 1)34        unstripped_foo_symbols = unstripped_target.FindSymbols("foo")35        self.assertEqual(unstripped_foo_symbols.GetSize(), 1)36 37        # Make sure we can look up the mangled name and the demangled base38        # name.39        unstripped_Z3pat_symbols = unstripped_target.FindSymbols("_Z3pati")40        self.assertEqual(unstripped_Z3pat_symbols.GetSize(), 1)41        unstripped_pat_symbols = unstripped_target.FindSymbols("pat")42        self.assertEqual(unstripped_pat_symbols.GetSize(), 1)43 44        unstripped_bar_symbols = unstripped_target.FindSymbols("bar")45        self.assertEqual(unstripped_bar_symbols.GetSize(), 1)46 47        # Verify that we can retrieve all the symbols with external48        # linkage after the binary has been stripped; they should not49        # exist in the nlist records at this point and can only be50        # retrieved from the dyld trie structure.51 52        stripped_target = self.dbg.CreateTarget(stripped_exe)53        self.assertTrue(stripped_target.IsValid(), "Got a vaid stripped target.")54 55        # Check that we're able to still retrieve all the symbols after56        # the binary has been stripped. Check that one we know will be57        # removed is absent.58        stripped_bazval_symbols = stripped_target.FindSymbols("bazval")59        self.assertEqual(stripped_bazval_symbols.GetSize(), 1)60        stripped_patval_symbols = stripped_target.FindSymbols("patval")61        self.assertEqual(stripped_patval_symbols.GetSize(), 1)62        stripped_Z3foo_symbols = stripped_target.FindSymbols("_Z3foov")63        self.assertEqual(stripped_Z3foo_symbols.GetSize(), 1)64        stripped_foo_symbols = stripped_target.FindSymbols("foo")65        self.assertEqual(stripped_foo_symbols.GetSize(), 1)66 67        # make sure we can look up the mangled name, demangled base name,68        # demangled name with argument.69        stripped_Z3pat_symbols = stripped_target.FindSymbols("_Z3pati")70        self.assertEqual(stripped_Z3pat_symbols.GetSize(), 1)71        stripped_pat_symbols = stripped_target.FindSymbols("pat")72        self.assertEqual(stripped_pat_symbols.GetSize(), 1)73 74        # bar should have been strippped.  We should not find it, or the75        # stripping went wrong.76        stripped_bar_symbols = stripped_target.FindSymbols("bar")77        self.assertEqual(stripped_bar_symbols.GetSize(), 0)78 79        # confirm that we classified objc runtime symbols correctly and80        # stripped off the objc prefix from the symbol names.81        syms_ctx = stripped_target.FindSymbols("SourceBase")82        self.assertEqual(syms_ctx.GetSize(), 2)83 84        sym1 = syms_ctx.GetContextAtIndex(0).GetSymbol()85        sym2 = syms_ctx.GetContextAtIndex(1).GetSymbol()86 87        # one of these should be a lldb.eSymbolTypeObjCClass, the other88        # should be lldb.eSymbolTypeObjCMetaClass.89        if sym1.GetType() == lldb.eSymbolTypeObjCMetaClass:90            self.assertEqual(sym2.GetType(), lldb.eSymbolTypeObjCClass)91        else:92            if sym1.GetType() == lldb.eSymbolTypeObjCClass:93                self.assertEqual(sym2.GetType(), lldb.eSymbolTypeObjCMetaClass)94            else:95                self.assertTrue(96                    sym1.GetType() == lldb.eSymbolTypeObjCMetaClass97                    or sym1.GetType() == lldb.eSymbolTypeObjCClass98                )99 100        syms_ctx = stripped_target.FindSymbols("SourceDerived._derivedValue")101        self.assertEqual(syms_ctx.GetSize(), 1)102        sym = syms_ctx.GetContextAtIndex(0).GetSymbol()103        self.assertEqual(sym.GetType(), lldb.eSymbolTypeObjCIVar)104