2 Tests expression evaluation in context of an object.
6 import lldbsuite.test.lldbutil as lldbutil
7 from lldbsuite.test.lldbtest import *
9 class ContextObjectTestCase(TestBase):
11 mydir = TestBase.compute_mydir(__file__)
13 def test_context_object(self):
14 """Tests expression evaluation in context of an object."""
17 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec)
18 frame = thread.GetFrameAtIndex(0)
21 # Test C++ struct variable
24 obj_val = frame.FindVariable("cpp_struct")
25 self.assertTrue(obj_val.IsValid())
27 # Test an empty expression evaluation
28 value = obj_val.EvaluateExpression("")
29 self.assertFalse(value.IsValid())
30 self.assertFalse(value.GetError().Success())
32 # Test retrieveing of a field (not a local with the same name)
33 value = obj_val.EvaluateExpression("field")
34 self.assertTrue(value.IsValid())
35 self.assertTrue(value.GetError().Success())
36 self.assertEqual(value.GetValueAsSigned(), 1111)
38 # Test functions evaluation
39 value = obj_val.EvaluateExpression("function()")
40 self.assertTrue(value.IsValid())
41 self.assertTrue(value.GetError().Success())
42 self.assertEqual(value.GetValueAsSigned(), 2222)
44 # Test that we retrieve the right global
45 value = obj_val.EvaluateExpression("global.field")
46 self.assertTrue(value.IsValid())
47 self.assertTrue(value.GetError().Success())
48 self.assertEqual(value.GetValueAsSigned(), 1111)
51 # Test C++ union variable
54 obj_val = frame.FindVariable("cpp_union")
55 self.assertTrue(obj_val.IsValid())
57 # Test retrieveing of a field
58 value = obj_val.EvaluateExpression("field_int")
59 self.assertTrue(value.IsValid())
60 self.assertTrue(value.GetError().Success())
61 self.assertEqual(value.GetValueAsSigned(), 5555)
67 obj_val = frame.FindVariable("cpp_scalar")
68 self.assertTrue(obj_val.IsValid())
70 # Test an expression evaluation
71 value = obj_val.EvaluateExpression("1")
72 self.assertFalse(value.IsValid())
73 self.assertFalse(value.GetError().Success())
79 obj_val = frame.FindVariable("cpp_array")
80 self.assertTrue(obj_val.IsValid())
82 # Test an expression evaluation
83 value = obj_val.EvaluateExpression("1")
84 self.assertFalse(value.IsValid())
85 self.assertFalse(value.GetError().Success())
87 # Test retrieveing of an element's field
88 value = obj_val.GetValueForExpressionPath("[7]").EvaluateExpression("field")
89 self.assertTrue(value.IsValid())
90 self.assertTrue(value.GetError().Success())
91 self.assertEqual(value.GetValueAsSigned(), 1111)
97 obj_val = frame.FindVariable("cpp_pointer")
98 self.assertTrue(obj_val.IsValid())
100 # Test an expression evaluation
101 value = obj_val.EvaluateExpression("1")
102 self.assertFalse(value.IsValid())
103 self.assertFalse(value.GetError().Success())
105 # Test retrieveing of a dereferenced object's field
106 value = obj_val.Dereference().EvaluateExpression("field")
107 self.assertTrue(value.IsValid())
108 self.assertTrue(value.GetError().Success())
109 self.assertEqual(value.GetValueAsSigned(), 1111)
112 # Test C++ computation result
115 obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStruct()")
116 self.assertTrue(obj_val.IsValid())
118 # Test an expression evaluation
119 value = obj_val.EvaluateExpression("1")
120 self.assertTrue(value.IsValid())
121 self.assertFalse(value.GetError().Success())
124 # Test C++ computation result located in debuggee memory
127 obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStructPtr()")
128 self.assertTrue(obj_val.IsValid())
130 # Test an expression evaluation
131 value = obj_val.EvaluateExpression("1")
132 self.assertFalse(value.IsValid())
133 self.assertFalse(value.GetError().Success())
135 # Test retrieveing of a dereferenced object's field
136 value = obj_val.Dereference().EvaluateExpression("field")
137 self.assertTrue(value.IsValid())
138 self.assertTrue(value.GetError().Success())
139 self.assertEqual(value.GetValueAsSigned(), 1111)
144 self.main_source = "main.cpp"
145 self.main_source_spec = lldb.SBFileSpec(self.main_source)