Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test SBSection APIs. |
| 3 | """ |
| 4 | |
| 5 | import unittest2 |
| 6 | from lldbtest import * |
| 7 | |
| 8 | class SectionAPITestCase(TestBase): |
| 9 | |
| 10 | mydir = TestBase.compute_mydir(__file__) |
| 11 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 12 | @skipUnlessDarwin |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 13 | @python_api_test |
| 14 | @dsym_test |
| 15 | def test_get_target_byte_size_with_dsym(self): |
| 16 | d = {'EXE': 'a.out'} |
| 17 | self.buildDsym(dictionary=d) |
| 18 | self.setTearDownCleanup(dictionary=d) |
| 19 | target = self.create_simple_target('a.out') |
| 20 | |
| 21 | # find the .data section of the main module |
| 22 | data_section = self.find_data_section(target) |
| 23 | |
| 24 | self.assertEquals(data_section.target_byte_size, 1) |
| 25 | |
| 26 | @python_api_test |
| 27 | @dwarf_test |
| 28 | def test_get_target_byte_size_with_dwarf(self): |
| 29 | d = {'EXE': 'b.out'} |
| 30 | self.buildDwarf(dictionary=d) |
| 31 | self.setTearDownCleanup(dictionary=d) |
| 32 | target = self.create_simple_target('b.out') |
| 33 | |
| 34 | # find the .data section of the main module |
| 35 | data_section = self.find_data_section(target) |
| 36 | |
| 37 | self.assertEquals(data_section.target_byte_size, 1) |
| 38 | |
| 39 | def create_simple_target(self, fn): |
| 40 | exe = os.path.join(os.getcwd(), fn) |
| 41 | target = self.dbg.CreateTarget(exe) |
| 42 | self.assertTrue(target, VALID_TARGET) |
| 43 | return target |
| 44 | |
| 45 | def find_data_section(self, target): |
| 46 | mod = target.GetModuleAtIndex(0) |
| 47 | data_section = None |
| 48 | for s in mod.sections: |
Greg Clayton | ed59d75 | 2014-11-03 23:02:08 +0000 | [diff] [blame] | 49 | sect_type = s.GetSectionType() |
| 50 | if sect_type == lldb.eSectionTypeData: |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 51 | data_section = s |
| 52 | break |
Greg Clayton | ed59d75 | 2014-11-03 23:02:08 +0000 | [diff] [blame] | 53 | elif sect_type == lldb.eSectionTypeContainer: |
| 54 | for i in range(s.GetNumSubSections()): |
| 55 | ss = s.GetSubSectionAtIndex(i) |
| 56 | sect_type = ss.GetSectionType() |
| 57 | if sect_type == lldb.eSectionTypeData: |
| 58 | data_section = ss |
| 59 | break |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 60 | |
| 61 | self.assertIsNotNone(data_section) |
| 62 | return data_section |
Greg Clayton | ed59d75 | 2014-11-03 23:02:08 +0000 | [diff] [blame] | 63 | |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 64 | |
| 65 | if __name__ == '__main__': |
| 66 | import atexit |
| 67 | lldb.SBDebugger.Initialize() |
| 68 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 69 | unittest2.main() |