TYPE_KIND_OS_STRING = 18
TYPE_KIND_STD_VECDEQUE = 19
TYPE_KIND_STD_BTREESET = 20
+TYPE_KIND_STD_BTREEMAP = 21
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
# std::collections::BTreeSet<> related constants
STD_BTREESET_FIELD_NAMES = ["map"]
+# std::collections::BTreeMap<> related constants
+STD_BTREEMAP_FIELD_NAMES = ["root", "length"]
+
# std::String related constants
STD_STRING_FIELD_NAMES = ["vec"]
self.__conforms_to_field_layout(STD_BTREESET_FIELD_NAMES)):
return TYPE_KIND_STD_BTREESET
+ # STD COLLECTION BTREEMAP
+ if (unqualified_type_name.startswith("BTreeMap<") and
+ self.__conforms_to_field_layout(STD_BTREEMAP_FIELD_NAMES)):
+ return TYPE_KIND_STD_BTREEMAP
+
# STD STRING
if (unqualified_type_name.startswith("String") and
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
return (length, data_ptr)
+def extract_length_and_ptr_from_std_btreemap(vec_val):
+ assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREEMAP
+ root = vec_val.get_child_at_index(0)
+ length = vec_val.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):
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
if type_kind == rustpp.TYPE_KIND_STD_BTREESET:
return RustStdBTreeSetPrinter(val)
+ if type_kind == rustpp.TYPE_KIND_STD_BTREEMAP:
+ return RustStdBTreeMapPrinter(val)
+
if type_kind == rustpp.TYPE_KIND_STD_STRING:
return RustStdStringPrinter(val)
yield (str(index), gdb_ptr[index])
+class RustStdBTreeMapPrinter(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_btreemap(self.__val)
+ return (self.__val.type.get_unqualified_type_name() +
+ ("(len: %i)" % length))
+
+ def children(self):
+ (length, data_ptr) = \
+ rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
+ keys = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
+ keys_ptr = keys.get_wrapped_value()
+ vals = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(4)
+ vals_ptr = vals.get_wrapped_value()
+ for index in xrange(length):
+ yield (str(index), keys_ptr[index])
+ yield (str(index), vals_ptr[index])
+
+
class RustStdStringPrinter(object):
def __init__(self, val):
self.__val = val
def display_hint(self):
return "string"
+
class RustOsStringPrinter(object):
def __init__(self, val):
self.__val = val
// gdb-command: print btree_set
// gdb-check:$1 = BTreeSet<i32>(len: 3) = {3, 5, 7}
+// gdb-command: print btree_map
+// gdb-check:$2 = BTreeMap<i32, i32>(len: 3) = {[3] = 3, [5] = 7, [7] = 4}
+
// gdb-command: print vec_deque
-// gdb-check:$2 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
+// gdb-check:$3 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
#![allow(unused_variables)]
use std::collections::BTreeSet;
+use std::collections::BTreeMap;
use std::collections::VecDeque;
btree_set.insert(3);
btree_set.insert(7);
+ // BTreeMap
+ let mut btree_map = BTreeMap::new();
+ btree_map.insert(5, 7);
+ btree_map.insert(3, 3);
+ btree_map.insert(7, 4);
+
// VecDeque
let mut vec_deque = VecDeque::new();
vec_deque.push_back(5);