/
TestTypeGetModule.py
94 lines (68 loc) · 2.88 KB
/
TestTypeGetModule.py
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
"""
Test that SBType returns SBModule of executable file but not
of compile unit's object file.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil
class TestTypeGetModule(TestBase):
mydir = TestBase.compute_mydir(__file__)
def find_module(self, target, name):
num_modules = target.GetNumModules()
index = 0
result = lldb.SBModule()
while index < num_modules:
module = target.GetModuleAtIndex(index)
if module.GetFileSpec().GetFilename() == name:
result = module
break
index += 1
return result
def find_comp_unit(self, exe_module, name):
num_comp_units = exe_module.GetNumCompileUnits()
index = 0
result = lldb.SBCompileUnit()
while index < num_comp_units:
comp_unit = exe_module.GetCompileUnitAtIndex(index)
if comp_unit.GetFileSpec().GetFilename() == name:
result = comp_unit
break
index += 1
return result
def find_type(self, type_list, name):
num_types = type_list.GetSize()
index = 0
result = lldb.SBType()
while index < num_types:
type = type_list.GetTypeAtIndex(index)
if type.GetName() == name:
result = type
break
index += 1
return result
def test(self):
self.build()
target = lldbutil.run_to_breakpoint_make_target(self)
exe_module = self.find_module(target, 'a.out')
self.assertTrue(exe_module.IsValid())
type1_name = 'compile_unit1_type'
type2_name = 'compile_unit2_type'
num_comp_units = exe_module.GetNumCompileUnits()
self.assertEqual(num_comp_units, 3)
comp_unit = self.find_comp_unit(exe_module, 'compile_unit1.c')
self.assertTrue(comp_unit.IsValid())
cu_type = self.find_type(comp_unit.GetTypes(), type1_name)
self.assertTrue(cu_type.IsValid())
self.assertEqual(cu_type.GetName(), type1_name)
comp_unit = self.find_comp_unit(exe_module, 'compile_unit2.c')
self.assertTrue(comp_unit.IsValid())
cu_type = self.find_type(comp_unit.GetTypes(), type2_name)
self.assertTrue(cu_type.IsValid())
self.assertEqual(cu_type.GetName(), type2_name)
type1 = target.FindFirstType(type1_name)
self.assertTrue(type1.IsValid())
type2 = target.FindFirstType(type2_name)
self.assertTrue(type2.IsValid())
self.assertTrue(exe_module == type1.GetModule() and
exe_module == type2.GetModule())