From b6d4d403217d8ef7ff98f21924819880efed56f0 Mon Sep 17 00:00:00 2001 From: fukatani Date: Mon, 6 Aug 2018 23:00:19 +0900 Subject: [PATCH 1/4] pretty print BTreeSet --- src/etc/debugger_pretty_printers_common.py | 22 ++++++++++++++++++ src/etc/gdb_rust_pretty_printing.py | 27 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/etc/debugger_pretty_printers_common.py b/src/etc/debugger_pretty_printers_common.py index 87c7b21bb8a35..e64d863717da0 100644 --- a/src/etc/debugger_pretty_printers_common.py +++ b/src/etc/debugger_pretty_printers_common.py @@ -48,6 +48,7 @@ TYPE_KIND_REGULAR_UNION = 17 TYPE_KIND_OS_STRING = 18 TYPE_KIND_STD_VECDEQUE = 19 +TYPE_KIND_STD_BTREESET = 20 ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$" ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR" @@ -71,6 +72,9 @@ STD_VECDEQUE_FIELD_NAME_HEAD, STD_VECDEQUE_FIELD_NAME_BUF] +# std::collections::BTreeSet<> related constants +STD_BTREESET_FIELD_NAMES = ["map"] + # std::String related constants STD_STRING_FIELD_NAMES = ["vec"] @@ -175,6 +179,11 @@ def __classify_struct(self): self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)): return TYPE_KIND_STD_VECDEQUE + # STD COLLECTION BTREESET + if (unqualified_type_name.startswith("BTreeSet<") and + self.__conforms_to_field_layout(STD_BTREESET_FIELD_NAMES)): + return TYPE_KIND_STD_BTREESET + # STD STRING if (unqualified_type_name.startswith("String") and self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)): @@ -358,6 +367,19 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val): return (tail, head, data_ptr, capacity) +def extract_length_and_ptr_from_std_btreeset(vec_val): + assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREESET + map = vec_val.get_child_at_index(0) + root = map.get_child_at_index(0) + length = map.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) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index b7de42a938417..8d9af89a74399 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -127,6 +127,9 @@ def rust_pretty_printer_lookup_function(gdb_val): if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE: return RustStdVecDequePrinter(val) + if type_kind == rustpp.TYPE_KIND_STD_BTREESET: + return RustStdBTreeSetPrinter(val) + if type_kind == rustpp.TYPE_KIND_STD_STRING: return RustStdStringPrinter(val) @@ -299,6 +302,30 @@ def children(self): yield (str(index), (gdb_ptr + index).dereference()) +class RustStdBTreeSetPrinter(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_btreeset(self.__val) + return (self.__val.type.get_unqualified_type_name() + + (" with %i elements" % length)) + + def children(self): + (length, data_ptr) = \ + rustpp.extract_length_and_ptr_from_std_btreeset(self.__val) + val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(0) + gdb_ptr = val.get_wrapped_value() + for index in xrange(length): + yield (str(index), str(index)) + yield (str(index), gdb_ptr[index]) + + class RustStdStringPrinter(object): def __init__(self, val): self.__val = val From 73436a7233e5a6ce2b2f98ee9747662eaeadb082 Mon Sep 17 00:00:00 2001 From: fukatani Date: Tue, 7 Aug 2018 22:05:32 +0900 Subject: [PATCH 2/4] add gdb test for std::collections --- src/test/debuginfo/pretty-std-collections.rs | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/test/debuginfo/pretty-std-collections.rs diff --git a/src/test/debuginfo/pretty-std-collections.rs b/src/test/debuginfo/pretty-std-collections.rs new file mode 100644 index 0000000000000..ca01b823b44e8 --- /dev/null +++ b/src/test/debuginfo/pretty-std-collections.rs @@ -0,0 +1,50 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-windows failing on win32 bot +// ignore-freebsd: gdb package too new +// ignore-android: FIXME(#10381) +// compile-flags:-g +// min-gdb-version 7.7 +// min-lldb-version: 310 + +// === GDB TESTS =================================================================================== + +// gdb-command: run + +// gdb-command: print btree_set +// gdb-check:$1 = BTreeSet with 3 elements = {[0] = 3, [1] = 5, [2] = 7} + +// gdb-command: print vec_deque +// gdb-check:$2 = VecDeque(len: 3, cap: 8) = {5, 3, 7} + +#![allow(unused_variables)] +use std::collections::BTreeSet; +use std::collections::VecDeque; + + +fn main() { + + // BTreeSet + let mut btree_set = BTreeSet::new(); + btree_set.insert(5); + btree_set.insert(3); + btree_set.insert(7); + + // VecDeque + let mut vec_deque = VecDeque::new(); + vec_deque.push_back(5); + vec_deque.push_back(3); + vec_deque.push_back(7); + + zzz(); // #break +} + +fn zzz() { () } From b95f6f2e8f33f82a84638cdebd3bdb5500458573 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Aug 2018 17:30:09 +0900 Subject: [PATCH 3/4] bug fix --- src/etc/gdb_rust_pretty_printing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index 8d9af89a74399..53face7dbcc12 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -319,7 +319,7 @@ def to_string(self): def children(self): (length, data_ptr) = \ rustpp.extract_length_and_ptr_from_std_btreeset(self.__val) - val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(0) + val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3) gdb_ptr = val.get_wrapped_value() for index in xrange(length): yield (str(index), str(index)) From 6e562d24c6a2849516745da540fdebe832c114ee Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Aug 2018 23:01:48 +0900 Subject: [PATCH 4/4] fix behavior --- src/etc/gdb_rust_pretty_printing.py | 5 ++--- src/test/debuginfo/pretty-std-collections.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index 53face7dbcc12..fae1fd0cac30d 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -308,13 +308,13 @@ def __init__(self, val): @staticmethod def display_hint(): - return "map" + return "array" def to_string(self): (length, data_ptr) = \ rustpp.extract_length_and_ptr_from_std_btreeset(self.__val) return (self.__val.type.get_unqualified_type_name() + - (" with %i elements" % length)) + ("(len: %i)" % length)) def children(self): (length, data_ptr) = \ @@ -322,7 +322,6 @@ def children(self): val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3) gdb_ptr = val.get_wrapped_value() for index in xrange(length): - yield (str(index), str(index)) yield (str(index), gdb_ptr[index]) diff --git a/src/test/debuginfo/pretty-std-collections.rs b/src/test/debuginfo/pretty-std-collections.rs index ca01b823b44e8..18d73bf5677bc 100644 --- a/src/test/debuginfo/pretty-std-collections.rs +++ b/src/test/debuginfo/pretty-std-collections.rs @@ -20,7 +20,7 @@ // gdb-command: run // gdb-command: print btree_set -// gdb-check:$1 = BTreeSet with 3 elements = {[0] = 3, [1] = 5, [2] = 7} +// gdb-check:$1 = BTreeSet(len: 3) = {3, 5, 7} // gdb-command: print vec_deque // gdb-check:$2 = VecDeque(len: 3, cap: 8) = {5, 3, 7}