brintos

brintos / llvm-project-archived public Read only

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