TestDyldTrieSymbols.py
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
Test that we read the exported symbols from the dyld trie
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class DyldTrieSymbolsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
@skipIfRemote
@skipUnlessDarwin
def test_dyld_trie_symbols(self):
"""Test that we make create symbol table entries from the dyld trie data structure."""
self.build()
unstripped_exe = self.getBuildArtifact("a.out")
stripped_exe = self.getBuildArtifact("a.out-stripped")
unstripped_target = self.dbg.CreateTarget(unstripped_exe)
self.assertTrue(unstripped_target.IsValid(), "Got a vaid stripped target.")
# Verify that the expected symbols are present in an unstripped
# binary, and that we didn't duplicate the entries in the symbol
# table.
unstripped_bazval_symbols = unstripped_target.FindSymbols("bazval")
self.assertEqual(unstripped_bazval_symbols.GetSize(), 1)
unstripped_patval_symbols = unstripped_target.FindSymbols("patval")
self.assertEqual(unstripped_patval_symbols.GetSize(), 1)
unstripped_Z3foo_symbols = unstripped_target.FindSymbols("_Z3foov")
self.assertEqual(unstripped_Z3foo_symbols.GetSize(), 1)
unstripped_foo_symbols = unstripped_target.FindSymbols("foo")
self.assertEqual(unstripped_foo_symbols.GetSize(), 1)
# make sure we can look up the mangled name, demangled base name,
# demangled name with argument.
unstripped_Z3pat_symbols = unstripped_target.FindSymbols("_Z3pati")
self.assertEqual(unstripped_Z3pat_symbols.GetSize(), 1)
unstripped_pat_symbols = unstripped_target.FindSymbols("pat")
self.assertEqual(unstripped_pat_symbols.GetSize(), 1)
unstripped_patint_symbols = unstripped_target.FindSymbols("pat(int)")
self.assertEqual(unstripped_patint_symbols.GetSize(), 1)
unstripped_bar_symbols = unstripped_target.FindSymbols("bar")
self.assertEqual(unstripped_bar_symbols.GetSize(), 1)
# Verify that we can retrieve all the symbols with external
# linkage after the binary has been stripped; they should not
# exist in the nlist records at this point and can only be
# retrieved from the dyld trie structure.
stripped_target = self.dbg.CreateTarget(stripped_exe)
self.assertTrue(stripped_target.IsValid(), "Got a vaid stripped target.")
# Check that we're able to still retrieve all the symbols after
# the binary has been stripped. Check that one we know will be
# removed is absent.
stripped_bazval_symbols = stripped_target.FindSymbols("bazval")
self.assertEqual(stripped_bazval_symbols.GetSize(), 1)
stripped_patval_symbols = stripped_target.FindSymbols("patval")
self.assertEqual(stripped_patval_symbols.GetSize(), 1)
stripped_Z3foo_symbols = stripped_target.FindSymbols("_Z3foov")
self.assertEqual(stripped_Z3foo_symbols.GetSize(), 1)
stripped_foo_symbols = stripped_target.FindSymbols("foo")
self.assertEqual(stripped_foo_symbols.GetSize(), 1)
# make sure we can look up the mangled name, demangled base name,
# demangled name with argument.
stripped_Z3pat_symbols = stripped_target.FindSymbols("_Z3pati")
self.assertEqual(stripped_Z3pat_symbols.GetSize(), 1)
stripped_pat_symbols = stripped_target.FindSymbols("pat")
self.assertEqual(stripped_pat_symbols.GetSize(), 1)
stripped_patint_symbols = stripped_target.FindSymbols("pat(int)")
self.assertEqual(stripped_patint_symbols.GetSize(), 1)
# bar should have been strippped. We should not find it, or the
# stripping went wrong.
stripped_bar_symbols = stripped_target.FindSymbols("bar")
self.assertEqual(stripped_bar_symbols.GetSize(), 0)
# confirm that we classified objc runtime symbols correctly and
# stripped off the objc prefix from the symbol names.
syms_ctx = stripped_target.FindSymbols("SourceBase")
self.assertEqual(syms_ctx.GetSize(), 2)
# The next part if not deterministic and potentially causes replay to
# fail when the order is different during capture and replay.
if not configuration.is_reproducer():
sym1 = syms_ctx.GetContextAtIndex(0).GetSymbol()
sym2 = syms_ctx.GetContextAtIndex(1).GetSymbol()
# one of these should be a lldb.eSymbolTypeObjCClass, the other
# should be lldb.eSymbolTypeObjCMetaClass.
if sym1.GetType() == lldb.eSymbolTypeObjCMetaClass:
self.assertEqual(sym2.GetType(), lldb.eSymbolTypeObjCClass)
else:
if sym1.GetType() == lldb.eSymbolTypeObjCClass:
self.assertEqual(sym2.GetType(), lldb.eSymbolTypeObjCMetaClass)
else:
self.assertTrue(sym1.GetType() == lldb.eSymbolTypeObjCMetaClass or sym1.GetType() == lldb.eSymbolTypeObjCClass)
syms_ctx = stripped_target.FindSymbols("SourceDerived._derivedValue")
self.assertEqual(syms_ctx.GetSize(), 1)
sym = syms_ctx.GetContextAtIndex(0).GetSymbol()
self.assertEqual(sym.GetType(), lldb.eSymbolTypeObjCIVar)