[Clang] Prevent `mlink-builtin-bitcode` from internalizing the RPC client (#118661)
[llvm-project.git] / lldb / test / API / commands / expression / persistent_variables / TestPersistentVariables.py
blobd0d9358589a71962e5e3606b47c1c6607970cc7a
1 """
2 Test that lldb persistent variables works correctly.
3 """
6 import lldb
7 from lldbsuite.test.lldbtest import *
10 class PersistentVariablesTestCase(TestBase):
11 def test_persistent_variables(self):
12 """Test that lldb persistent variables works correctly."""
13 self.build()
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.
31 self.expect(
32 "expr int $2 = 1234",
33 error=True,
34 substrs=[
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.
42 self.expect(
43 "expr int $200 = 3",
44 error=True,
45 substrs=[
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.
50 self.expect(
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.
56 self.expect(
57 "expr int $i = 123",
58 error=True,
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
64 # also be rejected.
65 self.expect(
66 "expr long $i = 123",
67 error=True,
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")