1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
| """
Tests expression evaluation in context of an object.
"""
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
class ContextObjectTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def test_context_object(self):
"""Tests expression evaluation in context of an object."""
self.build()
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec)
frame = thread.GetFrameAtIndex(0)
#
# Test C++ struct variable
#
obj_val = frame.FindVariable("cpp_struct")
self.assertTrue(obj_val.IsValid())
# Test an empty expression evaluation
value = obj_val.EvaluateExpression("")
self.assertFalse(value.IsValid())
self.assertFalse(value.GetError().Success())
# Test retrieveing of a field (not a local with the same name)
value = obj_val.EvaluateExpression("field")
self.assertTrue(value.IsValid())
self.assertTrue(value.GetError().Success())
self.assertEqual(value.GetValueAsSigned(), 1111)
# Test functions evaluation
value = obj_val.EvaluateExpression("function()")
self.assertTrue(value.IsValid())
self.assertTrue(value.GetError().Success())
self.assertEqual(value.GetValueAsSigned(), 2222)
# Test that we retrieve the right global
value = obj_val.EvaluateExpression("global.field")
self.assertTrue(value.IsValid())
self.assertTrue(value.GetError().Success())
self.assertEqual(value.GetValueAsSigned(), 1111)
#
# Test C++ union variable
#
obj_val = frame.FindVariable("cpp_union")
self.assertTrue(obj_val.IsValid())
# Test retrieveing of a field
value = obj_val.EvaluateExpression("field_int")
self.assertTrue(value.IsValid())
self.assertTrue(value.GetError().Success())
self.assertEqual(value.GetValueAsSigned(), 5555)
#
# Test C++ scalar
#
obj_val = frame.FindVariable("cpp_scalar")
self.assertTrue(obj_val.IsValid())
# Test an expression evaluation
value = obj_val.EvaluateExpression("1")
self.assertFalse(value.IsValid())
self.assertFalse(value.GetError().Success())
#
# Test C++ array
#
obj_val = frame.FindVariable("cpp_array")
self.assertTrue(obj_val.IsValid())
# Test an expression evaluation
value = obj_val.EvaluateExpression("1")
self.assertFalse(value.IsValid())
self.assertFalse(value.GetError().Success())
# Test retrieveing of an element's field
value = obj_val.GetValueForExpressionPath("[7]").EvaluateExpression("field")
self.assertTrue(value.IsValid())
self.assertTrue(value.GetError().Success())
self.assertEqual(value.GetValueAsSigned(), 1111)
#
# Test C++ pointer
#
obj_val = frame.FindVariable("cpp_pointer")
self.assertTrue(obj_val.IsValid())
# Test an expression evaluation
value = obj_val.EvaluateExpression("1")
self.assertFalse(value.IsValid())
self.assertFalse(value.GetError().Success())
# Test retrieveing of a dereferenced object's field
value = obj_val.Dereference().EvaluateExpression("field")
self.assertTrue(value.IsValid())
self.assertTrue(value.GetError().Success())
self.assertEqual(value.GetValueAsSigned(), 1111)
#
# Test C++ computation result
#
obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStruct()")
self.assertTrue(obj_val.IsValid())
# Test an expression evaluation
value = obj_val.EvaluateExpression("1")
self.assertTrue(value.IsValid())
self.assertFalse(value.GetError().Success())
#
# Test C++ computation result located in debuggee memory
#
obj_val = frame.EvaluateExpression("cpp_namespace::GetCppStructPtr()")
self.assertTrue(obj_val.IsValid())
# Test an expression evaluation
value = obj_val.EvaluateExpression("1")
self.assertFalse(value.IsValid())
self.assertFalse(value.GetError().Success())
# Test retrieveing of a dereferenced object's field
value = obj_val.Dereference().EvaluateExpression("field")
self.assertTrue(value.IsValid())
self.assertTrue(value.GetError().Success())
self.assertEqual(value.GetValueAsSigned(), 1111)
def setUp(self):
TestBase.setUp(self)
self.main_source = "main.cpp"
self.main_source_spec = lldb.SBFileSpec(self.main_source)
|