Don't allow SBValue::Cast to cast from a smaller type to a larger,
as we don't in general know where the extra data should come from. Differential Revision: https://reviews.llvm.org/D153657
This commit is contained in:
@@ -146,6 +146,19 @@ class ValueAPITestCase(TestBase):
|
||||
self.assertTrue(val_s.GetChildMemberWithName("a").AddressOf(), VALID_VARIABLE)
|
||||
self.assertTrue(val_a.Cast(val_i.GetType()).AddressOf(), VALID_VARIABLE)
|
||||
|
||||
# Test some other cases of the Cast API. We allow casts from one struct type
|
||||
# to another, which is a little weird, but we don't support casting from a
|
||||
# smaller type to a larger as we often wouldn't know how to get the extra data:
|
||||
val_f = target.EvaluateExpression("f")
|
||||
bad_cast = val_s.Cast(val_f.GetType())
|
||||
self.assertFailure(bad_cast.GetError(),
|
||||
"Can only cast to a type that is equal to or smaller than the orignal type.")
|
||||
weird_cast = val_f.Cast(val_s.GetType())
|
||||
self.assertSuccess(weird_cast.GetError(),
|
||||
"Can cast from a larger to a smaller")
|
||||
self.assertEqual(weird_cast.GetChildMemberWithName("a").GetValueAsSigned(0), 33,
|
||||
"Got the right value")
|
||||
|
||||
# Check that lldb.value implements truth testing.
|
||||
self.assertFalse(lldb.value(frame0.FindVariable("bogus")))
|
||||
self.assertTrue(lldb.value(frame0.FindVariable("uinthex")))
|
||||
|
||||
@@ -29,6 +29,13 @@ struct MyStruct
|
||||
int b;
|
||||
};
|
||||
|
||||
struct MyBiggerStruct
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
};
|
||||
|
||||
int main (int argc, char const *argv[])
|
||||
{
|
||||
uint32_t uinthex = 0xE0A35F10;
|
||||
@@ -37,6 +44,7 @@ int main (int argc, char const *argv[])
|
||||
int i;
|
||||
MyInt a = 12345;
|
||||
struct MyStruct s = { 11, 22 };
|
||||
struct MyBiggerStruct f = { 33, 44, 55 };
|
||||
int *my_int_ptr = &g_my_int;
|
||||
printf("my_int_ptr points to location %p\n", my_int_ptr);
|
||||
const char **str_ptr = days_of_week;
|
||||
|
||||
Reference in New Issue
Block a user