2 Test lldb data formatter subsystem.
5 from __future__ import print_function
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
16 class PrintArrayTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
20 def test_print_array(self):
21 """Test that expr -Z works"""
23 self.printarray_data_formatter_commands()
26 # Call super's setUp().
28 # Find the line number to break at.
29 self.line = line_number('main.cpp', 'break here')
31 def printarray_data_formatter_commands(self):
32 """Test that expr -Z works"""
33 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
35 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
37 self.runCmd("run", RUN_SUCCEEDED)
39 # The stop reason of the thread should be breakpoint.
40 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
42 'stop reason = breakpoint'])
44 # This is the function to remove the custom formats in order to have a
45 # clean slate for the next test case.
47 self.runCmd('type format clear', check=False)
48 self.runCmd('type summary clear', check=False)
49 self.runCmd('type synth clear', check=False)
51 # Execute the cleanup function during test case tear down.
52 self.addTearDownHook(cleanup)
54 self.expect('expr --element-count 3 -- data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
55 self.expect('expr data', substrs=['int *', '$', '0x'])
56 self.expect('expr -f binary --element-count 0 -- data', substrs=['int *', '$', '0b'])
57 self.expect('expr -f hex --element-count 3 -- data', substrs=['[0] = 0x', '1', '[1] = 0x', '3', '[2] = 0x', '5'])
58 self.expect('expr -f binary --element-count 2 -- data', substrs=['int *', '$', '0x', '[0] = 0b', '1', '[1] = 0b', '11'])
59 self.expect('parray 3 data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
60 self.expect('parray `1 + 1 + 1` data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
61 self.expect('parray `data[1]` data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
62 self.expect('parray/x 3 data', substrs=['[0] = 0x', '1', '[1] = 0x', '3', '[2] = 0x', '5'])
63 self.expect('parray/x `data[1]` data', substrs=['[0] = 0x', '1', '[1] = 0x', '3', '[2] = 0x', '5'])
65 # check error conditions
66 self.expect('expr --element-count 10 -- 123', error=True, substrs=['expression cannot be used with --element-count as it does not refer to a pointer'])
67 self.expect('expr --element-count 10 -- (void*)123', error=True, substrs=['expression cannot be used with --element-count as it refers to a pointer to void'])
68 self.expect('parray data', error=True, substrs=["invalid element count 'data'"])
69 self.expect('parray data data', error=True, substrs=["invalid element count 'data'"])
70 self.expect('parray', error=True, substrs=['Not enough arguments provided'])