1""" 2Test SBSection APIs. 3""" 4 5 6 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class SectionAPITestCase(TestBase): 13 14 def test_get_target_byte_size(self): 15 d = {'EXE': 'b.out'} 16 self.build(dictionary=d) 17 self.setTearDownCleanup(dictionary=d) 18 exe = self.getBuildArtifact('b.out') 19 target = self.dbg.CreateTarget(exe) 20 self.assertTrue(target, VALID_TARGET) 21 22 # find the .data section of the main module 23 mod = target.GetModuleAtIndex(0) 24 data_section = None 25 for s in mod.sections: 26 sect_type = s.GetSectionType() 27 if sect_type == lldb.eSectionTypeData: 28 data_section = s 29 break 30 elif sect_type == lldb.eSectionTypeContainer: 31 for i in range(s.GetNumSubSections()): 32 ss = s.GetSubSectionAtIndex(i) 33 sect_type = ss.GetSectionType() 34 if sect_type == lldb.eSectionTypeData: 35 data_section = ss 36 break 37 38 self.assertIsNotNone(data_section) 39 self.assertEqual(data_section.target_byte_size, 1) 40 41 def test_get_alignment(self): 42 exe = self.getBuildArtifact("aligned.out") 43 self.yaml2obj("aligned.yaml", exe) 44 target = self.dbg.CreateTarget(exe) 45 self.assertTrue(target, VALID_TARGET) 46 47 # exe contains a single section aligned to 0x1000 48 section = target.modules[0].sections[0] 49 self.assertEqual(section.GetAlignment(), 0x1000) 50 self.assertEqual(section.alignment, 0x1000) 51