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