TestRdar11355592.py revision 6b1763b5ab8f182029807293d74a66e1e1c6bafd
1"""
2Test that we do not attempt to make a dynamic type for a 'const char*'
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
11class Rdar10967107TestCase(TestBase):
12
13    mydir = os.path.join("lang", "objc", "rdar-11355592")
14
15    @dsym_test
16    def test_charstar_dyntype_with_dsym(self):
17        """Test that we do not attempt to make a dynamic type for a 'const char*'"""
18        d = {'EXE': self.exe_name}
19        self.buildDsym(dictionary=d)
20        self.setTearDownCleanup(dictionary=d)
21        self.charstar_dyntype(self.exe_name)
22
23    @dwarf_test
24    def test_charstar_dyntype_with_dwarf(self):
25        """Test that we do not attempt to make a dynamic type for a 'const char*'"""
26        d = {'EXE': self.exe_name}
27        self.buildDwarf(dictionary=d)
28        self.setTearDownCleanup(dictionary=d)
29        self.charstar_dyntype(self.exe_name)
30
31    def setUp(self):
32        # Call super's setUp().
33        TestBase.setUp(self)
34        # We'll use the test method name as the exe_name.
35        self.exe_name = self.testMethodName
36        # Find the line number to break inside main().
37        self.main_source = "main.m"
38        self.line = line_number(self.main_source, '// Set breakpoint here.')
39
40    def charstar_dyntype(self, exe_name):
41        """Test that we do not attempt to make a dynamic type for a 'const char*'"""
42        exe = os.path.join(os.getcwd(), exe_name)
43        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
44
45        self.expect("breakpoint set -f %s -l %d" % (self.main_source, self.line),
46                    BREAKPOINT_CREATED,
47            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
48                        (self.main_source, self.line))
49
50        self.runCmd("run", RUN_SUCCEEDED)
51        # check that we correctly see the const char*, even with dynamic types on
52        self.expect("frame variable my_string", substrs = ['const char *'])
53        self.expect("frame variable my_string -d run-target", substrs = ['const char *'])
54        # check that expr also gets it right
55        self.expect("expr my_string", substrs = ['const char *'])
56        self.expect("expr -d true -- my_string", substrs = ['const char *'])
57        # but check that we get the real Foolie as such
58        self.expect("frame variable my_foolie", substrs = ['FoolMeOnce *'])
59        self.expect("frame variable my_foolie -d run-target", substrs = ['FoolMeOnce *'])
60        # check that expr also gets it right
61        self.expect("expr my_foolie", substrs = ['FoolMeOnce *'])
62        self.expect("expr -d true -- my_foolie", substrs = ['FoolMeOnce *'])
63        # now check that assigning a true string does not break anything
64        self.runCmd("next")
65        # check that we correctly see the const char*, even with dynamic types on
66        self.expect("frame variable my_string", substrs = ['const char *'])
67        self.expect("frame variable my_string -d run-target", substrs = ['const char *'])
68        # check that expr also gets it right
69        self.expect("expr my_string", substrs = ['const char *'])
70        self.expect("expr -d true -- my_string", substrs = ['const char *'])
71        # but check that we get the real Foolie as such
72        self.expect("frame variable my_foolie", substrs = ['FoolMeOnce *'])
73        self.expect("frame variable my_foolie -d run-target", substrs = ['FoolMeOnce *'])
74        # check that expr also gets it right
75        self.expect("expr my_foolie", substrs = ['FoolMeOnce *'])
76        self.expect("expr -d true -- my_foolie", substrs = ['FoolMeOnce *'])
77
78if __name__ == '__main__':
79    import atexit
80    lldb.SBDebugger.Initialize()
81    atexit.register(lambda: lldb.SBDebugger.Terminate())
82    unittest2.main()
83