Debian Codegraph @

lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/TestFrameVarDILArraySubscript.py

raw
1 """
2 Test DIL array subscript.
3 """
4
5 import lldb
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test import lldbutil
9
10
11 class TestFrameVarDILArraySubscript(TestBase):
12 NO_DEBUG_INFO_TESTCASE = True
13
14 def test_subscript(self):
15 self.build()
16 lldbutil.run_to_source_breakpoint(
17 self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp")
18 )
19
20 self.runCmd("settings set target.experimental.use-DIL true")
21
22 # Test int[] and int*
23 self.expect_var_path("int_arr[0]", value="1")
24 self.expect_var_path("int_ptr[1]", value="2")
25 self.expect_var_path("int_ptr[enum_one]", value="2")
26
27 # Test when base and index are references.
28 self.expect_var_path("int_arr[0]", value="1")
29 self.expect_var_path("int_arr[idx_1_ref]", value="2")
30 self.expect_var_path("int_arr[enum_ref]", value="2")
31 self.expect_var_path("int_arr_ref[0]", value="1")
32 self.expect_var_path("int_arr_ref[idx_1_ref]", value="2")
33 self.expect_var_path("int_arr_ref[enum_ref]", value="2")
34
35 # Test when base and index are typedefs.
36 self.expect_var_path("td_int_arr[0]", value="1")
37 self.expect_var_path("td_int_arr[td_int_idx_1]", value="2")
38 self.expect_var_path("td_int_arr[td_td_int_idx_2]", value="3")
39 self.expect_var_path("td_int_ptr[0]", value="1")
40 self.expect_var_path("td_int_ptr[td_int_idx_1]", value="2")
41 self.expect_var_path("td_int_ptr[td_td_int_idx_2]", value="3")
42
43 # Both typedefs and refs
44 self.expect_var_path("td_int_arr_ref[td_int_idx_1_ref]", value="2")
45
46 # Test for index out of bounds. 1 beyond the end.
47 self.expect_var_path("int_arr[3]", type="int")
48 # Far beyond the end (but not far enough to be off the top of the stack).
49 self.expect_var_path("int_arr[10]", type="int")
50
51 # Test address-of of the subscripted value.
52 self.expect_var_path("*(&int_arr[1])", value="2")
53
54 # Test for negative index.
55 self.expect_var_path("int_ptr_1[-1]", value="1")
56
57 # Test for floating point index
58 self.expect(
59 "frame var 'int_arr[1.0]'",
60 error=True,
61 substrs=["array subscript is not an integer"],
62 )
63
64 # Test accessing bits in scalar types.
65 self.expect_var_path("idx_1[0]", value="1")
66 self.expect_var_path("idx_1[1]", value="0")
67 self.expect_var_path("1[0]", value="1")
68
69 # Bit access not valid for a reference.
70 self.expect(
71 "frame var 'idx_1_ref[0]'",
72 error=True,
73 substrs=["bitfield range 0:0 is not valid"],
74 )
75
76 # Base should be a "pointer to T" and index should be of an integral type.
77 self.expect(
78 "frame var 'int_arr[int_ptr]'",
79 error=True,
80 substrs=["array subscript is not an integer"],
81 )
82
83 # Base should not be a pointer to void
84 self.expect(
85 "frame var 'p_void[0]'",
86 error=True,
87 substrs=["subscript of pointer to incomplete type 'void'"],
88 )
89
90 def test_subscript_synthetic(self):
91 self.build()
92 lldbutil.run_to_source_breakpoint(
93 self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp")
94 )
95
96 self.runCmd("settings set target.experimental.use-DIL true")
97 self.runCmd("script from myArraySynthProvider import *")
98 self.runCmd("type synth add -l myArraySynthProvider myArray")
99
100 # Test synthetic value subscription
101 self.expect_var_path("vector[1]", value="2")
102 self.expect(
103 "frame var 'vector[100]'",
104 error=True,
105 substrs=["array index 100 is not valid"],
106 )
107 self.expect(
108 "frame var 'ma_ptr[0]'",
109 substrs=["(myArray) ma_ptr[0] = ([0] = 7, [1] = 8, [2] = 9, [3] = 10)"],
110 )