brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · ca3357c Raw
93 lines · python
1"""2Test DIL literals.3"""4 5import lldb6from lldbsuite.test.lldbtest import *7from lldbsuite.test.decorators import *8from lldbsuite.test import lldbutil9 10 11class TestFrameVarDILLiterals(TestBase):12    NO_DEBUG_INFO_TESTCASE = True13 14    def test_literals(self):15        self.build()16        (target, process, thread, bkpt) = 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        # Check boolean literals parsing23        self.expect_var_path("true", value="true", type="bool")24        self.expect_var_path("false", value="false", type="bool")25 26        # Check number literals parsing27        self.expect_var_path("1.0", value="1", type="double")28        self.expect_var_path("1.0f", value="1", type="float")29        self.expect_var_path("0x1.2p+3f", value="9", type="float")30        self.expect_var_path("1", value="1", type="int")31        self.expect_var_path("1u", value="1", type="unsigned int")32        self.expect_var_path("0b1l", value="1", type="long")33        self.expect_var_path("01ul", value="1", type="unsigned long")34        self.expect_var_path("01lu", value="1", type="unsigned long")35        self.expect_var_path("0o1ll", value="1", type="long long")36        self.expect_var_path("0x1ULL", value="1", type="unsigned long long")37        self.expect_var_path("0x1llu", value="1", type="unsigned long long")38        self.expect(39            "frame var '1LLL'",40            error=True,41            substrs=["Failed to parse token as numeric-constant"],42        )43        self.expect(44            "frame var '1ullu'",45            error=True,46            substrs=["Failed to parse token as numeric-constant"],47        )48 49        # Check integer literal type edge cases (dil::Interpreter::PickIntegerType)50        frame = thread.GetFrameAtIndex(0)51        v = frame.GetValueForVariablePath("argc")52        # Creating an SBType from a BasicType still requires any value from the frame53        int_size = v.GetType().GetBasicType(lldb.eBasicTypeInt).GetByteSize()54        long_size = v.GetType().GetBasicType(lldb.eBasicTypeLong).GetByteSize()55        longlong_size = v.GetType().GetBasicType(lldb.eBasicTypeLongLong).GetByteSize()56 57        longlong_str = "0x" + "F" * longlong_size * 258        longlong_str = str(int(longlong_str, 16))59        self.assert_literal_type(frame, longlong_str, lldb.eBasicTypeUnsignedLongLong)60        toolong_str = "0x" + "F" * longlong_size * 2 + "F"61        self.expect(62            f"frame var '{toolong_str}'",63            error=True,64            substrs=[65                "integer literal is too large to be represented in any integer type"66            ],67        )68 69        # These check only apply if adjacent types have different sizes70        if int_size < long_size:71            # For exmaple, 0xFFFFFFFF and 4294967295 will have different types72            # even though the numeric value is the same73            hex_str = "0x" + "F" * int_size * 274            dec_str = str(int(hex_str, 16))75            self.assert_literal_type(frame, hex_str, lldb.eBasicTypeUnsignedInt)76            self.assert_literal_type(frame, dec_str, lldb.eBasicTypeLong)77            long_str = "0x" + "F" * int_size * 2 + "F"78            ulong_str = long_str + "u"79            self.assert_literal_type(frame, long_str, lldb.eBasicTypeLong)80            self.assert_literal_type(frame, ulong_str, lldb.eBasicTypeUnsignedLong)81        if long_size < longlong_size:82            longlong_str = "0x" + "F" * long_size * 2 + "F"83            ulonglong_str = longlong_str + "u"84            self.assert_literal_type(frame, longlong_str, lldb.eBasicTypeLongLong)85            self.assert_literal_type(86                frame, ulonglong_str, lldb.eBasicTypeUnsignedLongLong87            )88 89    def assert_literal_type(self, frame, literal, expected_type):90        value = frame.GetValueForVariablePath(literal)91        basic_type = value.GetType().GetBasicType()92        self.assertEqual(basic_type, expected_type)93