1""" 2Test that SBType returns SBModule of executable file but not 3of compile unit's object file. 4""" 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10 11 12class TestTypeGetModule(TestBase): 13 def find_module(self, target, name): 14 num_modules = target.GetNumModules() 15 index = 0 16 result = lldb.SBModule() 17 18 while index < num_modules: 19 module = target.GetModuleAtIndex(index) 20 if module.GetFileSpec().GetFilename() == name: 21 result = module 22 break 23 24 index += 1 25 26 self.assertTrue(result.IsValid()) 27 return result 28 29 def find_comp_unit(self, exe_module, name): 30 num_comp_units = exe_module.GetNumCompileUnits() 31 index = 0 32 result = lldb.SBCompileUnit() 33 34 while index < num_comp_units: 35 comp_unit = exe_module.GetCompileUnitAtIndex(index) 36 if comp_unit.GetFileSpec().GetFilename() == name: 37 result = comp_unit 38 break 39 40 index += 1 41 42 self.assertTrue(result.IsValid()) 43 return result 44 45 def find_type(self, type_list, name): 46 num_types = type_list.GetSize() 47 index = 0 48 result = lldb.SBType() 49 50 while index < num_types: 51 type = type_list.GetTypeAtIndex(index) 52 if type.GetName() == name: 53 result = type 54 break 55 56 index += 1 57 58 self.assertTrue(result.IsValid()) 59 return result 60 61 def test(self): 62 self.build() 63 target = lldbutil.run_to_breakpoint_make_target(self) 64 exe_module = self.find_module(target, "a.out") 65 66 num_comp_units = exe_module.GetNumCompileUnits() 67 self.assertGreaterEqual(num_comp_units, 3) 68 69 comp_unit = self.find_comp_unit(exe_module, "compile_unit1.c") 70 cu_type = self.find_type(comp_unit.GetTypes(), "compile_unit1_type") 71 self.assertEqual(exe_module, cu_type.GetModule()) 72 73 comp_unit = self.find_comp_unit(exe_module, "compile_unit2.c") 74 cu_type = self.find_type(comp_unit.GetTypes(), "compile_unit2_type") 75 self.assertEqual(exe_module, cu_type.GetModule()) 76