199451b44SJordan Rupprecht"""Test settings and readings of program variables.""" 299451b44SJordan Rupprecht 399451b44SJordan Rupprecht 499451b44SJordan Rupprechtimport lldb 599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 899451b44SJordan Rupprecht 999451b44SJordan Rupprecht 1099451b44SJordan Rupprechtclass SetValuesTestCase(TestBase): 1199451b44SJordan Rupprecht def setUp(self): 1299451b44SJordan Rupprecht # Call super's setUp(). 1399451b44SJordan Rupprecht TestBase.setUp(self) 1499451b44SJordan Rupprecht # Find the line numbers to break inside main(). 15*2238dcc3SJonas Devlieghere self.line1 = line_number("main.c", "// Set break point #1.") 16*2238dcc3SJonas Devlieghere self.line2 = line_number("main.c", "// Set break point #2.") 17*2238dcc3SJonas Devlieghere self.line3 = line_number("main.c", "// Set break point #3.") 18*2238dcc3SJonas Devlieghere self.line4 = line_number("main.c", "// Set break point #4.") 19*2238dcc3SJonas Devlieghere self.line5 = line_number("main.c", "// Set break point #5.") 2099451b44SJordan Rupprecht 2199451b44SJordan Rupprecht def test(self): 2299451b44SJordan Rupprecht """Test settings and readings of program variables.""" 2399451b44SJordan Rupprecht self.build() 2499451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 2599451b44SJordan Rupprecht self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 2699451b44SJordan Rupprecht 2799451b44SJordan Rupprecht # Set breakpoints on several places to set program variables. 2899451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 29*2238dcc3SJonas Devlieghere self, "main.c", self.line1, num_expected_locations=1, loc_exact=True 30*2238dcc3SJonas Devlieghere ) 3199451b44SJordan Rupprecht 3299451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 33*2238dcc3SJonas Devlieghere self, "main.c", self.line2, num_expected_locations=1, loc_exact=True 34*2238dcc3SJonas Devlieghere ) 3599451b44SJordan Rupprecht 3699451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 37*2238dcc3SJonas Devlieghere self, "main.c", self.line3, num_expected_locations=1, loc_exact=True 38*2238dcc3SJonas Devlieghere ) 3999451b44SJordan Rupprecht 4099451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 41*2238dcc3SJonas Devlieghere self, "main.c", self.line4, num_expected_locations=1, loc_exact=True 42*2238dcc3SJonas Devlieghere ) 4399451b44SJordan Rupprecht 4499451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 45*2238dcc3SJonas Devlieghere self, "main.c", self.line5, num_expected_locations=1, loc_exact=True 46*2238dcc3SJonas Devlieghere ) 4799451b44SJordan Rupprecht 4899451b44SJordan Rupprecht self.runCmd("run", RUN_SUCCEEDED) 4999451b44SJordan Rupprecht 5099451b44SJordan Rupprecht # The stop reason of the thread should be breakpoint. 51*2238dcc3SJonas Devlieghere self.expect( 52*2238dcc3SJonas Devlieghere "thread list", 53*2238dcc3SJonas Devlieghere STOPPED_DUE_TO_BREAKPOINT, 54*2238dcc3SJonas Devlieghere substrs=["stopped", "stop reason = breakpoint"], 55*2238dcc3SJonas Devlieghere ) 5699451b44SJordan Rupprecht 5799451b44SJordan Rupprecht # The breakpoint should have a hit count of 1. 589f0b5f9aSSYNOPSYS\georgiev lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1) 5999451b44SJordan Rupprecht 6099451b44SJordan Rupprecht # main.c:15 6199451b44SJordan Rupprecht # Check that 'frame variable --show-types' displays the correct data 6299451b44SJordan Rupprecht # type and value. 6399451b44SJordan Rupprecht self.expect( 6499451b44SJordan Rupprecht "frame variable --show-types", 6599451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 66*2238dcc3SJonas Devlieghere startstr="(char) i = 'a'", 67*2238dcc3SJonas Devlieghere ) 6899451b44SJordan Rupprecht 6999451b44SJordan Rupprecht # Now set variable 'i' and check that it is correctly displayed. 7099451b44SJordan Rupprecht self.runCmd("expression i = 'b'") 7199451b44SJordan Rupprecht self.expect( 7299451b44SJordan Rupprecht "frame variable --show-types", 7399451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 74*2238dcc3SJonas Devlieghere startstr="(char) i = 'b'", 75*2238dcc3SJonas Devlieghere ) 7699451b44SJordan Rupprecht 7799451b44SJordan Rupprecht self.runCmd("continue") 7899451b44SJordan Rupprecht 7999451b44SJordan Rupprecht # main.c:36 8099451b44SJordan Rupprecht # Check that 'frame variable --show-types' displays the correct data 8199451b44SJordan Rupprecht # type and value. 8299451b44SJordan Rupprecht self.expect( 8399451b44SJordan Rupprecht "frame variable --show-types", 8499451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 85*2238dcc3SJonas Devlieghere patterns=["\((short unsigned int|unsigned short)\) i = 33"], 86*2238dcc3SJonas Devlieghere ) 8799451b44SJordan Rupprecht 8899451b44SJordan Rupprecht # Now set variable 'i' and check that it is correctly displayed. 8999451b44SJordan Rupprecht self.runCmd("expression i = 333") 9099451b44SJordan Rupprecht self.expect( 9199451b44SJordan Rupprecht "frame variable --show-types", 9299451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 93*2238dcc3SJonas Devlieghere patterns=["\((short unsigned int|unsigned short)\) i = 333"], 94*2238dcc3SJonas Devlieghere ) 9599451b44SJordan Rupprecht 9699451b44SJordan Rupprecht self.runCmd("continue") 9799451b44SJordan Rupprecht 9899451b44SJordan Rupprecht # main.c:57 9999451b44SJordan Rupprecht # Check that 'frame variable --show-types' displays the correct data 10099451b44SJordan Rupprecht # type and value. 10199451b44SJordan Rupprecht self.expect( 10299451b44SJordan Rupprecht "frame variable --show-types", 10399451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 104*2238dcc3SJonas Devlieghere startstr="(long) i = 33", 105*2238dcc3SJonas Devlieghere ) 10699451b44SJordan Rupprecht 10799451b44SJordan Rupprecht # Now set variable 'i' and check that it is correctly displayed. 10899451b44SJordan Rupprecht self.runCmd("expression i = 33333") 10999451b44SJordan Rupprecht self.expect( 11099451b44SJordan Rupprecht "frame variable --show-types", 11199451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 112*2238dcc3SJonas Devlieghere startstr="(long) i = 33333", 113*2238dcc3SJonas Devlieghere ) 11499451b44SJordan Rupprecht 11599451b44SJordan Rupprecht self.runCmd("continue") 11699451b44SJordan Rupprecht 11799451b44SJordan Rupprecht # main.c:78 11899451b44SJordan Rupprecht # Check that 'frame variable --show-types' displays the correct data 11999451b44SJordan Rupprecht # type and value. 12099451b44SJordan Rupprecht self.expect( 12199451b44SJordan Rupprecht "frame variable --show-types", 12299451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 123*2238dcc3SJonas Devlieghere startstr="(double) i = 2.25", 124*2238dcc3SJonas Devlieghere ) 12599451b44SJordan Rupprecht 12699451b44SJordan Rupprecht # Now set variable 'i' and check that it is correctly displayed. 12799451b44SJordan Rupprecht self.runCmd("expression i = 1.5") 12899451b44SJordan Rupprecht self.expect( 12999451b44SJordan Rupprecht "frame variable --show-types", 13099451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 131*2238dcc3SJonas Devlieghere startstr="(double) i = 1.5", 132*2238dcc3SJonas Devlieghere ) 13399451b44SJordan Rupprecht 13499451b44SJordan Rupprecht self.runCmd("continue") 13599451b44SJordan Rupprecht 13699451b44SJordan Rupprecht # main.c:85 13799451b44SJordan Rupprecht # Check that 'frame variable --show-types' displays the correct data 13899451b44SJordan Rupprecht # type and value. 13999451b44SJordan Rupprecht self.expect( 14099451b44SJordan Rupprecht "frame variable --show-types", 14199451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 142*2238dcc3SJonas Devlieghere startstr="(long double) i = 2.25", 143*2238dcc3SJonas Devlieghere ) 14499451b44SJordan Rupprecht 14599451b44SJordan Rupprecht # Now set variable 'i' and check that it is correctly displayed. 14699451b44SJordan Rupprecht self.runCmd("expression i = 1.5") 14799451b44SJordan Rupprecht self.expect( 14899451b44SJordan Rupprecht "frame variable --show-types", 14999451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 150*2238dcc3SJonas Devlieghere startstr="(long double) i = 1.5", 151*2238dcc3SJonas Devlieghere ) 152