[lldb] Add lookup by name to SBValue through new member property (#118814)

Introduces a `member` property to `SBValue`. This property provides pythonic access to a
value's members, by name. The expression `value.member["name"]` will be an alternate
form form of writing `value.GetChildMemberWithName("name")`.
This commit is contained in:
Dave Lee
2024-12-09 10:48:28 -08:00
committed by GitHub
parent bef562343f
commit 53fd724b25
2 changed files with 18 additions and 6 deletions

View File

@@ -140,10 +140,8 @@ class ValueAPITestCase(TestBase):
val_i = target.EvaluateExpression("i")
val_s = target.EvaluateExpression("s")
val_a = target.EvaluateExpression("a")
self.assertTrue(
val_s.GetChildMemberWithName("a").GetAddress().IsValid(), VALID_VARIABLE
)
self.assertTrue(val_s.GetChildMemberWithName("a").AddressOf(), VALID_VARIABLE)
self.assertTrue(val_s.member["a"].GetAddress().IsValid(), VALID_VARIABLE)
self.assertTrue(val_s.member["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
@@ -210,7 +208,7 @@ class ValueAPITestCase(TestBase):
weird_cast = f_var.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),
weird_cast.member["a"].GetValueAsSigned(0),
33,
"Got the right value",
)