mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Rollup merge of #53357 - fukatani:pretty-print-btreemap, r=michaelwoerister
Pretty print btreemap for GDB Merge #53112 first, please.
This commit is contained in:
commit
18122e0db0
@ -49,6 +49,7 @@ TYPE_KIND_REGULAR_UNION = 17
|
||||
TYPE_KIND_OS_STRING = 18
|
||||
TYPE_KIND_STD_VECDEQUE = 19
|
||||
TYPE_KIND_STD_BTREESET = 20
|
||||
TYPE_KIND_STD_BTREEMAP = 21
|
||||
|
||||
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
|
||||
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
|
||||
@ -75,6 +76,9 @@ STD_VECDEQUE_FIELD_NAMES = [STD_VECDEQUE_FIELD_NAME_TAIL,
|
||||
# std::collections::BTreeSet<> related constants
|
||||
STD_BTREESET_FIELD_NAMES = ["map"]
|
||||
|
||||
# std::collections::BTreeMap<> related constants
|
||||
STD_BTREEMAP_FIELD_NAMES = ["root", "length"]
|
||||
|
||||
# std::String related constants
|
||||
STD_STRING_FIELD_NAMES = ["vec"]
|
||||
|
||||
@ -184,6 +188,11 @@ class Type(object):
|
||||
self.__conforms_to_field_layout(STD_BTREESET_FIELD_NAMES)):
|
||||
return TYPE_KIND_STD_BTREESET
|
||||
|
||||
# STD COLLECTION BTREEMAP
|
||||
if (unqualified_type_name.startswith("BTreeMap<") and
|
||||
self.__conforms_to_field_layout(STD_BTREEMAP_FIELD_NAMES)):
|
||||
return TYPE_KIND_STD_BTREEMAP
|
||||
|
||||
# STD STRING
|
||||
if (unqualified_type_name.startswith("String") and
|
||||
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
|
||||
@ -380,6 +389,18 @@ def extract_length_and_ptr_from_std_btreeset(vec_val):
|
||||
return (length, data_ptr)
|
||||
|
||||
|
||||
def extract_length_and_ptr_from_std_btreemap(vec_val):
|
||||
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREEMAP
|
||||
root = vec_val.get_child_at_index(0)
|
||||
length = vec_val.get_child_at_index(1).as_integer()
|
||||
node = root.get_child_at_index(0)
|
||||
ptr = node.get_child_at_index(0)
|
||||
unique_ptr_val = ptr.get_child_at_index(0)
|
||||
data_ptr = unique_ptr_val.get_child_at_index(0)
|
||||
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
|
||||
return (length, data_ptr)
|
||||
|
||||
|
||||
def extract_length_and_ptr_from_slice(slice_val):
|
||||
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
|
||||
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
|
||||
|
@ -130,6 +130,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
|
||||
if type_kind == rustpp.TYPE_KIND_STD_BTREESET:
|
||||
return RustStdBTreeSetPrinter(val)
|
||||
|
||||
if type_kind == rustpp.TYPE_KIND_STD_BTREEMAP:
|
||||
return RustStdBTreeMapPrinter(val)
|
||||
|
||||
if type_kind == rustpp.TYPE_KIND_STD_STRING:
|
||||
return RustStdStringPrinter(val)
|
||||
|
||||
@ -325,6 +328,32 @@ class RustStdBTreeSetPrinter(object):
|
||||
yield (str(index), gdb_ptr[index])
|
||||
|
||||
|
||||
class RustStdBTreeMapPrinter(object):
|
||||
def __init__(self, val):
|
||||
self.__val = val
|
||||
|
||||
@staticmethod
|
||||
def display_hint():
|
||||
return "map"
|
||||
|
||||
def to_string(self):
|
||||
(length, data_ptr) = \
|
||||
rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
|
||||
return (self.__val.type.get_unqualified_type_name() +
|
||||
("(len: %i)" % length))
|
||||
|
||||
def children(self):
|
||||
(length, data_ptr) = \
|
||||
rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
|
||||
keys = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
|
||||
keys_ptr = keys.get_wrapped_value()
|
||||
vals = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(4)
|
||||
vals_ptr = vals.get_wrapped_value()
|
||||
for index in xrange(length):
|
||||
yield (str(index), keys_ptr[index])
|
||||
yield (str(index), vals_ptr[index])
|
||||
|
||||
|
||||
class RustStdStringPrinter(object):
|
||||
def __init__(self, val):
|
||||
self.__val = val
|
||||
@ -338,6 +367,7 @@ class RustStdStringPrinter(object):
|
||||
def display_hint(self):
|
||||
return "string"
|
||||
|
||||
|
||||
class RustOsStringPrinter(object):
|
||||
def __init__(self, val):
|
||||
self.__val = val
|
||||
|
@ -22,11 +22,15 @@
|
||||
// gdb-command: print btree_set
|
||||
// gdb-check:$1 = BTreeSet<i32>(len: 3) = {3, 5, 7}
|
||||
|
||||
// gdb-command: print btree_map
|
||||
// gdb-check:$2 = BTreeMap<i32, i32>(len: 3) = {[3] = 3, [5] = 7, [7] = 4}
|
||||
|
||||
// gdb-command: print vec_deque
|
||||
// gdb-check:$2 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
|
||||
// gdb-check:$3 = VecDeque<i32>(len: 3, cap: 8) = {5, 3, 7}
|
||||
|
||||
#![allow(unused_variables)]
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
|
||||
@ -38,6 +42,12 @@ fn main() {
|
||||
btree_set.insert(3);
|
||||
btree_set.insert(7);
|
||||
|
||||
// BTreeMap
|
||||
let mut btree_map = BTreeMap::new();
|
||||
btree_map.insert(5, 7);
|
||||
btree_map.insert(3, 3);
|
||||
btree_map.insert(7, 4);
|
||||
|
||||
// VecDeque
|
||||
let mut vec_deque = VecDeque::new();
|
||||
vec_deque.push_back(5);
|
||||
|
Loading…
Reference in New Issue
Block a user