Skip to content

Commit ed6c7b7

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#55771
2 parents 6398df1 + d4ee1c9 commit ed6c7b7

File tree

3 files changed

+50
-63
lines changed

3 files changed

+50
-63
lines changed

src/etc/debugger_pretty_printers_common.py

-26
Original file line numberDiff line numberDiff line change
@@ -375,32 +375,6 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
375375
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
376376
return (tail, head, data_ptr, capacity)
377377

378-
379-
def extract_length_and_ptr_from_std_btreeset(vec_val):
380-
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREESET
381-
map = vec_val.get_child_at_index(0)
382-
root = map.get_child_at_index(0)
383-
length = map.get_child_at_index(1).as_integer()
384-
node = root.get_child_at_index(0)
385-
ptr = node.get_child_at_index(0)
386-
unique_ptr_val = ptr.get_child_at_index(0)
387-
data_ptr = unique_ptr_val.get_child_at_index(0)
388-
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
389-
return (length, data_ptr)
390-
391-
392-
def extract_length_and_ptr_from_std_btreemap(vec_val):
393-
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREEMAP
394-
root = vec_val.get_child_at_index(0)
395-
length = vec_val.get_child_at_index(1).as_integer()
396-
node = root.get_child_at_index(0)
397-
ptr = node.get_child_at_index(0)
398-
unique_ptr_val = ptr.get_child_at_index(0)
399-
data_ptr = unique_ptr_val.get_child_at_index(0)
400-
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
401-
return (length, data_ptr)
402-
403-
404378
def extract_length_and_ptr_from_slice(slice_val):
405379
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
406380
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)

src/etc/gdb_rust_pretty_printing.py

+41-29
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,32 @@ def children(self):
319319
yield (str(index), (gdb_ptr + ((tail + index) % cap)).dereference())
320320

321321

322+
# Yield each key (and optionally value) from a BoxedNode.
323+
def children_of_node(boxed_node, height, want_values):
324+
ptr = boxed_node['ptr']['pointer']
325+
# This is written oddly because we don't want to rely on the field name being `__0`.
326+
node_ptr = ptr[ptr.type.fields()[0]]
327+
if height > 0:
328+
type_name = str(node_ptr.type.target()).replace('LeafNode', 'InternalNode')
329+
node_type = gdb.lookup_type(type_name)
330+
node_ptr = node_ptr.cast(node_type.pointer())
331+
leaf = node_ptr['data']
332+
else:
333+
leaf = node_ptr.dereference()
334+
keys = leaf['keys']['value']['value']
335+
if want_values:
336+
values = leaf['vals']['value']['value']
337+
length = int(leaf['len'])
338+
for i in xrange(0, length + 1):
339+
if height > 0:
340+
for child in children_of_node(node_ptr['edges'][i], height - 1, want_values):
341+
yield child
342+
if i < length:
343+
if want_values:
344+
yield (keys[i], values[i])
345+
else:
346+
yield keys[i]
347+
322348
class RustStdBTreeSetPrinter(object):
323349
def __init__(self, val):
324350
self.__val = val
@@ -328,21 +354,16 @@ def display_hint():
328354
return "array"
329355

330356
def to_string(self):
331-
(length, data_ptr) = \
332-
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
333357
return (self.__val.type.get_unqualified_type_name() +
334-
("(len: %i)" % length))
358+
("(len: %i)" % self.__val.get_wrapped_value()['map']['length']))
335359

336360
def children(self):
337-
(length, data_ptr) = \
338-
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
339-
leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
340-
maybe_uninit_keys = leaf_node.get_child_at_index(3)
341-
manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
342-
keys = manually_drop_keys.get_child_at_index(0)
343-
gdb_ptr = keys.get_wrapped_value()
344-
for index in xrange(length):
345-
yield (str(index), gdb_ptr[index])
361+
root = self.__val.get_wrapped_value()['map']['root']
362+
node_ptr = root['node']
363+
i = 0
364+
for child in children_of_node(node_ptr, root['height'], False):
365+
yield (str(i), child)
366+
i = i + 1
346367

347368

348369
class RustStdBTreeMapPrinter(object):
@@ -354,26 +375,17 @@ def display_hint():
354375
return "map"
355376

356377
def to_string(self):
357-
(length, data_ptr) = \
358-
rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
359378
return (self.__val.type.get_unqualified_type_name() +
360-
("(len: %i)" % length))
379+
("(len: %i)" % self.__val.get_wrapped_value()['length']))
361380

362381
def children(self):
363-
(length, data_ptr) = \
364-
rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
365-
leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
366-
maybe_uninit_keys = leaf_node.get_child_at_index(3)
367-
manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
368-
keys = manually_drop_keys.get_child_at_index(0)
369-
keys_ptr = keys.get_wrapped_value()
370-
maybe_uninit_vals = leaf_node.get_child_at_index(4)
371-
manually_drop_vals = maybe_uninit_vals.get_child_at_index(1)
372-
vals = manually_drop_vals.get_child_at_index(0)
373-
vals_ptr = vals.get_wrapped_value()
374-
for index in xrange(length):
375-
yield (str(index), keys_ptr[index])
376-
yield (str(index), vals_ptr[index])
382+
root = self.__val.get_wrapped_value()['root']
383+
node_ptr = root['node']
384+
i = 0
385+
for child in children_of_node(node_ptr, root['height'], True):
386+
yield (str(i), child[0])
387+
yield (str(i), child[1])
388+
i = i + 1
377389

378390

379391
class RustStdStringPrinter(object):

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
1112
// ignore-windows failing on win32 bot
1213
// ignore-freebsd: gdb package too new
1314
// ignore-android: FIXME(#10381)
@@ -20,10 +21,10 @@
2021
// gdb-command: run
2122

2223
// gdb-command: print btree_set
23-
// gdb-check:$1 = BTreeSet<i32>(len: 3) = {3, 5, 7}
24+
// gdb-check:$1 = BTreeSet<i32>(len: 15) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
2425

2526
// gdb-command: print btree_map
26-
// gdb-check:$2 = BTreeMap<i32, i32>(len: 3) = {[3] = 3, [5] = 7, [7] = 4}
27+
// 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}
2728

2829
// gdb-command: print vec_deque
2930
// gdb-check:$3 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
@@ -41,15 +42,15 @@ fn main() {
4142

4243
// BTreeSet
4344
let mut btree_set = BTreeSet::new();
44-
btree_set.insert(5);
45-
btree_set.insert(3);
46-
btree_set.insert(7);
45+
for i in 0..15 {
46+
btree_set.insert(i);
47+
}
4748

4849
// BTreeMap
4950
let mut btree_map = BTreeMap::new();
50-
btree_map.insert(5, 7);
51-
btree_map.insert(3, 3);
52-
btree_map.insert(7, 4);
51+
for i in 0..15 {
52+
btree_map.insert(i, i);
53+
}
5354

5455
// VecDeque
5556
let mut vec_deque = VecDeque::new();

0 commit comments

Comments
 (0)