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    @skipIf(debug_info="gmodules",
24            bugnumber="https://bugs.llvm.org/show_bug.cgi?id=36048")
25    def test_with_run_command(self):
26        """Test that that file and class static variables display correctly."""
27        self.build()
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        # This is the function to remove the custom formats in order to have a
34        # clean slate for the next test case.
35        def cleanup():
36            self.runCmd('type format clear', check=False)
37            self.runCmd('type summary clear', check=False)
38
39        # Execute the cleanup function during test case tear down.
40        self.addTearDownHook(cleanup)
41
42        self.runCmd("type summary add --summary-string \"JustATest\" Point")
43
44        # Simply check we can get at global variables
45        self.expect("target variable g_point",
46                    substrs=['JustATest'])
47
48        self.expect("target variable g_point_pointer",
49                    substrs=['(Point *) g_point_pointer ='])
50
51        # Print some information about the variables
52        # (we ignore the actual values)
53        self.runCmd(
54            "type summary add --summary-string \"(x=${var.x},y=${var.y})\" Point")
55
56        self.expect("target variable g_point",
57                    substrs=['x=',
58                             'y='])
59
60        self.expect("target variable g_point_pointer",
61                    substrs=['(Point *) g_point_pointer ='])
62
63        # Test Python code on resulting SBValue
64        self.runCmd(
65            "type summary add --python-script \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point")
66
67        self.expect("target variable g_point",
68                    substrs=['x='])
69
70        self.expect("target variable g_point_pointer",
71                    substrs=['(Point *) g_point_pointer ='])
72