199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest SBSection APIs. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtclass SectionAPITestCase(TestBase): 1399451b44SJordan Rupprecht 1499451b44SJordan Rupprecht def test_get_target_byte_size(self): 1599451b44SJordan Rupprecht d = {'EXE': 'b.out'} 1699451b44SJordan Rupprecht self.build(dictionary=d) 1799451b44SJordan Rupprecht self.setTearDownCleanup(dictionary=d) 1899451b44SJordan Rupprecht exe = self.getBuildArtifact('b.out') 1999451b44SJordan Rupprecht target = self.dbg.CreateTarget(exe) 2099451b44SJordan Rupprecht self.assertTrue(target, VALID_TARGET) 2199451b44SJordan Rupprecht 2299451b44SJordan Rupprecht # find the .data section of the main module 2399451b44SJordan Rupprecht mod = target.GetModuleAtIndex(0) 2499451b44SJordan Rupprecht data_section = None 2599451b44SJordan Rupprecht for s in mod.sections: 2699451b44SJordan Rupprecht sect_type = s.GetSectionType() 2799451b44SJordan Rupprecht if sect_type == lldb.eSectionTypeData: 2899451b44SJordan Rupprecht data_section = s 2999451b44SJordan Rupprecht break 3099451b44SJordan Rupprecht elif sect_type == lldb.eSectionTypeContainer: 3199451b44SJordan Rupprecht for i in range(s.GetNumSubSections()): 3299451b44SJordan Rupprecht ss = s.GetSubSectionAtIndex(i) 3399451b44SJordan Rupprecht sect_type = ss.GetSectionType() 3499451b44SJordan Rupprecht if sect_type == lldb.eSectionTypeData: 3599451b44SJordan Rupprecht data_section = ss 3699451b44SJordan Rupprecht break 3799451b44SJordan Rupprecht 3899451b44SJordan Rupprecht self.assertIsNotNone(data_section) 3999451b44SJordan Rupprecht self.assertEqual(data_section.target_byte_size, 1) 40*1e3ee766SDavid M. Lary 41*1e3ee766SDavid M. Lary def test_get_alignment(self): 42*1e3ee766SDavid M. Lary exe = self.getBuildArtifact("aligned.out") 43*1e3ee766SDavid M. Lary self.yaml2obj("aligned.yaml", exe) 44*1e3ee766SDavid M. Lary target = self.dbg.CreateTarget(exe) 45*1e3ee766SDavid M. Lary self.assertTrue(target, VALID_TARGET) 46*1e3ee766SDavid M. Lary 47*1e3ee766SDavid M. Lary # exe contains a single section aligned to 0x1000 48*1e3ee766SDavid M. Lary section = target.modules[0].sections[0] 49*1e3ee766SDavid M. Lary self.assertEqual(section.GetAlignment(), 0x1000) 50*1e3ee766SDavid M. Lary self.assertEqual(section.alignment, 0x1000) 51