TestAppleTypesIsProduced.py revision 0cef6bad66d4cbbe4a01617b27be5b85a3134592
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(dot_o=True)
26
27    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
28    def test_debug_info_for_apple_types_dsym(self):
29        """Test that __apple_types section does get produced by dsymutil.
30           This is supposed to succeed even with rdar://problem/11166975."""
31
32        if not self.getCompiler().endswith('clang'):
33            self.skipTest("clang compiler only test")
34
35        self.buildDsym()
36        self.apple_types(dot_o=False)
37
38    def apple_types(self, dot_o):
39        """Test that __apple_types section does get produced by clang."""
40        if dot_o:
41            exe = os.path.join(os.getcwd(), "main.o")
42        else:
43            exe = os.path.join(os.getcwd(), "a.out.dSYM/Contents/Resources/DWARF/a.out")
44
45        target = self.dbg.CreateTarget(exe)
46        self.assertTrue(target, VALID_TARGET)
47        self.assertTrue(target.GetNumModules() > 0)
48
49        # Hide stdout if not running with '-t' option.
50        if not self.TraceOn():
51            self.HideStdout()
52
53        print "Number of modules for the target: %d" % target.GetNumModules()
54        for module in target.module_iter():
55            print module
56
57        # Get the executable module at index 0.
58        exe_module = target.GetModuleAtIndex(0)
59
60        dwarf_section = exe_module.FindSection("__DWARF")
61        self.assertTrue(dwarf_section)
62        print "__DWARF section:", dwarf_section
63        print "Number of sub-sections: %d" % dwarf_section.GetNumSubSections()
64        INDENT = ' ' * 4
65        for subsec in dwarf_section:
66            print INDENT + str(subsec)
67
68        debug_str_sub_section = dwarf_section.FindSubSection("__debug_str")
69        self.assertTrue(debug_str_sub_section)
70        print "__debug_str sub-section:", debug_str_sub_section
71
72        # Find our __apple_types section by name.
73        apple_types_sub_section = dwarf_section.FindSubSection("__apple_types")
74        self.assertTrue(apple_types_sub_section)
75        print "__apple_types sub-section:", apple_types_sub_section
76
77        # These other three all important subsections should also be present.
78        self.assertTrue(dwarf_section.FindSubSection("__apple_names") and
79                        dwarf_section.FindSubSection("__apple_namespac") and
80                        dwarf_section.FindSubSection("__apple_objc"))
81
82
83if __name__ == '__main__':
84    import atexit
85    lldb.SBDebugger.Initialize()
86    atexit.register(lambda: lldb.SBDebugger.Terminate())
87    unittest2.main()
88