brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · b874a78 Raw
68 lines · python
1"""2Test SBSection APIs.3"""4 5 6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11class SectionAPITestCase(TestBase):12    @no_debug_info_test13    @skipIfXmlSupportMissing14    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 module23        mod = target.GetModuleAtIndex(0)24        data_section = None25        for s in mod.sections:26            sect_type = s.GetSectionType()27            if sect_type == lldb.eSectionTypeData:28                data_section = s29                break30            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 = ss36                        break37 38        self.assertIsNotNone(data_section)39        self.assertEqual(data_section.target_byte_size, 1)40 41    @no_debug_info_test42    @skipIfXmlSupportMissing43    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 0x100050        section = target.modules[0].sections[0]51        self.assertEqual(section.GetAlignment(), 0x1000)52        self.assertEqual(section.alignment, 0x1000)53 54    @no_debug_info_test55    @skipIfXmlSupportMissing56    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 that63        # GetSectionData returns the uncompressed data and not the raw contents64        # of the section.65        section = target.modules[0].sections[0]66        section_data = section.GetSectionData().uint8s67        self.assertEqual(section_data, [0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90])68