| 1 |
""" |
| 2 |
Test DIL literals. |
| 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 TestFrameVarDILLiterals(TestBase): |
| 12 |
NO_DEBUG_INFO_TESTCASE = True |
| 13 |
|
| 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 parsing |
| 23 |
self.expect_var_path("true", value="true", type="bool") |
| 24 |
self.expect_var_path("false", value="false", type="bool") |
| 25 |
|
| 26 |
# Check number literals parsing |
| 27 |
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 frame |
| 53 |
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 * 2 |
| 58 |
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 sizes |
| 70 |
if int_size < long_size: |
| 71 |
# For exmaple, 0xFFFFFFFF and 4294967295 will have different types |
| 72 |
# even though the numeric value is the same |
| 73 |
hex_str = "0x" + "F" * int_size * 2 |
| 74 |
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.eBasicTypeUnsignedLongLong |
| 87 |
) |
| 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) |