1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class Radar9974002DataFormatterTestCase(TestBase):
12
13    # test for rdar://problem/9974002 ()
14    mydir = os.path.join("functionalities", "data-formatter", "rdar-9974002")
15
16    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17    @dsym_test
18    def test_with_dsym_and_run_command(self):
19        """Test data formatter commands."""
20        self.buildDsym()
21        self.data_formatter_commands()
22
23    @dwarf_test
24    def test_with_dwarf_and_run_command(self):
25        """Test data formatter commands."""
26        self.buildDwarf()
27        self.data_formatter_commands()
28
29    def setUp(self):
30        # Call super's setUp().
31        TestBase.setUp(self)
32        # Find the line number to break at.
33        self.line = line_number('main.cpp', '// Set break point at this line.')
34
35    def data_formatter_commands(self):
36        """Test that that file and class static variables display correctly."""
37        if "clang" in self.getCompiler() and "3.4" in self.getCompilerVersion():
38            self.skipTest("llvm.org/pr16214 -- clang emits partial DWARF for structures referenced via typedef")
39
40        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
41
42        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
43
44        self.runCmd("run", RUN_SUCCEEDED)
45
46        # The stop reason of the thread should be breakpoint.
47        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
48            substrs = ['stopped',
49                       'stop reason = breakpoint'])
50
51        # This is the function to remove the custom formats in order to have a
52        # clean slate for the next test case.
53        def cleanup():
54            self.runCmd('type summary clear', check=False)
55
56        # Execute the cleanup function during test case tear down.
57        self.addTearDownHook(cleanup)
58
59        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer.first}\" container")
60
61        self.expect('frame variable mine',
62            substrs = ['mine = ',
63                       '1', '<parent is NULL>'])
64
65        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer}\" container")
66
67        self.expect('frame variable mine',
68                    substrs = ['mine = ',
69                               '1', '0x000000'])
70
71        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer%S}\" container")
72
73        self.expect('frame variable mine',
74                    substrs = ['mine = ',
75                               '1', '0x000000'])
76
77        self.runCmd("type summary add -s foo contained")
78
79        self.expect('frame variable mine',
80                    substrs = ['mine = ',
81                               '1', 'foo'])
82
83        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer}\" container")
84
85        self.expect('frame variable mine',
86                    substrs = ['mine = ',
87                               '1', 'foo'])
88
89        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer%V}\" container")
90
91        self.expect('frame variable mine',
92                    substrs = ['mine = ',
93                               '1', '0x000000'])
94
95        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer.first}\" container")
96
97        self.expect('frame variable mine',
98                    substrs = ['mine = ',
99                               '1', '<parent is NULL>'])
100
101        self.runCmd("type summary delete contained")
102        self.runCmd("n")
103
104        self.expect('frame variable mine',
105                    substrs = ['mine = ',
106                               '1', '<parent is NULL>'])
107
108        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer}\" container")
109
110        self.expect('frame variable mine',
111                    substrs = ['mine = ',
112                               '1', '0x000000'])
113
114        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer%S}\" container")
115
116        self.expect('frame variable mine',
117                    substrs = ['mine = ',
118                               '1', '0x000000'])
119
120        self.runCmd("type summary add -s foo contained")
121
122        self.expect('frame variable mine',
123                    substrs = ['mine = ',
124                               '1', 'foo'])
125
126        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer}\" container")
127
128        self.expect('frame variable mine',
129                    substrs = ['mine = ',
130                               '1', 'foo'])
131
132        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer%V}\" container")
133
134        self.expect('frame variable mine',
135                    substrs = ['mine = ',
136                               '1', '0x000000'])
137
138        self.runCmd("type summary add -s \"${var.scalar} and ${var.pointer.first}\" container")
139
140        self.expect('frame variable mine',
141                    substrs = ['mine = ',
142                               '1', '<parent is NULL>'])
143
144
145if __name__ == '__main__':
146    import atexit
147    lldb.SBDebugger.Initialize()
148    atexit.register(lambda: lldb.SBDebugger.Terminate())
149    unittest2.main()
150