1"""
2Test lldb data formatter subsystem.
3"""
4
5
6
7import lldb
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test.decorators import *
10import lldbsuite.test.lldbutil as lldbutil
11
12
13class GlobalsDataFormatterTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20        # Find the line number to break at.
21        self.line = line_number('main.cpp', '// Set break point at this line.')
22
23    def test_with_run_command(self):
24        """Test that that file and class static variables display correctly."""
25        self.build()
26        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
27
28        lldbutil.run_break_set_by_file_and_line(
29            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
30
31        # This is the function to remove the custom formats in order to have a
32        # clean slate for the next test case.
33        def cleanup():
34            self.runCmd('type format clear', check=False)
35            self.runCmd('type summary clear', check=False)
36
37        # Execute the cleanup function during test case tear down.
38        self.addTearDownHook(cleanup)
39
40        self.runCmd("type summary add --summary-string \"JustATest\" Point")
41
42        # Simply check we can get at global variables
43        self.expect("target variable g_point",
44                    substrs=['JustATest'])
45
46        self.expect("target variable g_point_pointer",
47                    substrs=['(Point *) g_point_pointer ='])
48
49        # Print some information about the variables
50        # (we ignore the actual values)
51        self.runCmd(
52            "type summary add --summary-string \"(x=${var.x},y=${var.y})\" Point")
53
54        self.expect("target variable g_point",
55                    substrs=['x=',
56                             'y='])
57
58        self.expect("target variable g_point_pointer",
59                    substrs=['(Point *) g_point_pointer ='])
60
61        # Test Python code on resulting SBValue
62        self.runCmd(
63            "type summary add --python-script \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point")
64
65        self.expect("target variable g_point",
66                    substrs=['x='])
67
68        self.expect("target variable g_point_pointer",
69                    substrs=['(Point *) g_point_pointer ='])
70