Skip to content

Commit

Permalink
Fix debugger pretty printing of BTrees
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Mar 20, 2020
1 parent 4d85314 commit bce7f6f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
34 changes: 21 additions & 13 deletions src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,17 @@ def to_string(self):
("(len: %i)" % self.__val.get_wrapped_value()['map']['length']))

def children(self):
root = self.__val.get_wrapped_value()['map']['root']
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], False):
yield (str(i), child)
i = i + 1
prev_idx = None
innermap = GdbValue(self.__val.get_wrapped_value()['map'])
if innermap.get_wrapped_value()['length'] > 0:
root = GdbValue(innermap.get_wrapped_value()['root'])
type_name = str(root.type.ty.name).replace('core::option::Option<', '')[:-1]
root = root.get_wrapped_value().cast(gdb.lookup_type(type_name))
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], False):
yield (str(i), child)
i = i + 1


class RustStdBTreeMapPrinter(object):
Expand All @@ -391,13 +396,16 @@ def to_string(self):
("(len: %i)" % self.__val.get_wrapped_value()['length']))

def children(self):
root = self.__val.get_wrapped_value()['root']
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], True):
yield (str(i), child[0])
yield (str(i), child[1])
i = i + 1
if self.__val.get_wrapped_value()['length'] > 0:
root = GdbValue(self.__val.get_wrapped_value()['root'])
type_name = str(root.type.ty.name).replace('core::option::Option<', '')[:-1]
root = root.get_wrapped_value().cast(gdb.lookup_type(type_name))
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], True):
yield (str(i), child[0])
yield (str(i), child[1])
i = i + 1


class RustStdStringPrinter(object):
Expand Down
24 changes: 17 additions & 7 deletions src/test/debuginfo/pretty-std-collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,43 @@
// gdb-command: print btree_set
// gdb-check:$1 = BTreeSet<i32>(len: 15) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}

// gdb-command: print empty_btree_set
// gdb-check:$2 = BTreeSet<i32>(len: 0)

// gdb-command: print btree_map
// 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}
// 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}

// gdb-command: print empty_btree_map
// gdb-check:$4 = BTreeMap<i32, u32>(len: 0)

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

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

#![allow(unused_variables)]
use std::collections::BTreeSet;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;


fn main() {

// BTreeSet
let mut btree_set = BTreeSet::new();
for i in 0..15 {
btree_set.insert(i);
}

let mut empty_btree_set: BTreeSet<i32> = BTreeSet::new();

// BTreeMap
let mut btree_map = BTreeMap::new();
for i in 0..15 {
btree_map.insert(i, i);
}

let mut empty_btree_map: BTreeMap<i32, u32> = BTreeMap::new();

// VecDeque
let mut vec_deque = VecDeque::new();
vec_deque.push_back(5);
Expand All @@ -63,4 +71,6 @@ fn main() {
zzz(); // #break
}

fn zzz() { () }
fn zzz() {
()
}

0 comments on commit bce7f6f

Please sign in to comment.