Skip to content

Commit db7a697

Browse files
Fix debugger pretty printing of BTrees
1 parent 416fd43 commit db7a697

File tree

2 files changed

+56
-20
lines changed

2 files changed

+56
-20
lines changed

src/etc/gdb_rust_pretty_printing.py

+39-13
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,25 @@ def to_string(self):
370370
("(len: %i)" % self.__val.get_wrapped_value()['map']['length']))
371371

372372
def children(self):
373-
root = self.__val.get_wrapped_value()['map']['root']
374-
node_ptr = root['node']
375-
i = 0
376-
for child in children_of_node(node_ptr, root['height'], False):
377-
yield (str(i), child)
378-
i = i + 1
373+
if self.__val.get_wrapped_value()['map']['length'] > 0:
374+
root = self.__val.get_wrapped_value()['map']['root']
375+
# get at `Option` innards
376+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
377+
# pull out the `Some` variant of the enum
378+
try:
379+
root = root['Some']
380+
except:
381+
# Do nothing, we just want to pull out Some if it exists.
382+
# If it didn't, then it seems at least on some versions of gdb
383+
# we don't actually need to do the above line, so just skip it.
384+
pass
385+
# And now the value of the Some variant
386+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
387+
node_ptr = root['node']
388+
i = 0
389+
for child in children_of_node(node_ptr, root['height'], False):
390+
yield (str(i), child)
391+
i = i + 1
379392

380393

381394
class RustStdBTreeMapPrinter(object):
@@ -391,13 +404,26 @@ def to_string(self):
391404
("(len: %i)" % self.__val.get_wrapped_value()['length']))
392405

393406
def children(self):
394-
root = self.__val.get_wrapped_value()['root']
395-
node_ptr = root['node']
396-
i = 0
397-
for child in children_of_node(node_ptr, root['height'], True):
398-
yield (str(i), child[0])
399-
yield (str(i), child[1])
400-
i = i + 1
407+
if self.__val.get_wrapped_value()['length'] > 0:
408+
root = self.__val.get_wrapped_value()['root']
409+
# get at `Option` innards
410+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
411+
# pull out the `Some` variant of the enum
412+
try:
413+
root = root['Some']
414+
except:
415+
# Do nothing, we just want to pull out Some if it exists.
416+
# If it didn't, then it seems at least on some versions of gdb
417+
# we don't actually need to do the above line, so just skip it.
418+
pass
419+
# And now the value of the Some variant
420+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
421+
node_ptr = root['node']
422+
i = 0
423+
for child in children_of_node(node_ptr, root['height'], True):
424+
yield (str(i), child[0])
425+
yield (str(i), child[1])
426+
i = i + 1
401427

402428

403429
class RustStdStringPrinter(object):

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

+17-7
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,43 @@
1717
// gdb-command: print btree_set
1818
// gdb-check:$1 = BTreeSet<i32>(len: 15) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
1919

20+
// gdb-command: print empty_btree_set
21+
// gdb-check:$2 = BTreeSet<i32>(len: 0)
22+
2023
// gdb-command: print btree_map
21-
// 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}
24+
// gdb-check:$3 = 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}
25+
26+
// gdb-command: print empty_btree_map
27+
// gdb-check:$4 = BTreeMap<i32, u32>(len: 0)
2228

2329
// gdb-command: print vec_deque
24-
// gdb-check:$3 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
30+
// gdb-check:$5 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
2531

2632
// gdb-command: print vec_deque2
27-
// gdb-check:$4 = VecDeque<i32>(len: 7, cap: 8) = {2, 3, 4, 5, 6, 7, 8}
33+
// gdb-check:$6 = VecDeque<i32>(len: 7, cap: 8) = {2, 3, 4, 5, 6, 7, 8}
2834

2935
#![allow(unused_variables)]
30-
use std::collections::BTreeSet;
3136
use std::collections::BTreeMap;
37+
use std::collections::BTreeSet;
3238
use std::collections::VecDeque;
3339

34-
3540
fn main() {
36-
3741
// BTreeSet
3842
let mut btree_set = BTreeSet::new();
3943
for i in 0..15 {
4044
btree_set.insert(i);
4145
}
4246

47+
let mut empty_btree_set: BTreeSet<i32> = BTreeSet::new();
48+
4349
// BTreeMap
4450
let mut btree_map = BTreeMap::new();
4551
for i in 0..15 {
4652
btree_map.insert(i, i);
4753
}
4854

55+
let mut empty_btree_map: BTreeMap<i32, u32> = BTreeMap::new();
56+
4957
// VecDeque
5058
let mut vec_deque = VecDeque::new();
5159
vec_deque.push_back(5);
@@ -63,4 +71,6 @@ fn main() {
6371
zzz(); // #break
6472
}
6573

66-
fn zzz() { () }
74+
fn zzz() {
75+
()
76+
}

0 commit comments

Comments
 (0)