aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2023-06-26 16:01:18 -0700
committerJim Ingham <jingham@apple.com>2023-06-26 16:02:01 -0700
commitf05e2fb013f0e2504471a9899dba7d70cc58a63d (patch)
tree6ca2739c84156a060c7e2d02e8d6deed3e52a937 /lldb/test/API/python_api
parent4cf35a85c77db42b524459fe019a34c7306ca359 (diff)
downloadllvm-f05e2fb013f0e2504471a9899dba7d70cc58a63d.zip
llvm-f05e2fb013f0e2504471a9899dba7d70cc58a63d.tar.gz
llvm-f05e2fb013f0e2504471a9899dba7d70cc58a63d.tar.bz2
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
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/value/TestValueAPI.py13
-rw-r--r--lldb/test/API/python_api/value/main.c8
2 files changed, 21 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/value/TestValueAPI.py b/lldb/test/API/python_api/value/TestValueAPI.py
index dc68eb6..b5d065e 100644
--- a/lldb/test/API/python_api/value/TestValueAPI.py
+++ b/lldb/test/API/python_api/value/TestValueAPI.py
@@ -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")))
diff --git a/lldb/test/API/python_api/value/main.c b/lldb/test/API/python_api/value/main.c
index c2e0dc8..bf00aba 100644
--- a/lldb/test/API/python_api/value/main.c
+++ b/lldb/test/API/python_api/value/main.c
@@ -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;