Skip to content

Commit

Permalink
Test pretty printing more and fix overzealous type substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
ssomers committed Jan 21, 2020
1 parent 5e8897b commit 44f52ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
44 changes: 24 additions & 20 deletions src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,27 +333,31 @@ def children(self):
# Yield each key (and optionally value) from a BoxedNode.
def children_of_node(boxed_node, height, want_values):
node_ptr = boxed_node['ptr']['pointer']
if height > 0:
type_name = str(node_ptr.type.target()).replace('LeafNode', 'InternalNode')
node_type = gdb.lookup_type(type_name)
node_ptr = node_ptr.cast(node_type.pointer())
leaf = node_ptr['data']
else:
leaf = node_ptr.dereference()
keys = leaf['keys']
if want_values:
values = leaf['vals']
length = int(leaf['len'])
for i in xrange(0, length + 1):
head = node_ptr.dereference()
length = int(head['len'])
if length > 0:
if height > 0:
child_ptr = node_ptr['edges'][i]['value']['value']
for child in children_of_node(child_ptr, height - 1, want_values):
yield child
if i < length:
if want_values:
yield (keys[i]['value']['value'], values[i]['value']['value'])
else:
yield keys[i]['value']['value']
type_name = str(node_ptr.type.target()).replace('LeafNode', 'InternalNode', 1)
node_type = gdb.lookup_type(type_name)
node_ptr = node_ptr.cast(node_type.pointer())
leaf = node_ptr['data']
edges = node_ptr['edges']
else:
leaf = node_ptr.dereference()
edges = None
keys = leaf['keys']
if want_values:
values = leaf['vals']
for i in xrange(0, length + 1):
if edges:
child_ptr = edges[i]['value']['value']
for child in children_of_node(child_ptr, height - 1, want_values):
yield child
if i < length:
if want_values:
yield (keys[i]['value']['value'], values[i]['value']['value'])
else:
yield keys[i]['value']['value']

class RustStdBTreeSetPrinter(object):
def __init__(self, val):
Expand Down
21 changes: 16 additions & 5 deletions src/test/debuginfo/pretty-std-collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@
// 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-command: print empty_btree_map
// gdb-check:$3 = BTreeMap<(), ()>(len: 0)

// gdb-command: print nasty_btree_map
// gdb-check:$4 = BTreeMap<i32, pretty_std_collections::MyLeafNode>(len: 1) = {[1] = pretty_std_collections::MyLeafNode (11)}

// 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;

struct MyLeafNode(i32); // helps to ensure we don't blindly replace substring "LeafNode"

fn main() {

// BTreeSet
let mut btree_set = BTreeSet::new();
for i in 0..15 {
Expand All @@ -45,6 +51,9 @@ fn main() {
for i in 0..15 {
btree_map.insert(i, i);
}
let empty_btree_map: BTreeMap<(), ()> = BTreeMap::new();
let mut nasty_btree_map: BTreeMap<i32, MyLeafNode> = BTreeMap::new();
nasty_btree_map.insert(1, MyLeafNode(11));

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

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

0 comments on commit 44f52ee

Please sign in to comment.