Changeset View
Changeset View
Standalone View
Standalone View
debuggers/lldb/formatters/helpers.py
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | 175 | def __init__(self, valobj, internal_dict): | |||
---|---|---|---|---|---|
179 | # cache for visible children | 179 | # cache for visible children | ||
180 | self._members = [] | 180 | self._members = [] | ||
181 | # cache for hidden children | 181 | # cache for hidden children | ||
182 | self._hiddens = [] | 182 | self._hiddens = [] | ||
183 | # child name to index | 183 | # child name to index | ||
184 | self._name2idx = {} | 184 | self._name2idx = {} | ||
185 | # whether to add original children | 185 | # whether to add original children | ||
186 | self._add_original = True | 186 | self._add_original = True | ||
187 | # some useful info | ||||
188 | process = self.valobj.GetProcess() | ||||
189 | self._endianness = process.GetByteOrder() | ||||
190 | self._pointer_size = process.GetAddressByteSize() | ||||
191 | self._char_type = valobj.GetType().GetBasicType(lldb.eBasicTypeChar) | ||||
187 | 192 | | |||
188 | def has_children(self): | 193 | def has_children(self): | ||
189 | return self._num_children != 0 | 194 | return self._num_children != 0 | ||
190 | 195 | | |||
191 | def num_children(self): | 196 | def num_children(self): | ||
192 | return self._num_children | 197 | return self._num_children | ||
193 | 198 | | |||
194 | def get_child_index(self, name): | 199 | def get_child_index(self, name): | ||
Show All 14 Lines | 204 | def get_child_at_index(self, idx): | |||
209 | elif idx < self._num_children + len(self._hiddens): | 214 | elif idx < self._num_children + len(self._hiddens): | ||
210 | child = self._hiddens[idx - self._num_children] | 215 | child = self._hiddens[idx - self._num_children] | ||
211 | else: | 216 | else: | ||
212 | return None | 217 | return None | ||
213 | 218 | | |||
214 | if isinstance(child, AutoCacheValue): | 219 | if isinstance(child, AutoCacheValue): | ||
215 | child = child.get() | 220 | child = child.get() | ||
216 | 221 | | |||
217 | if isinstance(child, lldb.SBValue): | 222 | return child | ||
218 | return child | | |||
219 | else: | | |||
220 | # we don't cache (const char[]) SBValue, ceate it on the fly | | |||
221 | # LLDB tends to reuse a static data space for c-string literal type expressions, | | |||
222 | # it might be overwriten by others if we cache them. | | |||
223 | # child is a (name, expr) tuple in this case | | |||
224 | if len(child) != 2: | | |||
225 | print('error, const char[] value should be a tuple with two elements, it is', child) | | |||
226 | return self.valobj.CreateValueFromExpression(*child) | | |||
227 | 223 | | |||
228 | @staticmethod | 224 | @staticmethod | ||
229 | def _getName(var): | 225 | def _getName(var): | ||
230 | if isinstance(var, lldb.SBValue): | 226 | if isinstance(var, lldb.SBValue): | ||
231 | return var.GetName() | 227 | return var.GetName() | ||
232 | else: | 228 | else: | ||
233 | return var[0] | 229 | return var[0] | ||
234 | 230 | | |||
Show All 30 Lines | 259 | self._name2idx.update({ | |||
265 | for idx in range(0, self._num_children) | 261 | for idx in range(0, self._num_children) | ||
266 | }) | 262 | }) | ||
267 | 263 | | |||
268 | def _update(self): | 264 | def _update(self): | ||
269 | """override in subclass""" | 265 | """override in subclass""" | ||
270 | pass | 266 | pass | ||
271 | 267 | | |||
272 | def _addChild(self, var, hidden=False): | 268 | def _addChild(self, var, hidden=False): | ||
269 | if not isinstance(var, lldb.SBValue): | ||||
270 | # special handling for (name, expr) tuple of string constants | ||||
271 | if len(var) != 2: | ||||
272 | print('error, const char[] value should be a tuple with two elements, it is', var) | ||||
273 | name, content = var | ||||
274 | | ||||
275 | if isinstance(content, unicode): | ||||
276 | content = content.encode() | ||||
277 | | ||||
278 | try: | ||||
279 | char_arr_type = self._char_type.GetArrayType(len(content)); | ||||
280 | strdata = lldb.SBData.CreateDataFromCString(self._endianness, self._pointer_size, content) | ||||
281 | var = self.valobj.CreateValueFromData(name, strdata, char_arr_type) | ||||
282 | except: | ||||
283 | pass | ||||
284 | | ||||
273 | cache = self._hiddens if hidden else self._members | 285 | cache = self._hiddens if hidden else self._members | ||
274 | cache.append(var) | 286 | cache.append(var) |