about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-11-25 17:05:04 +0100
committerGitHub <noreply@github.com>2018-11-25 17:05:04 +0100
commited6c7b751dd427d6b10825c9d6bbcca08e769fa9 (patch)
treeedb071d761f94eaa2f7f95942b978cd99e7d362b
parent6398df1520638c68bb75daa33d64c75387c26b1f (diff)
parentd4ee1c93ff25a7fa6f5e35dc774a648a7e6d578e (diff)
downloadrust-ed6c7b751dd427d6b10825c9d6bbcca08e769fa9.tar.gz
rust-ed6c7b751dd427d6b10825c9d6bbcca08e769fa9.zip
Rollup merge of #56144 - tromey:Bug-55771-btreemap, r=alexcrichton
Fix BTreeSet and BTreeMap gdb pretty-printers

The BTreeSet and BTreeMap gdb pretty-printers did not take the node
structure into account, and consequently only worked for shallow sets.
This fixes the problem by iterating over child nodes when needed.

This patch avoids the current approach of implementing some of the
value manipulations in debugger-indepdendent code.  This was done for
convenience: a type lookup was needed for the first time, and there
currently are no lldb formatters for these types.

Closes #55771
-rw-r--r--src/etc/debugger_pretty_printers_common.py26
-rwxr-xr-xsrc/etc/gdb_rust_pretty_printing.py70
-rw-r--r--src/test/debuginfo/pretty-std-collections.rs17
3 files changed, 50 insertions, 63 deletions
diff --git a/src/etc/debugger_pretty_printers_common.py b/src/etc/debugger_pretty_printers_common.py
index 1797f6708ac..b99e401929e 100644
--- a/src/etc/debugger_pretty_printers_common.py
+++ b/src/etc/debugger_pretty_printers_common.py
@@ -375,32 +375,6 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
     assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
     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_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)
diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py
index 4c746536547..a376c8593f4 100755
--- a/src/etc/gdb_rust_pretty_printing.py
+++ b/src/etc/gdb_rust_pretty_printing.py
@@ -319,6 +319,32 @@ class RustStdVecDequePrinter(object):
             yield (str(index), (gdb_ptr + ((tail + index) % cap)).dereference())
 
 
+# Yield each key (and optionally value) from a BoxedNode.
+def children_of_node(boxed_node, height, want_values):
+    ptr = boxed_node['ptr']['pointer']
+    # This is written oddly because we don't want to rely on the field name being `__0`.
+    node_ptr = ptr[ptr.type.fields()[0]]
+    if height > 0:
+        type_name = str(node_ptr.type.target()).replace('LeafNode', 'InternalNode')
+        node_type = gdb.lookup_type(type_name)
+        node_ptr = node_ptr.cast(node_type.pointer())
+        leaf = node_ptr['data']
+    else:
+        leaf = node_ptr.dereference()
+    keys = leaf['keys']['value']['value']
+    if want_values:
+        values = leaf['vals']['value']['value']
+    length = int(leaf['len'])
+    for i in xrange(0, length + 1):
+        if height > 0:
+            for child in children_of_node(node_ptr['edges'][i], height - 1, want_values):
+                yield child
+        if i < length:
+            if want_values:
+                yield (keys[i], values[i])
+            else:
+                yield keys[i]
+
 class RustStdBTreeSetPrinter(object):
     def __init__(self, val):
         self.__val = val
@@ -328,21 +354,16 @@ class RustStdBTreeSetPrinter(object):
         return "array"
 
     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() +
-                ("(len: %i)" % length))
+                ("(len: %i)" % self.__val.get_wrapped_value()['map']['length']))
 
     def children(self):
-        (length, data_ptr) = \
-            rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
-        leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
-        maybe_uninit_keys = leaf_node.get_child_at_index(3)
-        manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
-        keys = manually_drop_keys.get_child_at_index(0)
-        gdb_ptr = keys.get_wrapped_value()
-        for index in xrange(length):
-            yield (str(index), gdb_ptr[index])
+        root = self.__val.get_wrapped_value()['map']['root']
+        node_ptr = root['node']
+        i = 0
+        for child in children_of_node(node_ptr, root['height'], False):
+            yield (str(i), child)
+            i = i + 1
 
 
 class RustStdBTreeMapPrinter(object):
@@ -354,26 +375,17 @@ class RustStdBTreeMapPrinter(object):
         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))
+                ("(len: %i)" % self.__val.get_wrapped_value()['length']))
 
     def children(self):
-        (length, data_ptr) = \
-            rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
-        leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
-        maybe_uninit_keys = leaf_node.get_child_at_index(3)
-        manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
-        keys = manually_drop_keys.get_child_at_index(0)
-        keys_ptr = keys.get_wrapped_value()
-        maybe_uninit_vals = leaf_node.get_child_at_index(4)
-        manually_drop_vals = maybe_uninit_vals.get_child_at_index(1)
-        vals = manually_drop_vals.get_child_at_index(0)
-        vals_ptr = vals.get_wrapped_value()
-        for index in xrange(length):
-            yield (str(index), keys_ptr[index])
-            yield (str(index), vals_ptr[index])
+        root = self.__val.get_wrapped_value()['root']
+        node_ptr = root['node']
+        i = 0
+        for child in children_of_node(node_ptr, root['height'], True):
+            yield (str(i), child[0])
+            yield (str(i), child[1])
+            i = i + 1
 
 
 class RustStdStringPrinter(object):
diff --git a/src/test/debuginfo/pretty-std-collections.rs b/src/test/debuginfo/pretty-std-collections.rs
index 0d3f4b90f23..a51be370aa4 100644
--- a/src/test/debuginfo/pretty-std-collections.rs
+++ b/src/test/debuginfo/pretty-std-collections.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-tidy-linelength
 // ignore-windows failing on win32 bot
 // ignore-freebsd: gdb package too new
 // ignore-android: FIXME(#10381)
@@ -20,10 +21,10 @@
 // gdb-command: run
 
 // gdb-command: print btree_set
-// gdb-check:$1 = BTreeSet<i32>(len: 3) = {3, 5, 7}
+// gdb-check:$1 = BTreeSet<i32>(len: 15) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
 
 // gdb-command: print btree_map
-// gdb-check:$2 = BTreeMap<i32, i32>(len: 3) = {[3] = 3, [5] = 7, [7] = 4}
+// gdb-check:$2 = BTreeMap<i32, i32>(len: 15) = {[0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9, [10] = 10, [11] = 11, [12] = 12, [13] = 13, [14] = 14}
 
 // gdb-command: print vec_deque
 // gdb-check:$3 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
@@ -41,15 +42,15 @@ fn main() {
 
     // BTreeSet
     let mut btree_set = BTreeSet::new();
-    btree_set.insert(5);
-    btree_set.insert(3);
-    btree_set.insert(7);
+    for i in 0..15 {
+        btree_set.insert(i);
+    }
 
     // BTreeMap
     let mut btree_map = BTreeMap::new();
-    btree_map.insert(5, 7);
-    btree_map.insert(3, 3);
-    btree_map.insert(7, 4);
+    for i in 0..15 {
+        btree_map.insert(i, i);
+    }
 
     // VecDeque
     let mut vec_deque = VecDeque::new();