1""" 2Test SBSection APIs. 3""" 4 5 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class SectionAPITestCase(TestBase): 12 @no_debug_info_test 13 @skipIfXmlSupportMissing 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 @no_debug_info_test 42 @skipIfXmlSupportMissing 43 def test_get_alignment(self): 44 exe = self.getBuildArtifact("aligned.out") 45 self.yaml2obj("aligned.yaml", exe) 46 target = self.dbg.CreateTarget(exe) 47 self.assertTrue(target, VALID_TARGET) 48 49 # exe contains a single section aligned to 0x1000 50 section = target.modules[0].sections[0] 51 self.assertEqual(section.GetAlignment(), 0x1000) 52 self.assertEqual(section.alignment, 0x1000) 53 54 @no_debug_info_test 55 @skipIfXmlSupportMissing 56 def test_compressed_section_data(self): 57 exe = self.getBuildArtifact("compressed-sections.out") 58 self.yaml2obj("compressed-sections.yaml", exe) 59 target = self.dbg.CreateTarget(exe) 60 self.assertTrue(target, VALID_TARGET) 61 62 # exe contains a single section with SHF_COMPRESSED. Check that 63 # GetSectionData returns the uncompressed data and not the raw contents 64 # of the section. 65 section = target.modules[0].sections[0] 66 section_data = section.GetSectionData().uint8s 67 self.assertEqual(section_data, [0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90]) 68