199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest that lldb persistent variables works correctly. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprecht 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprechtclass PersistentVariablesTestCase(TestBase): 1299451b44SJordan Rupprecht 1399451b44SJordan Rupprecht def test_persistent_variables(self): 1499451b44SJordan Rupprecht """Test that lldb persistent variables works correctly.""" 1599451b44SJordan Rupprecht self.build() 16f52e4129SRaphael Isemann lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c")) 1799451b44SJordan Rupprecht 18f52e4129SRaphael Isemann self.runCmd("expr int $i = i") 19f52e4129SRaphael Isemann self.expect_expr("$i == i", result_type="bool", result_value="true") 20f52e4129SRaphael Isemann self.expect_expr("$i + 1", result_type="int", result_value="6") 21f52e4129SRaphael Isemann self.expect_expr("$i + 3", result_type="int", result_value="8") 22f52e4129SRaphael Isemann self.expect_expr("$1 + $2", result_type="int", result_value="14") 23f52e4129SRaphael Isemann self.expect_expr("$3", result_type="int", result_value="14") 24f52e4129SRaphael Isemann self.expect_expr("$2", result_type="int", result_value="8") 25f52e4129SRaphael Isemann self.expect_expr("(int)-2", result_type="int", result_value="-2") 26f52e4129SRaphael Isemann self.expect_expr("$4", result_type="int", result_value="-2") 27f52e4129SRaphael Isemann self.expect_expr("$4 > (int)31", result_type="bool", result_value="false") 28f52e4129SRaphael Isemann self.expect_expr("(long)$4", result_type="long", result_value="-2") 29a8c75554SRaphael Isemann 30a8c75554SRaphael Isemann # Try assigning an existing persistent veriable with a numeric name. 31a8c75554SRaphael Isemann self.expect("expr int $2 = 1234", error=True, 32a8c75554SRaphael Isemann substrs=["Error [IRForTarget]: Names starting with $0, $1, ... are reserved for use as result names"]) 33a8c75554SRaphael Isemann # $2 should still have its original value. 34a8c75554SRaphael Isemann self.expect_expr("$2", result_type="int", result_value="8") 35a8c75554SRaphael Isemann 36a8c75554SRaphael Isemann # Try assigning an non-existing persistent veriable with a numeric name. 37a8c75554SRaphael Isemann self.expect("expr int $200 = 3", error=True, 38a8c75554SRaphael Isemann substrs=["Error [IRForTarget]: Names starting with $0, $1, ... are reserved for use as result names"]) 39a8c75554SRaphael Isemann # Test that $200 wasn't created by the previous expression. 40a8c75554SRaphael Isemann self.expect("expr $200", error=True, 41a8c75554SRaphael Isemann substrs=["use of undeclared identifier '$200'"]) 42*cb81e662SRaphael Isemann 43*cb81e662SRaphael Isemann # Try redeclaring the persistent variable with the same type. 44*cb81e662SRaphael Isemann # This should be rejected as we treat them as if they are globals. 45*cb81e662SRaphael Isemann self.expect("expr int $i = 123", error=True, 46*cb81e662SRaphael Isemann substrs=["error: redefinition of persistent variable '$i'"]) 47*cb81e662SRaphael Isemann self.expect_expr("$i", result_type="int", result_value="5") 48*cb81e662SRaphael Isemann 49*cb81e662SRaphael Isemann # Try redeclaring the persistent variable with another type. Should 50*cb81e662SRaphael Isemann # also be rejected. 51*cb81e662SRaphael Isemann self.expect("expr long $i = 123", error=True, 52*cb81e662SRaphael Isemann substrs=["error: redefinition of persistent variable '$i'"]) 53*cb81e662SRaphael Isemann self.expect_expr("$i", result_type="int", result_value="5") 54*cb81e662SRaphael Isemann 55*cb81e662SRaphael Isemann # Try assigning the persistent variable a new value. 56*cb81e662SRaphael Isemann self.expect("expr $i = 55") 57*cb81e662SRaphael Isemann self.expect_expr("$i", result_type="int", result_value="55") 58