pretty print BTreeSet
This commit is contained in:
parent
b47c314c56
commit
b6d4d40321
2 changed files with 49 additions and 0 deletions
|
@ -48,6 +48,7 @@ TYPE_KIND_FIXED_SIZE_VEC = 16
|
||||||
TYPE_KIND_REGULAR_UNION = 17
|
TYPE_KIND_REGULAR_UNION = 17
|
||||||
TYPE_KIND_OS_STRING = 18
|
TYPE_KIND_OS_STRING = 18
|
||||||
TYPE_KIND_STD_VECDEQUE = 19
|
TYPE_KIND_STD_VECDEQUE = 19
|
||||||
|
TYPE_KIND_STD_BTREESET = 20
|
||||||
|
|
||||||
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
|
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
|
||||||
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
|
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
|
||||||
|
@ -71,6 +72,9 @@ STD_VECDEQUE_FIELD_NAMES = [STD_VECDEQUE_FIELD_NAME_TAIL,
|
||||||
STD_VECDEQUE_FIELD_NAME_HEAD,
|
STD_VECDEQUE_FIELD_NAME_HEAD,
|
||||||
STD_VECDEQUE_FIELD_NAME_BUF]
|
STD_VECDEQUE_FIELD_NAME_BUF]
|
||||||
|
|
||||||
|
# std::collections::BTreeSet<> related constants
|
||||||
|
STD_BTREESET_FIELD_NAMES = ["map"]
|
||||||
|
|
||||||
# std::String related constants
|
# std::String related constants
|
||||||
STD_STRING_FIELD_NAMES = ["vec"]
|
STD_STRING_FIELD_NAMES = ["vec"]
|
||||||
|
|
||||||
|
@ -175,6 +179,11 @@ class Type(object):
|
||||||
self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)):
|
self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)):
|
||||||
return TYPE_KIND_STD_VECDEQUE
|
return TYPE_KIND_STD_VECDEQUE
|
||||||
|
|
||||||
|
# STD COLLECTION BTREESET
|
||||||
|
if (unqualified_type_name.startswith("BTreeSet<") and
|
||||||
|
self.__conforms_to_field_layout(STD_BTREESET_FIELD_NAMES)):
|
||||||
|
return TYPE_KIND_STD_BTREESET
|
||||||
|
|
||||||
# STD STRING
|
# STD STRING
|
||||||
if (unqualified_type_name.startswith("String") and
|
if (unqualified_type_name.startswith("String") and
|
||||||
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
|
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):
|
||||||
return (tail, head, data_ptr, capacity)
|
return (tail, head, data_ptr, capacity)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_length_and_ptr_from_std_btreeset(vec_val):
|
||||||
|
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREESET
|
||||||
|
map = vec_val.get_child_at_index(0)
|
||||||
|
root = map.get_child_at_index(0)
|
||||||
|
length = map.get_child_at_index(1).as_integer()
|
||||||
|
node = root.get_child_at_index(0)
|
||||||
|
ptr = node.get_child_at_index(0)
|
||||||
|
unique_ptr_val = ptr.get_child_at_index(0)
|
||||||
|
data_ptr = unique_ptr_val.get_child_at_index(0)
|
||||||
|
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
|
||||||
|
return (length, data_ptr)
|
||||||
|
|
||||||
|
|
||||||
def extract_length_and_ptr_from_slice(slice_val):
|
def extract_length_and_ptr_from_slice(slice_val):
|
||||||
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
|
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
|
||||||
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
|
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
|
||||||
|
|
|
@ -127,6 +127,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
|
||||||
if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE:
|
if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE:
|
||||||
return RustStdVecDequePrinter(val)
|
return RustStdVecDequePrinter(val)
|
||||||
|
|
||||||
|
if type_kind == rustpp.TYPE_KIND_STD_BTREESET:
|
||||||
|
return RustStdBTreeSetPrinter(val)
|
||||||
|
|
||||||
if type_kind == rustpp.TYPE_KIND_STD_STRING:
|
if type_kind == rustpp.TYPE_KIND_STD_STRING:
|
||||||
return RustStdStringPrinter(val)
|
return RustStdStringPrinter(val)
|
||||||
|
|
||||||
|
@ -299,6 +302,30 @@ class RustStdVecDequePrinter(object):
|
||||||
yield (str(index), (gdb_ptr + index).dereference())
|
yield (str(index), (gdb_ptr + index).dereference())
|
||||||
|
|
||||||
|
|
||||||
|
class RustStdBTreeSetPrinter(object):
|
||||||
|
def __init__(self, val):
|
||||||
|
self.__val = val
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def display_hint():
|
||||||
|
return "map"
|
||||||
|
|
||||||
|
def to_string(self):
|
||||||
|
(length, data_ptr) = \
|
||||||
|
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
|
||||||
|
return (self.__val.type.get_unqualified_type_name() +
|
||||||
|
(" with %i elements" % length))
|
||||||
|
|
||||||
|
def children(self):
|
||||||
|
(length, data_ptr) = \
|
||||||
|
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
|
||||||
|
val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(0)
|
||||||
|
gdb_ptr = val.get_wrapped_value()
|
||||||
|
for index in xrange(length):
|
||||||
|
yield (str(index), str(index))
|
||||||
|
yield (str(index), gdb_ptr[index])
|
||||||
|
|
||||||
|
|
||||||
class RustStdStringPrinter(object):
|
class RustStdStringPrinter(object):
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.__val = val
|
self.__val = val
|
||||||
|
|
Loading…
Add table
Reference in a new issue