Skip to content

Commit

Permalink
Rollup merge of rust-lang#77932 - ssomers:btree_cleanup_gdb, r=Mark-S…
Browse files Browse the repository at this point in the history
…imulacrum

BTreeMap: improve gdb introspection of BTreeMap with ZST keys or values

I accidentally pushed an earlier revision in rust-lang#77788: it changes the index of tuples for BTreeSet from ""[{}]".format(i) to "key{}".format(i). Which doesn't seem to make the slightest difference on my linux box nor on CI. In fact, gdb doesn't make any distinction between "key{}" and "val{}" for a BTreeMap either, leading to confusing output if you test more. But easy to improve.

r? @Mark-Simulacrum
  • Loading branch information
Dylan-DPC committed Oct 17, 2020
2 parents 446686f + 28af355 commit 16b878f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
1 change: 0 additions & 1 deletion library/alloc/src/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ impl<K, V> LeafNode<K, V> {
#[repr(C)]
// gdb_providers.py uses this type name for introspection.
struct InternalNode<K, V> {
// gdb_providers.py uses this field name for introspection.
data: LeafNode<K, V>,

/// The pointers to the children of this node. `len + 1` of these are considered
Expand Down
20 changes: 9 additions & 11 deletions src/etc/gdb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def cast_to_internal(node):
yield child
if i < length:
# Avoid "Cannot perform pointer math on incomplete type" on zero-sized arrays.
key = keys[i]["value"]["value"] if keys.type.sizeof > 0 else None
val = vals[i]["value"]["value"] if vals.type.sizeof > 0 else None
key = keys[i]["value"]["value"] if keys.type.sizeof > 0 else "()"
val = vals[i]["value"]["value"] if vals.type.sizeof > 0 else "()"
yield key, val


Expand All @@ -242,11 +242,8 @@ def children_of_map(map):
root = root.cast(gdb.lookup_type(root.type.name[21:-1]))
boxed_root_node = root["node"]
height = root["height"]
for i, (key, val) in enumerate(children_of_node(boxed_root_node, height)):
if key is not None:
yield "key{}".format(i), key
if val is not None:
yield "val{}".format(i), val
for child in children_of_node(boxed_root_node, height):
yield child


class StdBTreeSetProvider:
Expand All @@ -258,8 +255,8 @@ def to_string(self):

def children(self):
inner_map = self.valobj["map"]
for child in children_of_map(inner_map):
yield child
for i, (child, _) in enumerate(children_of_map(inner_map)):
yield "[{}]".format(i), child

@staticmethod
def display_hint():
Expand All @@ -274,8 +271,9 @@ def to_string(self):
return "BTreeMap(size={})".format(self.valobj["length"])

def children(self):
for child in children_of_map(self.valobj):
yield child
for i, (key, val) in enumerate(children_of_map(self.valobj)):
yield "key{}".format(i), key
yield "val{}".format(i), val

@staticmethod
def display_hint():
Expand Down
28 changes: 20 additions & 8 deletions src/test/debuginfo/pretty-std-collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,26 @@
// gdb-check:$6 = BTreeMap(size=15) = {[0] = pretty_std_collections::MyLeafNode (0), [...]}
// (abbreviated because it's boring but we need enough elements to include internal nodes)

// gdb-command: print zst_btree_map
// gdb-check:$7 = BTreeMap(size=1)
// gdb-command: print zst_key_btree_map
// gdb-check:$7 = BTreeMap(size=1) = {[()] = 1}

// gdb-command: print zst_val_btree_map
// gdb-check:$8 = BTreeMap(size=1) = {[1] = ()}

// gdb-command: print zst_key_val_btree_map
// gdb-check:$9 = BTreeMap(size=1) = {[()] = ()}

// gdb-command: print vec_deque
// gdb-check:$8 = VecDeque(size=3) = {5, 3, 7}
// gdb-check:$10 = VecDeque(size=3) = {5, 3, 7}

// gdb-command: print vec_deque2
// gdb-check:$9 = VecDeque(size=7) = {2, 3, 4, 5, 6, 7, 8}
// gdb-check:$11 = VecDeque(size=7) = {2, 3, 4, 5, 6, 7, 8}

// gdb-command: print hash_map
// gdb-check:$10 = HashMap(size=4) = {[1] = 10, [2] = 20, [3] = 30, [4] = 40}
// gdb-check:$12 = HashMap(size=4) = {[1] = 10, [2] = 20, [3] = 30, [4] = 40}

// gdb-command: print hash_set
// gdb-check:$11 = HashSet(size=4) = {1, 2, 3, 4}
// gdb-check:$13 = HashSet(size=4) = {1, 2, 3, 4}

// === LLDB TESTS ==================================================================================

Expand Down Expand Up @@ -114,8 +120,14 @@ fn main() {
nasty_btree_map.insert(i, MyLeafNode(i));
}

let mut zst_btree_map: BTreeMap<(), ()> = BTreeMap::new();
zst_btree_map.insert((), ());
let mut zst_key_btree_map: BTreeMap<(), i32> = BTreeMap::new();
zst_key_btree_map.insert((), 1);

let mut zst_val_btree_map: BTreeMap<i32, ()> = BTreeMap::new();
zst_val_btree_map.insert(1, ());

let mut zst_key_val_btree_map: BTreeMap<(), ()> = BTreeMap::new();
zst_key_val_btree_map.insert((), ());

// VecDeque
let mut vec_deque = VecDeque::new();
Expand Down

0 comments on commit 16b878f

Please sign in to comment.