1"""
2Test lldb data formatter subsystem.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class DataFormatterVarScriptFormatting(TestBase):
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18        # Find the line number to break at.
19        self.line = line_number('main.cpp', ' // Set breakpoint here.')
20
21    def test_with_run_command(self):
22        """Test using Python synthetic children provider."""
23        self.build()
24        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
25
26        lldbutil.run_break_set_by_file_and_line(
27            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
28
29        self.runCmd("run", RUN_SUCCEEDED)
30
31        # The stop reason of the thread should be breakpoint.
32        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
33                    substrs=['stopped',
34                             'stop reason = breakpoint'])
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 format clear', check=False)
40            self.runCmd('type summary clear', check=False)
41            self.runCmd('type filter clear', check=False)
42            self.runCmd('type synth clear', check=False)
43
44        # Execute the cleanup function during test case tear down.
45        self.addTearDownHook(cleanup)
46
47        self.runCmd("command script import helperfunc.py")
48        self.runCmd(
49            'type summary add -x "^something<.*>$" -s "T is a ${script.var:helperfunc.f}"')
50
51        self.expect("frame variable x", substrs=['T is a non-pointer type'])
52
53        self.expect("frame variable y", substrs=['T is a pointer type'])
54