199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest lldb data formatter subsystem. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprechtimport lldb 799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtclass PrintArrayTestCase(TestBase): 1399451b44SJordan Rupprecht def test_print_array(self): 1499451b44SJordan Rupprecht """Test that expr -Z works""" 1599451b44SJordan Rupprecht self.build() 1699451b44SJordan Rupprecht self.printarray_data_formatter_commands() 1799451b44SJordan Rupprecht 1899451b44SJordan Rupprecht def setUp(self): 1999451b44SJordan Rupprecht # Call super's setUp(). 2099451b44SJordan Rupprecht TestBase.setUp(self) 2199451b44SJordan Rupprecht # Find the line number to break at. 22*2238dcc3SJonas Devlieghere self.line = line_number("main.cpp", "break here") 2399451b44SJordan Rupprecht 2499451b44SJordan Rupprecht def printarray_data_formatter_commands(self): 2599451b44SJordan Rupprecht """Test that expr -Z works""" 2699451b44SJordan Rupprecht self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 2799451b44SJordan Rupprecht 2899451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 29*2238dcc3SJonas Devlieghere self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True 30*2238dcc3SJonas Devlieghere ) 3199451b44SJordan Rupprecht 3299451b44SJordan Rupprecht self.runCmd("run", RUN_SUCCEEDED) 3399451b44SJordan Rupprecht 3499451b44SJordan Rupprecht # The stop reason of the thread should be breakpoint. 35*2238dcc3SJonas Devlieghere self.expect( 36*2238dcc3SJonas Devlieghere "thread list", 37*2238dcc3SJonas Devlieghere STOPPED_DUE_TO_BREAKPOINT, 38*2238dcc3SJonas Devlieghere substrs=["stopped", "stop reason = breakpoint"], 39*2238dcc3SJonas Devlieghere ) 4099451b44SJordan Rupprecht 4199451b44SJordan Rupprecht # This is the function to remove the custom formats in order to have a 4299451b44SJordan Rupprecht # clean slate for the next test case. 4399451b44SJordan Rupprecht def cleanup(): 44*2238dcc3SJonas Devlieghere self.runCmd("type format clear", check=False) 45*2238dcc3SJonas Devlieghere self.runCmd("type summary clear", check=False) 46*2238dcc3SJonas Devlieghere self.runCmd("type synth clear", check=False) 4799451b44SJordan Rupprecht 4899451b44SJordan Rupprecht # Execute the cleanup function during test case tear down. 4999451b44SJordan Rupprecht self.addTearDownHook(cleanup) 5099451b44SJordan Rupprecht 5199451b44SJordan Rupprecht self.expect( 52*2238dcc3SJonas Devlieghere "expr --element-count 3 -- data", substrs=["[0] = 1", "[1] = 3", "[2] = 5"] 53*2238dcc3SJonas Devlieghere ) 54*2238dcc3SJonas Devlieghere self.expect("expr data", substrs=["int *", "$", "0x"]) 5599451b44SJordan Rupprecht self.expect( 56*2238dcc3SJonas Devlieghere "expr -f binary --element-count 0 -- data", substrs=["int *", "$", "0b"] 57*2238dcc3SJonas Devlieghere ) 5899451b44SJordan Rupprecht self.expect( 59*2238dcc3SJonas Devlieghere "expr -f hex --element-count 3 -- data", 60*2238dcc3SJonas Devlieghere substrs=["[0] = 0x", "1", "[1] = 0x", "3", "[2] = 0x", "5"], 61*2238dcc3SJonas Devlieghere ) 6299451b44SJordan Rupprecht self.expect( 63*2238dcc3SJonas Devlieghere "expr -f binary --element-count 2 -- data", 64*2238dcc3SJonas Devlieghere substrs=["int *", "$", "0x", "[0] = 0b", "1", "[1] = 0b", "11"], 65*2238dcc3SJonas Devlieghere ) 66*2238dcc3SJonas Devlieghere self.expect("parray 3 data", substrs=["[0] = 1", "[1] = 3", "[2] = 5"]) 6799451b44SJordan Rupprecht self.expect( 68*2238dcc3SJonas Devlieghere "parray `1 + 1 + 1` data", substrs=["[0] = 1", "[1] = 3", "[2] = 5"] 69*2238dcc3SJonas Devlieghere ) 70*2238dcc3SJonas Devlieghere self.expect("parray `data[1]` data", substrs=["[0] = 1", "[1] = 3", "[2] = 5"]) 7199451b44SJordan Rupprecht self.expect( 72*2238dcc3SJonas Devlieghere "parray/x 3 data", 73*2238dcc3SJonas Devlieghere substrs=["[0] = 0x", "1", "[1] = 0x", "3", "[2] = 0x", "5"], 74*2238dcc3SJonas Devlieghere ) 7599451b44SJordan Rupprecht self.expect( 76*2238dcc3SJonas Devlieghere "parray/x `data[1]` data", 77*2238dcc3SJonas Devlieghere substrs=["[0] = 0x", "1", "[1] = 0x", "3", "[2] = 0x", "5"], 78*2238dcc3SJonas Devlieghere ) 7999451b44SJordan Rupprecht 8099451b44SJordan Rupprecht # check error conditions 8199451b44SJordan Rupprecht self.expect( 82*2238dcc3SJonas Devlieghere "expr --element-count 10 -- 123", 8399451b44SJordan Rupprecht error=True, 84*2238dcc3SJonas Devlieghere substrs=[ 85*2238dcc3SJonas Devlieghere "expression cannot be used with --element-count as it does not refer to a pointer" 86*2238dcc3SJonas Devlieghere ], 87*2238dcc3SJonas Devlieghere ) 8899451b44SJordan Rupprecht self.expect( 89*2238dcc3SJonas Devlieghere "expr --element-count 10 -- (void*)123", 9099451b44SJordan Rupprecht error=True, 91*2238dcc3SJonas Devlieghere substrs=[ 92*2238dcc3SJonas Devlieghere "expression cannot be used with --element-count as it refers to a pointer to void" 93*2238dcc3SJonas Devlieghere ], 94*2238dcc3SJonas Devlieghere ) 95*2238dcc3SJonas Devlieghere self.expect("parray data", error=True, substrs=["invalid element count 'data'"]) 9699451b44SJordan Rupprecht self.expect( 97*2238dcc3SJonas Devlieghere "parray data data", error=True, substrs=["invalid element count 'data'"] 98*2238dcc3SJonas Devlieghere ) 99*2238dcc3SJonas Devlieghere self.expect("parray", error=True, substrs=["Not enough arguments provided"]) 100