• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PrintObjectArrayTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    @skipUnlessDarwin
18    def test_print_array(self):
19        """Test that expr -O -Z works"""
20        self.build()
21        self.printarray_data_formatter_commands()
22
23    def setUp(self):
24        # Call super's setUp().
25        TestBase.setUp(self)
26        # Find the line number to break at.
27        self.line = line_number('main.mm', 'break here')
28
29    def printarray_data_formatter_commands(self):
30        """Test that expr -O -Z works"""
31        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
32
33        lldbutil.run_break_set_by_file_and_line(
34            self, "main.mm", self.line, num_expected_locations=1, loc_exact=True)
35
36        self.runCmd("run", RUN_SUCCEEDED)
37
38        # The stop reason of the thread should be breakpoint.
39        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
40                    substrs=['stopped',
41                             'stop reason = breakpoint'])
42
43        # This is the function to remove the custom formats in order to have a
44        # clean slate for the next test case.
45        def cleanup():
46            self.runCmd('type format clear', check=False)
47            self.runCmd('type summary clear', check=False)
48            self.runCmd('type synth clear', check=False)
49
50        # Execute the cleanup function during test case tear down.
51        self.addTearDownHook(cleanup)
52
53        self.expect(
54            'expr --element-count 3 --object-description -- objects',
55            substrs=[
56                '3735928559',
57                '4276993775',
58                '3203398366',
59                'Hello',
60                'World',
61                'Two =',
62                '1 ='])
63        self.expect(
64            'poarray 3 objects',
65            substrs=[
66                '3735928559',
67                '4276993775',
68                '3203398366',
69                'Hello',
70                'World',
71                'Two =',
72                '1 ='])
73        self.expect(
74            'expr --element-count 3 --object-description --description-verbosity=full -- objects',
75            substrs=[
76                '[0] =',
77                '3735928559',
78                '4276993775',
79                '3203398366',
80                '[1] =',
81                'Hello',
82                'World',
83                '[2] =',
84                'Two =',
85                '1 ='])
86        self.expect(
87            'parray 3 objects',
88            substrs=[
89                '[0] = 0x',
90                '[1] = 0x',
91                '[2] = 0x'])
92        self.expect(
93            'expr --element-count 3 -d run -- objects',
94            substrs=[
95                '3 elements',
96                '2 elements',
97                '2 key/value pairs'])
98        self.expect(
99            'expr --element-count 3 -d run --ptr-depth=1 -- objects',
100            substrs=[
101                '3 elements',
102                '3735928559',
103                '4276993775',
104                '3203398366',
105                '2 elements',
106                '"Hello"',
107                '"World"',
108                '2 key/value pairs',
109            ])
110