blob: 0d124d758656859dce564f8f139de8c13e2c7bdb [file] [log] [blame]
Enrico Granata217f91f2011-08-17 19:07:52 +00001import re
Enrico Granata85ce21c2012-04-25 16:32:39 +00002import lldb.formatters.Logger
Enrico Granata217f91f2011-08-17 19:07:52 +00003
4# C++ STL formatters for LLDB
Enrico Granata5a61fc0d2011-08-22 16:10:25 +00005# These formatters are based upon the version of the GNU libstdc++
Enrico Granata114bb192012-08-27 17:42:50 +00006# as it ships with Mac OS X 10.6.8 thru 10.8.0
Enrico Granata5a61fc0d2011-08-22 16:10:25 +00007# You are encouraged to look at the STL implementation for your platform
8# before relying on these formatters to do the right thing for your setup
Enrico Granata217f91f2011-08-17 19:07:52 +00009
10class StdListSynthProvider:
11
12 def __init__(self, valobj, dict):
Enrico Granata7d222212012-04-25 17:53:41 +000013 logger = lldb.formatters.Logger.Logger()
Enrico Granata217f91f2011-08-17 19:07:52 +000014 self.valobj = valobj
Enrico Granatacb50d342012-04-10 00:11:03 +000015 self.count = None
16 logger >> "Providing synthetic children for a map named " + str(valobj.GetName())
Enrico Granata217f91f2011-08-17 19:07:52 +000017
Enrico Granata9d60f602012-03-09 03:09:58 +000018 def next_node(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +000019 logger = lldb.formatters.Logger.Logger()
Enrico Granata9d60f602012-03-09 03:09:58 +000020 return node.GetChildMemberWithName('_M_next')
21
22 def is_valid(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +000023 logger = lldb.formatters.Logger.Logger()
Enrico Granata9d60f602012-03-09 03:09:58 +000024 return self.value(self.next_node(node)) != self.node_address
25
26 def value(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +000027 logger = lldb.formatters.Logger.Logger()
Enrico Granata9d60f602012-03-09 03:09:58 +000028 return node.GetValueAsUnsigned()
29
30 # Floyd's cyle-finding algorithm
31 # try to detect if this list has a loop
32 def has_loop(self):
Enrico Granatad50f18b2012-03-29 19:29:45 +000033 global _list_uses_loop_detector
Enrico Granata7d222212012-04-25 17:53:41 +000034 logger = lldb.formatters.Logger.Logger()
Enrico Granatad50f18b2012-03-29 19:29:45 +000035 if _list_uses_loop_detector == False:
36 logger >> "Asked not to use loop detection"
37 return False
Enrico Granata9d60f602012-03-09 03:09:58 +000038 slow = self.next
39 fast1 = self.next
40 fast2 = self.next
41 while self.is_valid(slow):
42 slow_value = self.value(slow)
43 fast1 = self.next_node(fast2)
44 fast2 = self.next_node(fast1)
45 if self.value(fast1) == slow_value or self.value(fast2) == slow_value:
46 return True
47 slow = self.next_node(slow)
48 return False
49
Enrico Granata217f91f2011-08-17 19:07:52 +000050 def num_children(self):
Enrico Granatad50f18b2012-03-29 19:29:45 +000051 global _list_capping_size
Enrico Granata7d222212012-04-25 17:53:41 +000052 logger = lldb.formatters.Logger.Logger()
Enrico Granata9d60f602012-03-09 03:09:58 +000053 if self.count == None:
54 self.count = self.num_children_impl()
Enrico Granatad50f18b2012-03-29 19:29:45 +000055 if self.count > _list_capping_size:
56 self.count = _list_capping_size
Enrico Granata9d60f602012-03-09 03:09:58 +000057 return self.count
58
59 def num_children_impl(self):
Enrico Granata7d222212012-04-25 17:53:41 +000060 logger = lldb.formatters.Logger.Logger()
Enrico Granatad50f18b2012-03-29 19:29:45 +000061 global _list_capping_size
Enrico Granata5a61fc0d2011-08-22 16:10:25 +000062 try:
63 next_val = self.next.GetValueAsUnsigned(0)
64 prev_val = self.prev.GetValueAsUnsigned(0)
65 # After a std::list has been initialized, both next and prev will be non-NULL
66 if next_val == 0 or prev_val == 0:
67 return 0
68 if next_val == self.node_address:
69 return 0
70 if next_val == prev_val:
71 return 1
Enrico Granata9d60f602012-03-09 03:09:58 +000072 if self.has_loop():
73 return 0
Enrico Granata5a61fc0d2011-08-22 16:10:25 +000074 size = 2
75 current = self.next
76 while current.GetChildMemberWithName('_M_next').GetValueAsUnsigned(0) != self.node_address:
77 size = size + 1
78 current = current.GetChildMemberWithName('_M_next')
Enrico Granatad50f18b2012-03-29 19:29:45 +000079 if size > _list_capping_size:
80 return _list_capping_size
Enrico Granata5a61fc0d2011-08-22 16:10:25 +000081 return (size - 1)
82 except:
83 return 0;
Enrico Granata217f91f2011-08-17 19:07:52 +000084
85 def get_child_index(self,name):
Enrico Granata7d222212012-04-25 17:53:41 +000086 logger = lldb.formatters.Logger.Logger()
Enrico Granata5a61fc0d2011-08-22 16:10:25 +000087 try:
88 return int(name.lstrip('[').rstrip(']'))
89 except:
90 return -1
Enrico Granata217f91f2011-08-17 19:07:52 +000091
92 def get_child_at_index(self,index):
Enrico Granata7d222212012-04-25 17:53:41 +000093 logger = lldb.formatters.Logger.Logger()
Enrico Granata22fe3172012-03-30 16:07:08 +000094 logger >> "Fetching child " + str(index)
Enrico Granata5a61fc0d2011-08-22 16:10:25 +000095 if index < 0:
96 return None;
Enrico Granata217f91f2011-08-17 19:07:52 +000097 if index >= self.num_children():
98 return None;
Enrico Granata5a61fc0d2011-08-22 16:10:25 +000099 try:
100 offset = index
101 current = self.next
102 while offset > 0:
103 current = current.GetChildMemberWithName('_M_next')
104 offset = offset - 1
105 return current.CreateChildAtOffset('['+str(index)+']',2*current.GetType().GetByteSize(),self.data_type)
106 except:
Enrico Granata23e578c2011-08-22 16:38:44 +0000107 return None
Enrico Granata217f91f2011-08-17 19:07:52 +0000108
Enrico Granata4cee9e52012-02-03 18:11:52 +0000109 def extract_type(self):
Enrico Granata7d222212012-04-25 17:53:41 +0000110 logger = lldb.formatters.Logger.Logger()
Enrico Granata4cee9e52012-02-03 18:11:52 +0000111 list_type = self.valobj.GetType().GetUnqualifiedType()
Enrico Granatac5bc4122012-03-27 02:35:13 +0000112 if list_type.IsReferenceType():
113 list_type = list_type.GetDereferencedType()
Enrico Granata4cee9e52012-02-03 18:11:52 +0000114 if list_type.GetNumberOfTemplateArguments() > 0:
115 data_type = list_type.GetTemplateArgumentType(0)
116 else:
117 data_type = None
118 return data_type
Enrico Granata217f91f2011-08-17 19:07:52 +0000119
120 def update(self):
Enrico Granata7d222212012-04-25 17:53:41 +0000121 logger = lldb.formatters.Logger.Logger()
Enrico Granata79c1baf2012-03-31 00:15:24 +0000122 # preemptively setting this to None - we might end up changing our mind later
123 self.count = None
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000124 try:
125 impl = self.valobj.GetChildMemberWithName('_M_impl')
126 node = impl.GetChildMemberWithName('_M_node')
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000127 self.node_address = self.valobj.AddressOf().GetValueAsUnsigned(0)
128 self.next = node.GetChildMemberWithName('_M_next')
129 self.prev = node.GetChildMemberWithName('_M_prev')
Enrico Granata4cee9e52012-02-03 18:11:52 +0000130 self.data_type = self.extract_type()
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000131 self.data_size = self.data_type.GetByteSize()
132 except:
133 pass
Enrico Granata217f91f2011-08-17 19:07:52 +0000134
Enrico Granata91fe0172012-10-23 21:54:53 +0000135 def has_children(self):
136 logger = lldb.formatters.Logger.Logger()
137 if self.count == None:
138 self.update ()
139 try:
140 next_val = self.next.GetValueAsUnsigned(0)
141 prev_val = self.prev.GetValueAsUnsigned(0)
142 if next_val == 0 or prev_val == 0:
143 return False
144 if next_val == self.node_address:
145 return False
146 # skip all the advanced logic to detect the exact count of children
147 # in the interest of speed from this point on, we MIGHT have children
148 # our loop detection logic will still make nothing show up :)
149 return True
150 except:
151 return False
152 if self.count == 0:
153 return False
154 return True
155
Enrico Granata217f91f2011-08-17 19:07:52 +0000156class StdVectorSynthProvider:
157
158 def __init__(self, valobj, dict):
Enrico Granata7d222212012-04-25 17:53:41 +0000159 logger = lldb.formatters.Logger.Logger()
Enrico Granatacb50d342012-04-10 00:11:03 +0000160 self.count = None
161 self.valobj = valobj
162 logger >> "Providing synthetic children for a map named " + str(valobj.GetName())
Enrico Granata217f91f2011-08-17 19:07:52 +0000163
164 def num_children(self):
Enrico Granata7d222212012-04-25 17:53:41 +0000165 logger = lldb.formatters.Logger.Logger()
Enrico Granata9d60f602012-03-09 03:09:58 +0000166 if self.count == None:
167 self.count = self.num_children_impl()
168 return self.count
169
170 def is_valid_pointer(ptr,process):
Enrico Granata7d222212012-04-25 17:53:41 +0000171 logger = lldb.formatters.Logger.Logger()
Enrico Granata9d60f602012-03-09 03:09:58 +0000172 error = lldb.SBError()
173 process.ReadMemory(ptr,1,error)
174 return False if error.Fail() else True
175
176 def num_children_impl(self):
Enrico Granata7d222212012-04-25 17:53:41 +0000177 logger = lldb.formatters.Logger.Logger()
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000178 try:
179 start_val = self.start.GetValueAsUnsigned(0)
180 finish_val = self.finish.GetValueAsUnsigned(0)
181 end_val = self.end.GetValueAsUnsigned(0)
182 # Before a vector has been constructed, it will contain bad values
183 # so we really need to be careful about the length we return since
184 # unitialized data can cause us to return a huge number. We need
185 # to also check for any of the start, finish or end of storage values
186 # being zero (NULL). If any are, then this vector has not been
187 # initialized yet and we should return zero
Enrico Granata217f91f2011-08-17 19:07:52 +0000188
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000189 # Make sure nothing is NULL
190 if start_val == 0 or finish_val == 0 or end_val == 0:
191 return 0
192 # Make sure start is less than finish
193 if start_val >= finish_val:
194 return 0
195 # Make sure finish is less than or equal to end of storage
196 if finish_val > end_val:
197 return 0
Enrico Granata217f91f2011-08-17 19:07:52 +0000198
Enrico Granata9d60f602012-03-09 03:09:58 +0000199 # if we have a struct (or other data type that the compiler pads to native word size)
200 # this check might fail, unless the sizeof() we get is itself incremented to take the
201 # padding bytes into account - on current clang it looks like this is the case
202 num_children = (finish_val-start_val)
203 if (num_children % self.data_size) != 0:
204 return 0
205 else:
206 num_children = num_children/self.data_size
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000207 return num_children
208 except:
209 return 0;
Enrico Granata217f91f2011-08-17 19:07:52 +0000210
211 def get_child_index(self,name):
Enrico Granata7d222212012-04-25 17:53:41 +0000212 logger = lldb.formatters.Logger.Logger()
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000213 try:
214 return int(name.lstrip('[').rstrip(']'))
215 except:
216 return -1
Enrico Granata217f91f2011-08-17 19:07:52 +0000217
218 def get_child_at_index(self,index):
Enrico Granata7d222212012-04-25 17:53:41 +0000219 logger = lldb.formatters.Logger.Logger()
Enrico Granata22fe3172012-03-30 16:07:08 +0000220 logger >> "Retrieving child " + str(index)
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000221 if index < 0:
222 return None;
Enrico Granata217f91f2011-08-17 19:07:52 +0000223 if index >= self.num_children():
224 return None;
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000225 try:
226 offset = index * self.data_size
227 return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type)
228 except:
229 return None
Enrico Granata217f91f2011-08-17 19:07:52 +0000230
231 def update(self):
Enrico Granata7d222212012-04-25 17:53:41 +0000232 logger = lldb.formatters.Logger.Logger()
Enrico Granata79c1baf2012-03-31 00:15:24 +0000233 # preemptively setting this to None - we might end up changing our mind later
234 self.count = None
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000235 try:
236 impl = self.valobj.GetChildMemberWithName('_M_impl')
237 self.start = impl.GetChildMemberWithName('_M_start')
238 self.finish = impl.GetChildMemberWithName('_M_finish')
239 self.end = impl.GetChildMemberWithName('_M_end_of_storage')
240 self.data_type = self.start.GetType().GetPointeeType()
241 self.data_size = self.data_type.GetByteSize()
Enrico Granata9d60f602012-03-09 03:09:58 +0000242 # if any of these objects is invalid, it means there is no point in trying to fetch anything
243 if self.start.IsValid() and self.finish.IsValid() and self.end.IsValid() and self.data_type.IsValid():
244 self.count = None
245 else:
246 self.count = 0
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000247 except:
248 pass
Enrico Granata91fe0172012-10-23 21:54:53 +0000249
250
251 def has_children(self):
252 return self.num_children() > 0
Enrico Granata217f91f2011-08-17 19:07:52 +0000253
254
255class StdMapSynthProvider:
256
257 def __init__(self, valobj, dict):
Enrico Granata7d222212012-04-25 17:53:41 +0000258 logger = lldb.formatters.Logger.Logger()
Enrico Granata217f91f2011-08-17 19:07:52 +0000259 self.valobj = valobj;
Enrico Granatacb50d342012-04-10 00:11:03 +0000260 self.count = None
Enrico Granatad50f18b2012-03-29 19:29:45 +0000261 logger >> "Providing synthetic children for a map named " + str(valobj.GetName())
Enrico Granata4cee9e52012-02-03 18:11:52 +0000262
263 # we need this function as a temporary workaround for rdar://problem/10801549
264 # which prevents us from extracting the std::pair<K,V> SBType out of the template
265 # arguments for _Rep_Type _M_t in the map itself - because we have to make up the
266 # typename and then find it, we may hit the situation were std::string has multiple
267 # names but only one is actually referenced in the debug information. hence, we need
268 # to replace the longer versions of std::string with the shorter one in order to be able
269 # to find the type name
270 def fixup_class_name(self, class_name):
Enrico Granata7d222212012-04-25 17:53:41 +0000271 logger = lldb.formatters.Logger.Logger()
Enrico Granata4cee9e52012-02-03 18:11:52 +0000272 if class_name == 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >':
Enrico Granatac5bc4122012-03-27 02:35:13 +0000273 return 'std::basic_string<char>',True
Enrico Granata4cee9e52012-02-03 18:11:52 +0000274 if class_name == 'basic_string<char, std::char_traits<char>, std::allocator<char> >':
Enrico Granatac5bc4122012-03-27 02:35:13 +0000275 return 'std::basic_string<char>',True
276 if class_name == 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >':
277 return 'std::basic_string<char>',True
278 if class_name == 'basic_string<char, std::char_traits<char>, std::allocator<char> >':
279 return 'std::basic_string<char>',True
280 return class_name,False
Enrico Granata217f91f2011-08-17 19:07:52 +0000281
282 def update(self):
Enrico Granata7d222212012-04-25 17:53:41 +0000283 logger = lldb.formatters.Logger.Logger()
Enrico Granata79c1baf2012-03-31 00:15:24 +0000284 # preemptively setting this to None - we might end up changing our mind later
285 self.count = None
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000286 try:
Enrico Granatad50f18b2012-03-29 19:29:45 +0000287 # we will set this to True if we find out that discovering a node in the map takes more steps than the overall size of the RB tree
288 # if this gets set to True, then we will merrily return None for any child from that moment on
289 self.garbage = False
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000290 self.Mt = self.valobj.GetChildMemberWithName('_M_t')
291 self.Mimpl = self.Mt.GetChildMemberWithName('_M_impl')
292 self.Mheader = self.Mimpl.GetChildMemberWithName('_M_header')
Enrico Granata4cee9e52012-02-03 18:11:52 +0000293
Enrico Granatac5bc4122012-03-27 02:35:13 +0000294 map_type = self.valobj.GetType()
295 if map_type.IsReferenceType():
Enrico Granata22fe3172012-03-30 16:07:08 +0000296 logger >> "Dereferencing type"
Enrico Granatac5bc4122012-03-27 02:35:13 +0000297 map_type = map_type.GetDereferencedType()
Enrico Granata4cee9e52012-02-03 18:11:52 +0000298
Enrico Granatac5bc4122012-03-27 02:35:13 +0000299 map_arg_0 = str(map_type.GetTemplateArgumentType(0).GetName())
300 map_arg_1 = str(map_type.GetTemplateArgumentType(1).GetName())
Enrico Granata4cee9e52012-02-03 18:11:52 +0000301
Enrico Granata22fe3172012-03-30 16:07:08 +0000302 logger >> "map has args " + str(map_arg_0) + " and " + str(map_arg_1)
303
Enrico Granatac5bc4122012-03-27 02:35:13 +0000304 map_arg_0,fixed_0 = self.fixup_class_name(map_arg_0)
305 map_arg_1,fixed_1 = self.fixup_class_name(map_arg_1)
306
Enrico Granata22fe3172012-03-30 16:07:08 +0000307 logger >> "arg_0 has become: " + str(map_arg_0) + " (fixed: " + str(fixed_0) + ")"
308 logger >> "arg_1 has become: " + str(map_arg_1) + " (fixed: " + str(fixed_1) + ")"
309
Enrico Granatac5bc4122012-03-27 02:35:13 +0000310 # HACK: this is related to the above issue with the typename for std::string
311 # being shortened by clang - the changes to typename display and searching to honor
312 # namespaces make it so that we go looking for std::pair<const std::basic_string<char>, ...>
313 # but when we find a type for this, we then compare it against the fully-qualified
314 # std::pair<const std::basic_string<char, std::char_traits... and of course fail
315 # the way to bypass this problem is to avoid using the std:: prefix in this specific case
316 if fixed_0 or fixed_1:
317 map_arg_type = "pair<const " + map_arg_0 + ", " + map_arg_1
318 else:
319 map_arg_type = "std::pair<const " + map_arg_0 + ", " + map_arg_1
320
Enrico Granata4cee9e52012-02-03 18:11:52 +0000321 if map_arg_1[-1] == '>':
322 map_arg_type = map_arg_type + " >"
323 else:
324 map_arg_type = map_arg_type + ">"
325
Enrico Granata22fe3172012-03-30 16:07:08 +0000326 logger >> "final contents datatype is: " + str(map_arg_type)
327
Enrico Granata4cee9e52012-02-03 18:11:52 +0000328 self.data_type = self.valobj.GetTarget().FindFirstType(map_arg_type)
329
Enrico Granata22fe3172012-03-30 16:07:08 +0000330 logger >> "and the SBType is: " + str(self.data_type)
331
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000332 # from libstdc++ implementation of _M_root for rbtree
333 self.Mroot = self.Mheader.GetChildMemberWithName('_M_parent')
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000334 self.data_size = self.data_type.GetByteSize()
335 self.skip_size = self.Mheader.GetType().GetByteSize()
336 except:
337 pass
Enrico Granata217f91f2011-08-17 19:07:52 +0000338
Enrico Granata217f91f2011-08-17 19:07:52 +0000339 def num_children(self):
Enrico Granatad50f18b2012-03-29 19:29:45 +0000340 global _map_capping_size
Enrico Granata7d222212012-04-25 17:53:41 +0000341 logger = lldb.formatters.Logger.Logger()
Enrico Granatad50f18b2012-03-29 19:29:45 +0000342 if self.count == None:
343 self.count = self.num_children_impl()
344 if self.count > _map_capping_size:
345 self.count = _map_capping_size
346 return self.count
347
348 def num_children_impl(self):
Enrico Granata7d222212012-04-25 17:53:41 +0000349 logger = lldb.formatters.Logger.Logger()
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000350 try:
351 root_ptr_val = self.node_ptr_value(self.Mroot)
352 if root_ptr_val == 0:
353 return 0;
Enrico Granatad50f18b2012-03-29 19:29:45 +0000354 count = self.Mimpl.GetChildMemberWithName('_M_node_count').GetValueAsUnsigned(0)
355 logger >> "I have " + str(count) + " children available"
356 return count
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000357 except:
Enrico Granata217f91f2011-08-17 19:07:52 +0000358 return 0;
Enrico Granata217f91f2011-08-17 19:07:52 +0000359
360 def get_child_index(self,name):
Enrico Granata7d222212012-04-25 17:53:41 +0000361 logger = lldb.formatters.Logger.Logger()
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000362 try:
363 return int(name.lstrip('[').rstrip(']'))
364 except:
365 return -1
Enrico Granata217f91f2011-08-17 19:07:52 +0000366
367 def get_child_at_index(self,index):
Enrico Granata7d222212012-04-25 17:53:41 +0000368 logger = lldb.formatters.Logger.Logger()
Enrico Granatad50f18b2012-03-29 19:29:45 +0000369 logger >> "Being asked to fetch child[" + str(index) + "]"
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000370 if index < 0:
371 return None
Enrico Granata217f91f2011-08-17 19:07:52 +0000372 if index >= self.num_children():
373 return None;
Enrico Granatad50f18b2012-03-29 19:29:45 +0000374 if self.garbage:
375 logger >> "Returning None since we are a garbage tree"
376 return None
Enrico Granata5a61fc0d2011-08-22 16:10:25 +0000377 try:
378 offset = index
379 current = self.left(self.Mheader);
380 while offset > 0:
381 current = self.increment_node(current)
382 offset = offset - 1;
383 # skip all the base stuff and get at the data
384 return current.CreateChildAtOffset('['+str(index)+']',self.skip_size,self.data_type)
385 except:
386 return None
Enrico Granata217f91f2011-08-17 19:07:52 +0000387
388 # utility functions
389 def node_ptr_value(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +0000390 logger = lldb.formatters.Logger.Logger()
Enrico Granata217f91f2011-08-17 19:07:52 +0000391 return node.GetValueAsUnsigned(0)
392
393 def right(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +0000394 logger = lldb.formatters.Logger.Logger()
Enrico Granata217f91f2011-08-17 19:07:52 +0000395 return node.GetChildMemberWithName("_M_right");
396
397 def left(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +0000398 logger = lldb.formatters.Logger.Logger()
Enrico Granata217f91f2011-08-17 19:07:52 +0000399 return node.GetChildMemberWithName("_M_left");
400
401 def parent(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +0000402 logger = lldb.formatters.Logger.Logger()
Enrico Granata217f91f2011-08-17 19:07:52 +0000403 return node.GetChildMemberWithName("_M_parent");
404
405 # from libstdc++ implementation of iterator for rbtree
406 def increment_node(self,node):
Enrico Granata7d222212012-04-25 17:53:41 +0000407 logger = lldb.formatters.Logger.Logger()
Enrico Granatad50f18b2012-03-29 19:29:45 +0000408 max_steps = self.num_children()
Enrico Granata217f91f2011-08-17 19:07:52 +0000409 if self.node_ptr_value(self.right(node)) != 0:
410 x = self.right(node);
Enrico Granatad50f18b2012-03-29 19:29:45 +0000411 max_steps -= 1
Enrico Granata217f91f2011-08-17 19:07:52 +0000412 while self.node_ptr_value(self.left(x)) != 0:
413 x = self.left(x);
Enrico Granatad50f18b2012-03-29 19:29:45 +0000414 max_steps -= 1
415 logger >> str(max_steps) + " more to go before giving up"
416 if max_steps <= 0:
417 self.garbage = True
418 return None
Enrico Granata217f91f2011-08-17 19:07:52 +0000419 return x;
420 else:
421 x = node;
422 y = self.parent(x)
Enrico Granatad50f18b2012-03-29 19:29:45 +0000423 max_steps -= 1
Enrico Granata217f91f2011-08-17 19:07:52 +0000424 while(self.node_ptr_value(x) == self.node_ptr_value(self.right(y))):
425 x = y;
426 y = self.parent(y);
Enrico Granatad50f18b2012-03-29 19:29:45 +0000427 max_steps -= 1
428 logger >> str(max_steps) + " more to go before giving up"
429 if max_steps <= 0:
430 self.garbage = True
431 return None
Enrico Granata217f91f2011-08-17 19:07:52 +0000432 if self.node_ptr_value(self.right(x)) != self.node_ptr_value(y):
433 x = y;
434 return x;
435
Enrico Granata91fe0172012-10-23 21:54:53 +0000436 def has_children(self):
437 return self.num_children() > 0
Enrico Granatad50f18b2012-03-29 19:29:45 +0000438
439_map_capping_size = 255
440_list_capping_size = 255
441_list_uses_loop_detector = True