xref: /llvm-project/lldb/test/API/python_api/section/TestSectionAPI.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest SBSection APIs.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
799451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
899451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprechtclass SectionAPITestCase(TestBase):
12bde5d31eSMuhammad Omair Javaid    @no_debug_info_test
13bde5d31eSMuhammad Omair Javaid    @skipIfXmlSupportMissing
1499451b44SJordan Rupprecht    def test_get_target_byte_size(self):
15*2238dcc3SJonas Devlieghere        d = {"EXE": "b.out"}
1699451b44SJordan Rupprecht        self.build(dictionary=d)
1799451b44SJordan Rupprecht        self.setTearDownCleanup(dictionary=d)
18*2238dcc3SJonas Devlieghere        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)
401e3ee766SDavid M. Lary
41bde5d31eSMuhammad Omair Javaid    @no_debug_info_test
42bde5d31eSMuhammad Omair Javaid    @skipIfXmlSupportMissing
431e3ee766SDavid M. Lary    def test_get_alignment(self):
441e3ee766SDavid M. Lary        exe = self.getBuildArtifact("aligned.out")
451e3ee766SDavid M. Lary        self.yaml2obj("aligned.yaml", exe)
461e3ee766SDavid M. Lary        target = self.dbg.CreateTarget(exe)
471e3ee766SDavid M. Lary        self.assertTrue(target, VALID_TARGET)
481e3ee766SDavid M. Lary
491e3ee766SDavid M. Lary        # exe contains a single section aligned to 0x1000
501e3ee766SDavid M. Lary        section = target.modules[0].sections[0]
511e3ee766SDavid M. Lary        self.assertEqual(section.GetAlignment(), 0x1000)
521e3ee766SDavid M. Lary        self.assertEqual(section.alignment, 0x1000)
53bde5d31eSMuhammad Omair Javaid
54bde5d31eSMuhammad Omair Javaid    @no_debug_info_test
55bde5d31eSMuhammad Omair Javaid    @skipIfXmlSupportMissing
56bde5d31eSMuhammad Omair Javaid    def test_compressed_section_data(self):
57bde5d31eSMuhammad Omair Javaid        exe = self.getBuildArtifact("compressed-sections.out")
58bde5d31eSMuhammad Omair Javaid        self.yaml2obj("compressed-sections.yaml", exe)
59bde5d31eSMuhammad Omair Javaid        target = self.dbg.CreateTarget(exe)
60bde5d31eSMuhammad Omair Javaid        self.assertTrue(target, VALID_TARGET)
61bde5d31eSMuhammad Omair Javaid
62bde5d31eSMuhammad Omair Javaid        # exe contains a single section with SHF_COMPRESSED. Check that
63bde5d31eSMuhammad Omair Javaid        # GetSectionData returns the uncompressed data and not the raw contents
64bde5d31eSMuhammad Omair Javaid        # of the section.
65bde5d31eSMuhammad Omair Javaid        section = target.modules[0].sections[0]
66bde5d31eSMuhammad Omair Javaid        section_data = section.GetSectionData().uint8s
67*2238dcc3SJonas Devlieghere        self.assertEqual(section_data, [0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90])
68