2 Test that we read the exported symbols from the dyld trie
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
import lldbutil
11 class DyldTrieSymbolsTestCase(TestBase
):
12 NO_DEBUG_INFO_TESTCASE
= True
16 def test_dyld_trie_symbols(self
):
17 """Test that we make create symbol table entries from the dyld trie data structure."""
19 unstripped_exe
= self
.getBuildArtifact("a.out")
20 stripped_exe
= self
.getBuildArtifact("a.out-stripped")
22 unstripped_target
= self
.dbg
.CreateTarget(unstripped_exe
)
23 self
.assertTrue(unstripped_target
.IsValid(), "Got a vaid stripped target.")
25 # Verify that the expected symbols are present in an unstripped
26 # binary, and that we didn't duplicate the entries in the symbol
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)
37 # Make sure we can look up the mangled name and the demangled base
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)
44 unstripped_bar_symbols
= unstripped_target
.FindSymbols("bar")
45 self
.assertEqual(unstripped_bar_symbols
.GetSize(), 1)
47 # Verify that we can retrieve all the symbols with external
48 # linkage after the binary has been stripped; they should not
49 # exist in the nlist records at this point and can only be
50 # retrieved from the dyld trie structure.
52 stripped_target
= self
.dbg
.CreateTarget(stripped_exe
)
53 self
.assertTrue(stripped_target
.IsValid(), "Got a vaid stripped target.")
55 # Check that we're able to still retrieve all the symbols after
56 # the binary has been stripped. Check that one we know will be
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)
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)
74 # bar should have been strippped. We should not find it, or the
75 # stripping went wrong.
76 stripped_bar_symbols
= stripped_target
.FindSymbols("bar")
77 self
.assertEqual(stripped_bar_symbols
.GetSize(), 0)
79 # confirm that we classified objc runtime symbols correctly and
80 # stripped off the objc prefix from the symbol names.
81 syms_ctx
= stripped_target
.FindSymbols("SourceBase")
82 self
.assertEqual(syms_ctx
.GetSize(), 2)
84 sym1
= syms_ctx
.GetContextAtIndex(0).GetSymbol()
85 sym2
= syms_ctx
.GetContextAtIndex(1).GetSymbol()
87 # one of these should be a lldb.eSymbolTypeObjCClass, the other
88 # should be lldb.eSymbolTypeObjCMetaClass.
89 if sym1
.GetType() == lldb
.eSymbolTypeObjCMetaClass
:
90 self
.assertEqual(sym2
.GetType(), lldb
.eSymbolTypeObjCClass
)
92 if sym1
.GetType() == lldb
.eSymbolTypeObjCClass
:
93 self
.assertEqual(sym2
.GetType(), lldb
.eSymbolTypeObjCMetaClass
)
96 sym1
.GetType() == lldb
.eSymbolTypeObjCMetaClass
97 or sym1
.GetType() == lldb
.eSymbolTypeObjCClass
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
)