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 VarInAggregateMisuseTestCase(TestBase):
12    def setUp(self):
13        # Call super's setUp().
14        TestBase.setUp(self)
15        # Find the line number to break at.
16        self.line = line_number("main.cpp", "// Set break point at this line.")
17
18    def test_with_run_command(self):
19        """Test that that file and class static variables display correctly."""
20        self.build()
21        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
22
23        lldbutil.run_break_set_by_file_and_line(
24            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True
25        )
26
27        self.runCmd("run", RUN_SUCCEEDED)
28
29        # The stop reason of the thread should be breakpoint.
30        self.expect(
31            "thread list",
32            STOPPED_DUE_TO_BREAKPOINT,
33            substrs=["stopped", "stop reason = breakpoint"],
34        )
35
36        # This is the function to remove the custom formats in order to have a
37        # clean slate for the next test case.
38        def cleanup():
39            self.runCmd("type summary clear", check=False)
40
41        # Execute the cleanup function during test case tear down.
42        self.addTearDownHook(cleanup)
43
44        self.runCmd(
45            'type summary add --summary-string "SUMMARY SUCCESS ${var}" Summarize'
46        )
47
48        self.expect(
49            "frame variable mine_ptr", substrs=["SUMMARY SUCCESS summarize_ptr_t @ "]
50        )
51
52        self.expect(
53            "frame variable *mine_ptr", substrs=["SUMMARY SUCCESS summarize_t @"]
54        )
55
56        self.runCmd(
57            'type summary add --summary-string "SUMMARY SUCCESS ${var.first}" Summarize'
58        )
59
60        self.expect("frame variable mine_ptr", substrs=["SUMMARY SUCCESS 10"])
61
62        self.expect("frame variable *mine_ptr", substrs=["SUMMARY SUCCESS 10"])
63
64        self.runCmd('type summary add --summary-string "${var}" Summarize')
65        self.runCmd('type summary add --summary-string "${var}" -e TwoSummarizes')
66
67        self.expect(
68            "frame variable",
69            substrs=[
70                "(TwoSummarizes) twos = TwoSummarizes @ ",
71                "first = summarize_t @ ",
72                "second = summarize_t @ ",
73            ],
74        )
75
76        self.runCmd(
77            'type summary add --summary-string "SUMMARY SUCCESS ${var.first}" Summarize'
78        )
79        self.expect(
80            "frame variable",
81            substrs=[
82                "(TwoSummarizes) twos = TwoSummarizes @ ",
83                "first = SUMMARY SUCCESS 1",
84                "second = SUMMARY SUCCESS 3",
85            ],
86        )
87