1"""
2Test lldb data formatter subsystem.
3"""
4
5
6
7import lldb
8from lldbsuite.test.lldbtest import *
9import lldbsuite.test.lldbutil as lldbutil
10
11
12class PtrToArrayDataFormatterTestCase(TestBase):
13
14    def test_with_run_command(self):
15        """Test that LLDB handles the clang typeclass Paren correctly."""
16        self.build()
17        self.data_formatter_commands()
18
19    def setUp(self):
20        # Call super's setUp().
21        TestBase.setUp(self)
22        # Find the line number to break at.
23        self.line = line_number('main.cpp', '// Set break point at this line.')
24
25    def data_formatter_commands(self):
26        """Test that LLDB handles the clang typeclass Paren correctly."""
27        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
28
29        lldbutil.run_break_set_by_file_and_line(
30            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
31
32        self.runCmd("run", RUN_SUCCEEDED)
33
34        # The stop reason of the thread should be breakpoint.
35        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
36                    substrs=['stopped',
37                             'stop reason = breakpoint'])
38
39        # This is the function to remove the custom formats in order to have a
40        # clean slate for the next test case.
41        def cleanup():
42            self.runCmd('type format delete hex', check=False)
43            self.runCmd('type summary clear', check=False)
44
45        # Execute the cleanup function during test case tear down.
46        self.addTearDownHook(cleanup)
47
48        self.expect('p *(int (*)[3])foo',
49                    substrs=['(int[3]) $', '[0] = 1', '[1] = 2', '[2] = 3'])
50
51        self.expect('p *(int (*)[3])foo', matching=False,
52                    substrs=['01 00 00 00 02 00 00 00 03 00 00 00'])
53        self.expect('p *(int (*)[3])foo', matching=False,
54                    substrs=['0x000000030000000200000001'])
55