TestAppleTypesIsProduced.py revision 4eb1453a5273e432a706ca69d9e91fb678170aff
1"""
2Test that clang produces the __apple accelerator tables, for example, __apple_types, correctly.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9from lldbutil import symbol_type_to_str
10
11class AppleTypesTestCase(TestBase):
12
13    mydir = os.path.join("macosx", "debug-info", "apple_types")
14
15    #rdar://problem/11166975
16    @unittest2.expectedFailure
17    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
18    def test_debug_info_for_apple_types(self):
19        """Test that __apple_types section does get produced by clang."""
20
21        if not self.getCompiler().endswith('clang'):
22            self.skipTest("clang compiler only test")
23
24        self.buildDefault()
25        self.apple_types()
26
27    def apple_types(self):
28        """Test that __apple_types section does get produced by clang."""
29        exe = os.path.join(os.getcwd(), "main.o")
30
31        target = self.dbg.CreateTarget(exe)
32        self.assertTrue(target, VALID_TARGET)
33        self.assertTrue(target.GetNumModules() > 0)
34
35        # Hide stdout if not running with '-t' option.
36        if not self.TraceOn():
37            self.HideStdout()
38
39        print "Number of modules for the target: %d" % target.GetNumModules()
40        for module in target.module_iter():
41            print module
42
43        # Get the executable module at index 0.
44        exe_module = target.GetModuleAtIndex(0)
45
46        dwarf_section = exe_module.FindSection("__DWARF")
47        self.assertTrue(dwarf_section)
48        print "__DWARF section:", dwarf_section
49        print "Number of sub-sections: %d" % dwarf_section.GetNumSubSections()
50        INDENT = ' ' * 4
51        for subsec in dwarf_section:
52            print INDENT + str(subsec)
53
54        debug_str_sub_section = dwarf_section.FindSubSection("__debug_str")
55        self.assertTrue(debug_str_sub_section)
56        print "__debug_str sub-section:", debug_str_sub_section
57
58        # Find our __apple_types section by name.
59        apple_types_sub_section = dwarf_section.FindSubSection("__apple_types")
60        self.assertTrue(apple_types_sub_section)
61        print "__apple_types sub-section:", apple_types_sub_section
62
63
64if __name__ == '__main__':
65    import atexit
66    lldb.SBDebugger.Initialize()
67    atexit.register(lambda: lldb.SBDebugger.Terminate())
68    unittest2.main()
69