@@ -106,6 +106,20 @@ def test_with_run_command_complete(self):
106
106
],
107
107
)
108
108
109
+ def build_value_check (self , var_name , values ):
110
+ children_1 = [ValueCheck (name = "x" , value = values [0 ], type = "int" ),
111
+ ValueCheck (name = "y" , value = values [1 ], type = "int" )]
112
+ children_2 = [ValueCheck (name = "x" , value = values [2 ], type = "int" ),
113
+ ValueCheck (name = "y" , value = values [3 ], type = "int" )]
114
+ elem_0 = ValueCheck (name = "[0]" , value = None , type = "PointType" ,
115
+ children = children_1 )
116
+ elem_1 = ValueCheck (name = "[1]" , value = None , type = "PointType" ,
117
+ children = children_2 )
118
+ value_check = ValueCheck (name = var_name , value = None , type = "PointType[2]" ,
119
+ children = [elem_0 , elem_1 ])
120
+
121
+ return value_check
122
+
109
123
@expectedFailureAll (
110
124
compiler = ["gcc" ], bugnumber = "Compiler emits incomplete debug info"
111
125
)
@@ -142,27 +156,30 @@ def test_with_python_api(self):
142
156
# in_scope_only => False
143
157
valList = frame .GetVariables (False , False , True , False )
144
158
145
- for val in valList :
159
+ # Build ValueCheckers for the values we're going to find:
160
+ value_check_A = self .build_value_check ("A::g_points" , ["1" , "2" , "11" , "22" ])
161
+ value_check_none = self .build_value_check ("g_points" , ["3" , "4" , "33" , "44" ])
162
+ value_check_AA = self .build_value_check ("AA::g_points" , ["5" , "6" , "55" , "66" ])
163
+
164
+ for val in valList :
146
165
self .DebugSBValue (val )
147
166
name = val .GetName ()
148
- self .assertIn (name , ["g_points" , "A::g_points" ])
167
+ self .assertIn (name , ["g_points" , "A::g_points" , "AA::g_points" ])
168
+
169
+ if name == "A::g_points" :
170
+ self .assertEqual (val .GetValueType (), lldb .eValueTypeVariableGlobal )
171
+ value_check_A .check_value (self , val , "Got A::g_points right" )
149
172
if name == "g_points" :
150
173
self .assertEqual (val .GetValueType (), lldb .eValueTypeVariableStatic )
151
- self . assertEqual ( val . GetNumChildren (), 2 )
152
- elif name == "A ::g_points" :
174
+ value_check_none . check_value ( self , val , "Got g_points right" )
175
+ if name == "AA ::g_points" :
153
176
self .assertEqual (val .GetValueType (), lldb .eValueTypeVariableGlobal )
154
- self .assertEqual (val .GetNumChildren (), 2 )
155
- child1 = val .GetChildAtIndex (1 )
156
- self .DebugSBValue (child1 )
157
- child1_x = child1 .GetChildAtIndex (0 )
158
- self .DebugSBValue (child1_x )
159
- self .assertEqual (child1_x .GetTypeName (), "int" )
160
- self .assertEqual (child1_x .GetValue (), "11" )
177
+ value_check_AA .check_value (self , val , "Got AA::g_points right" )
161
178
162
179
# SBFrame.FindValue() should also work.
163
180
val = frame .FindValue ("A::g_points" , lldb .eValueTypeVariableGlobal )
164
181
self .DebugSBValue (val )
165
- self . assertEqual ( val . GetName () , "A::g_points " )
182
+ value_check_A . check_value ( self , val , "FindValue also works " )
166
183
167
184
# Also exercise the "parameter" and "local" scopes while we are at it.
168
185
val = frame .FindValue ("argc" , lldb .eValueTypeVariableArgument )
@@ -176,3 +193,37 @@ def test_with_python_api(self):
176
193
val = frame .FindValue ("hello_world" , lldb .eValueTypeVariableLocal )
177
194
self .DebugSBValue (val )
178
195
self .assertEqual (val .GetName (), "hello_world" )
196
+
197
+ # We should also be able to get class statics from FindGlobalVariables.
198
+ # eMatchTypeStartsWith should only find A:: not AA::
199
+ val_list = target .FindGlobalVariables ("A::" , 10 , lldb .eMatchTypeStartsWith )
200
+ self .assertEqual (val_list .GetSize (), 1 , "Found only one match" )
201
+ val = val_list [0 ]
202
+ value_check_A .check_value (self , val , "FindGlobalVariables starts with" )
203
+
204
+ # Regex should find both
205
+ val_list = target .FindGlobalVariables ("A::" , 10 , lldb .eMatchTypeRegex )
206
+ self .assertEqual (val_list .GetSize (), 2 , "Found A & AA" )
207
+ found_a = False
208
+ found_aa = False
209
+ for val in val_list :
210
+ name = val .GetName ()
211
+ if name == "A::g_points" :
212
+ value_check_A .check_value (self , val , "AA found by regex" )
213
+ found_a = True
214
+ elif name == "AA::g_points" :
215
+ value_check_AA .check_value (self , val , "A found by regex" )
216
+ found_aa = True
217
+
218
+ self .assertTrue (found_a , "Regex search found A::g_points" )
219
+ self .assertTrue (found_aa , "Regex search found AA::g_points" )
220
+
221
+ # Normal search for full name should find one, but it looks like we don't match
222
+ # on identifier boundaries here yet:
223
+ val_list = target .FindGlobalVariables ("A::g_points" , 10 , lldb .eMatchTypeNormal )
224
+ self .assertEqual (val_list .GetSize (), 2 , "We aren't matching on name boundaries yet" )
225
+
226
+ # Normal search for g_points should find 3 - FindGlobalVariables doesn't distinguish
227
+ # between file statics and globals:
228
+ val_list = target .FindGlobalVariables ("g_points" , 10 , lldb .eMatchTypeNormal )
229
+ self .assertEqual (val_list .GetSize (), 3 , "Found all three g_points" )
0 commit comments