Rollup merge of #77932 - ssomers:btree_cleanup_gdb, r=Mark-Simulacrum

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

I accidentally pushed an earlier revision in #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
This commit is contained in:
Dylan DPC 2020-10-17 03:27:18 +02:00 committed by GitHub
commit 16b878fd0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 20 deletions

View File

@ -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

View File

@ -229,8 +229,8 @@ def children_of_node(boxed_node, height):
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
@ -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:
@ -258,8 +255,8 @@ class StdBTreeSetProvider:
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():
@ -274,8 +271,9 @@ class StdBTreeMapProvider:
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():

View File

@ -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 ==================================================================================
@ -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();