Skip to content

Commit b6d4d40

Browse files
committed
pretty print BTreeSet
1 parent b47c314 commit b6d4d40

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/etc/debugger_pretty_printers_common.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
TYPE_KIND_REGULAR_UNION = 17
4949
TYPE_KIND_OS_STRING = 18
5050
TYPE_KIND_STD_VECDEQUE = 19
51+
TYPE_KIND_STD_BTREESET = 20
5152

5253
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
5354
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
@@ -71,6 +72,9 @@
7172
STD_VECDEQUE_FIELD_NAME_HEAD,
7273
STD_VECDEQUE_FIELD_NAME_BUF]
7374

75+
# std::collections::BTreeSet<> related constants
76+
STD_BTREESET_FIELD_NAMES = ["map"]
77+
7478
# std::String related constants
7579
STD_STRING_FIELD_NAMES = ["vec"]
7680

@@ -175,6 +179,11 @@ def __classify_struct(self):
175179
self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)):
176180
return TYPE_KIND_STD_VECDEQUE
177181

182+
# STD COLLECTION BTREESET
183+
if (unqualified_type_name.startswith("BTreeSet<") and
184+
self.__conforms_to_field_layout(STD_BTREESET_FIELD_NAMES)):
185+
return TYPE_KIND_STD_BTREESET
186+
178187
# STD STRING
179188
if (unqualified_type_name.startswith("String") and
180189
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
@@ -358,6 +367,19 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
358367
return (tail, head, data_ptr, capacity)
359368

360369

370+
def extract_length_and_ptr_from_std_btreeset(vec_val):
371+
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREESET
372+
map = vec_val.get_child_at_index(0)
373+
root = map.get_child_at_index(0)
374+
length = map.get_child_at_index(1).as_integer()
375+
node = root.get_child_at_index(0)
376+
ptr = node.get_child_at_index(0)
377+
unique_ptr_val = ptr.get_child_at_index(0)
378+
data_ptr = unique_ptr_val.get_child_at_index(0)
379+
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
380+
return (length, data_ptr)
381+
382+
361383
def extract_length_and_ptr_from_slice(slice_val):
362384
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
363385
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)

src/etc/gdb_rust_pretty_printing.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
127127
if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE:
128128
return RustStdVecDequePrinter(val)
129129

130+
if type_kind == rustpp.TYPE_KIND_STD_BTREESET:
131+
return RustStdBTreeSetPrinter(val)
132+
130133
if type_kind == rustpp.TYPE_KIND_STD_STRING:
131134
return RustStdStringPrinter(val)
132135

@@ -299,6 +302,30 @@ def children(self):
299302
yield (str(index), (gdb_ptr + index).dereference())
300303

301304

305+
class RustStdBTreeSetPrinter(object):
306+
def __init__(self, val):
307+
self.__val = val
308+
309+
@staticmethod
310+
def display_hint():
311+
return "map"
312+
313+
def to_string(self):
314+
(length, data_ptr) = \
315+
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
316+
return (self.__val.type.get_unqualified_type_name() +
317+
(" with %i elements" % length))
318+
319+
def children(self):
320+
(length, data_ptr) = \
321+
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
322+
val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(0)
323+
gdb_ptr = val.get_wrapped_value()
324+
for index in xrange(length):
325+
yield (str(index), str(index))
326+
yield (str(index), gdb_ptr[index])
327+
328+
302329
class RustStdStringPrinter(object):
303330
def __init__(self, val):
304331
self.__val = val

0 commit comments

Comments
 (0)