blob: 6c7b4f53ea777bc75b9ed5666ddf89f701807f9d [file] [log] [blame]
Matthew Gardinerc928de32014-10-22 07:22:56 +00001"""
2Test SBSection APIs.
3"""
4
5import unittest2
6from lldbtest import *
7
8class SectionAPITestCase(TestBase):
9
10 mydir = TestBase.compute_mydir(__file__)
11
Robert Flack13c7ad92015-03-30 14:12:17 +000012 @skipUnlessDarwin
Matthew Gardinerc928de32014-10-22 07:22:56 +000013 @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 Claytoned59d752014-11-03 23:02:08 +000049 sect_type = s.GetSectionType()
50 if sect_type == lldb.eSectionTypeData:
Matthew Gardinerc928de32014-10-22 07:22:56 +000051 data_section = s
52 break
Greg Claytoned59d752014-11-03 23:02:08 +000053 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 Gardinerc928de32014-10-22 07:22:56 +000060
61 self.assertIsNotNone(data_section)
62 return data_section
Greg Claytoned59d752014-11-03 23:02:08 +000063
Matthew Gardinerc928de32014-10-22 07:22:56 +000064
65if __name__ == '__main__':
66 import atexit
67 lldb.SBDebugger.Initialize()
68 atexit.register(lambda: lldb.SBDebugger.Terminate())
69 unittest2.main()