]> git.lizzy.rs Git - rust.git/commitdiff
pretty printing for btreemap
authorUnknown <nannyakannya@gmail.com>
Tue, 14 Aug 2018 16:38:00 +0000 (01:38 +0900)
committerfukatani <nannyakannya@gmail.com>
Wed, 15 Aug 2018 04:48:10 +0000 (13:48 +0900)
src/etc/debugger_pretty_printers_common.py
src/etc/gdb_rust_pretty_printing.py
src/test/debuginfo/pretty-std-collections.rs

index e64d863717da0019773a6eb0c861ebfd15d32aa1..1797f6708ac5b4745fcc2300fc3653b68c1320bc 100644 (file)
@@ -49,6 +49,7 @@ TYPE_KIND_REGULAR_UNION     = 17
 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"
@@ -75,6 +76,9 @@ STD_VECDEQUE_FIELD_NAMES = [STD_VECDEQUE_FIELD_NAME_TAIL,
 # 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"]
 
@@ -184,6 +188,11 @@ class Type(object):
                 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)):
@@ -380,6 +389,18 @@ def extract_length_and_ptr_from_std_btreeset(vec_val):
     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)
index fae1fd0cac30dde40b36f28e31a5b1a9215d340c..216915dba5fe7c03116d1cf2906afd7bbafe392f 100755 (executable)
@@ -130,6 +130,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
     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)
 
@@ -325,6 +328,32 @@ class RustStdBTreeSetPrinter(object):
             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
@@ -338,6 +367,7 @@ class RustStdStringPrinter(object):
     def display_hint(self):
         return "string"
 
+
 class RustOsStringPrinter(object):
     def __init__(self, val):
         self.__val = val
index 18d73bf5677bce950c35c9dece69f5837e0cc0ce..8e37a884b34bbe24171fee585e1b98f1e8a394c3 100644 (file)
 // 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;
 
 
@@ -38,6 +42,12 @@ fn main() {
     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);