Skip to content

Commit 16b878f

Browse files
authored
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
2 parents 446686f + 28af355 commit 16b878f

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

library/alloc/src/collections/btree/node.rs

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ impl<K, V> LeafNode<K, V> {
8787
#[repr(C)]
8888
// gdb_providers.py uses this type name for introspection.
8989
struct InternalNode<K, V> {
90-
// gdb_providers.py uses this field name for introspection.
9190
data: LeafNode<K, V>,
9291

9392
/// The pointers to the children of this node. `len + 1` of these are considered

src/etc/gdb_providers.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ def cast_to_internal(node):
229229
yield child
230230
if i < length:
231231
# Avoid "Cannot perform pointer math on incomplete type" on zero-sized arrays.
232-
key = keys[i]["value"]["value"] if keys.type.sizeof > 0 else None
233-
val = vals[i]["value"]["value"] if vals.type.sizeof > 0 else None
232+
key = keys[i]["value"]["value"] if keys.type.sizeof > 0 else "()"
233+
val = vals[i]["value"]["value"] if vals.type.sizeof > 0 else "()"
234234
yield key, val
235235

236236

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

251248

252249
class StdBTreeSetProvider:
@@ -258,8 +255,8 @@ def to_string(self):
258255

259256
def children(self):
260257
inner_map = self.valobj["map"]
261-
for child in children_of_map(inner_map):
262-
yield child
258+
for i, (child, _) in enumerate(children_of_map(inner_map)):
259+
yield "[{}]".format(i), child
263260

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

276273
def children(self):
277-
for child in children_of_map(self.valobj):
278-
yield child
274+
for i, (key, val) in enumerate(children_of_map(self.valobj)):
275+
yield "key{}".format(i), key
276+
yield "val{}".format(i), val
279277

280278
@staticmethod
281279
def display_hint():

src/test/debuginfo/pretty-std-collections.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,26 @@
3434
// gdb-check:$6 = BTreeMap(size=15) = {[0] = pretty_std_collections::MyLeafNode (0), [...]}
3535
// (abbreviated because it's boring but we need enough elements to include internal nodes)
3636

37-
// gdb-command: print zst_btree_map
38-
// gdb-check:$7 = BTreeMap(size=1)
37+
// gdb-command: print zst_key_btree_map
38+
// gdb-check:$7 = BTreeMap(size=1) = {[()] = 1}
39+
40+
// gdb-command: print zst_val_btree_map
41+
// gdb-check:$8 = BTreeMap(size=1) = {[1] = ()}
42+
43+
// gdb-command: print zst_key_val_btree_map
44+
// gdb-check:$9 = BTreeMap(size=1) = {[()] = ()}
3945

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

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

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

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

5258
// === LLDB TESTS ==================================================================================
5359

@@ -114,8 +120,14 @@ fn main() {
114120
nasty_btree_map.insert(i, MyLeafNode(i));
115121
}
116122

117-
let mut zst_btree_map: BTreeMap<(), ()> = BTreeMap::new();
118-
zst_btree_map.insert((), ());
123+
let mut zst_key_btree_map: BTreeMap<(), i32> = BTreeMap::new();
124+
zst_key_btree_map.insert((), 1);
125+
126+
let mut zst_val_btree_map: BTreeMap<i32, ()> = BTreeMap::new();
127+
zst_val_btree_map.insert(1, ());
128+
129+
let mut zst_key_val_btree_map: BTreeMap<(), ()> = BTreeMap::new();
130+
zst_key_val_btree_map.insert((), ());
119131

120132
// VecDeque
121133
let mut vec_deque = VecDeque::new();

0 commit comments

Comments
 (0)