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