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 PtrToArrayDataFormatterTestCase(TestBase):
12    def test_with_run_command(self):
13        """Test that LLDB handles the clang typeclass Paren correctly."""
14        self.build()
15        self.data_formatter_commands()
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 data_formatter_commands(self):
24        """Test that LLDB handles the clang typeclass Paren correctly."""
25        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
26
27        lldbutil.run_break_set_by_file_and_line(
28            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True
29        )
30
31        self.runCmd("run", RUN_SUCCEEDED)
32
33        # The stop reason of the thread should be breakpoint.
34        self.expect(
35            "thread list",
36            STOPPED_DUE_TO_BREAKPOINT,
37            substrs=["stopped", "stop reason = breakpoint"],
38        )
39
40        # This is the function to remove the custom formats in order to have a
41        # clean slate for the next test case.
42        def cleanup():
43            self.runCmd("type format delete hex", check=False)
44            self.runCmd("type summary clear", check=False)
45
46        # Execute the cleanup function during test case tear down.
47        self.addTearDownHook(cleanup)
48
49        self.expect(
50            "expression *(int (*)[3])foo",
51            substrs=["(int[3]) $", "[0] = 1", "[1] = 2", "[2] = 3"],
52        )
53
54        self.expect(
55            "expression *(int (*)[3])foo",
56            matching=False,
57            substrs=["01 00 00 00 02 00 00 00 03 00 00 00"],
58        )
59        self.expect(
60            "expression *(int (*)[3])foo",
61            matching=False,
62            substrs=["0x000000030000000200000001"],
63        )
64