2 Test that lldb persistent variables works correctly.
7 from lldbsuite
.test
.lldbtest
import *
10 class PersistentVariablesTestCase(TestBase
):
11 def test_persistent_variables(self
):
12 """Test that lldb persistent variables works correctly."""
14 lldbutil
.run_to_source_breakpoint(
15 self
, "// break here", lldb
.SBFileSpec("main.c")
18 self
.runCmd("expr int $i = i")
19 self
.expect_expr("$i == i", result_type
="bool", result_value
="true")
20 self
.expect_expr("$i + 1", result_type
="int", result_value
="6")
21 self
.expect_expr("$i + 3", result_type
="int", result_value
="8")
22 self
.expect_expr("$1 + $2", result_type
="int", result_value
="14")
23 self
.expect_expr("$3", result_type
="int", result_value
="14")
24 self
.expect_expr("$2", result_type
="int", result_value
="8")
25 self
.expect_expr("(int)-2", result_type
="int", result_value
="-2")
26 self
.expect_expr("$4", result_type
="int", result_value
="-2")
27 self
.expect_expr("$4 > (int)31", result_type
="bool", result_value
="false")
28 self
.expect_expr("(long)$4", result_type
="long", result_value
="-2")
30 # Try assigning an existing persistent veriable with a numeric name.
35 "Error [IRForTarget]: Names starting with $0, $1, ... are reserved for use as result names"
38 # $2 should still have its original value.
39 self
.expect_expr("$2", result_type
="int", result_value
="8")
41 # Try assigning an non-existing persistent veriable with a numeric name.
46 "Error [IRForTarget]: Names starting with $0, $1, ... are reserved for use as result names"
49 # Test that $200 wasn't created by the previous expression.
51 "expr $200", error
=True, substrs
=["use of undeclared identifier '$200'"]
54 # Try redeclaring the persistent variable with the same type.
55 # This should be rejected as we treat them as if they are globals.
59 substrs
=["redefinition of persistent variable '$i'"],
61 self
.expect_expr("$i", result_type
="int", result_value
="5")
63 # Try redeclaring the persistent variable with another type. Should
68 substrs
=["redefinition of persistent variable '$i'"],
70 self
.expect_expr("$i", result_type
="int", result_value
="5")
72 # Try assigning the persistent variable a new value.
73 self
.expect("expr $i = 55")
74 self
.expect_expr("$i", result_type
="int", result_value
="55")