about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-08-01 10:12:42 +0200
committerGitHub <noreply@github.com>2018-08-01 10:12:42 +0200
commit39406ee241714085bfcd2aa0bec2a6c75c28c01a (patch)
treeadd94b38b70c88464ff9e96ff6932596b599cdbb
parent333d8c456c507cdbf31f790d56524126ae112e0d (diff)
parent9845ee08867e3527b9e57c86b08d38d5a0db255a (diff)
downloadrust-39406ee241714085bfcd2aa0bec2a6c75c28c01a.tar.gz
rust-39406ee241714085bfcd2aa0bec2a6c75c28c01a.zip
Rollup merge of #52821 - fukatani:gdb-vecdeque-print, r=michaelwoerister
pretty print for std::collections::vecdeque

I want pretty print function for VecDeque like Vec.

```rust
use std::collections::VecDeque;

fn main() {
    let mut d: VecDeque<i32> = VecDeque::new();
    d.push_back(4);
    d.push_back(4);
    d.push_back(6);
    let mut v: Vec<i32> = Vec::new();
    v.push(4);
    v.push(4);
    v.push(6);
}
```

```
(gdb) p v
$1 = Vec<i32>(len: 3, cap: 4) = {4, 4, 6}
(gdb) p d
$2 = VecDeque<i32>(len: 3, cap: 8) = {4, 4, 6}
```

Thanks.
-rw-r--r--src/etc/debugger_pretty_printers_common.py33
-rwxr-xr-xsrc/etc/gdb_rust_pretty_printing.py25
2 files changed, 58 insertions, 0 deletions
diff --git a/src/etc/debugger_pretty_printers_common.py b/src/etc/debugger_pretty_printers_common.py
index 4a38d4be083..87c7b21bb8a 100644
--- a/src/etc/debugger_pretty_printers_common.py
+++ b/src/etc/debugger_pretty_printers_common.py
@@ -47,6 +47,7 @@ TYPE_KIND_PTR               = 15
 TYPE_KIND_FIXED_SIZE_VEC    = 16
 TYPE_KIND_REGULAR_UNION     = 17
 TYPE_KIND_OS_STRING         = 18
+TYPE_KIND_STD_VECDEQUE      = 19
 
 ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
 ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
@@ -62,6 +63,14 @@ STD_VEC_FIELD_NAME_BUF = "buf"
 STD_VEC_FIELD_NAMES = [STD_VEC_FIELD_NAME_BUF,
                        STD_VEC_FIELD_NAME_LENGTH]
 
+# std::collections::VecDeque<> related constants
+STD_VECDEQUE_FIELD_NAME_TAIL = "tail"
+STD_VECDEQUE_FIELD_NAME_HEAD = "head"
+STD_VECDEQUE_FIELD_NAME_BUF = "buf"
+STD_VECDEQUE_FIELD_NAMES = [STD_VECDEQUE_FIELD_NAME_TAIL,
+                            STD_VECDEQUE_FIELD_NAME_HEAD,
+                            STD_VECDEQUE_FIELD_NAME_BUF]
+
 # std::String related constants
 STD_STRING_FIELD_NAMES = ["vec"]
 
@@ -161,6 +170,11 @@ class Type(object):
             self.__conforms_to_field_layout(STD_VEC_FIELD_NAMES)):
             return TYPE_KIND_STD_VEC
 
+        # STD COLLECTION VECDEQUE
+        if (unqualified_type_name.startswith("VecDeque<") and
+            self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)):
+            return TYPE_KIND_STD_VECDEQUE
+
         # STD STRING
         if (unqualified_type_name.startswith("String") and
             self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
@@ -325,6 +339,25 @@ def extract_length_ptr_and_cap_from_std_vec(vec_val):
     assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
     return (length, data_ptr, capacity)
 
+
+def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
+    assert vec_val.type.get_type_kind() == TYPE_KIND_STD_VECDEQUE
+    tail_field_index = STD_VECDEQUE_FIELD_NAMES.index(STD_VECDEQUE_FIELD_NAME_TAIL)
+    head_field_index = STD_VECDEQUE_FIELD_NAMES.index(STD_VECDEQUE_FIELD_NAME_HEAD)
+    buf_field_index = STD_VECDEQUE_FIELD_NAMES.index(STD_VECDEQUE_FIELD_NAME_BUF)
+
+    tail = vec_val.get_child_at_index(tail_field_index).as_integer()
+    head = vec_val.get_child_at_index(head_field_index).as_integer()
+    buf = vec_val.get_child_at_index(buf_field_index)
+
+    vec_ptr_val = buf.get_child_at_index(0)
+    capacity = buf.get_child_at_index(1).as_integer()
+    unique_ptr_val = vec_ptr_val.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 (tail, head, data_ptr, capacity)
+
+
 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 0612873e281..b7de42a9384 100755
--- a/src/etc/gdb_rust_pretty_printing.py
+++ b/src/etc/gdb_rust_pretty_printing.py
@@ -124,6 +124,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
     if type_kind == rustpp.TYPE_KIND_STD_VEC:
         return RustStdVecPrinter(val)
 
+    if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE:
+        return RustStdVecDequePrinter(val)
+
     if type_kind == rustpp.TYPE_KIND_STD_STRING:
         return RustStdStringPrinter(val)
 
@@ -274,6 +277,28 @@ class RustStdVecPrinter(object):
             yield (str(index), (gdb_ptr + index).dereference())
 
 
+class RustStdVecDequePrinter(object):
+    def __init__(self, val):
+        self.__val = val
+
+    @staticmethod
+    def display_hint():
+        return "array"
+
+    def to_string(self):
+        (tail, head, data_ptr, cap) = \
+            rustpp.extract_tail_head_ptr_and_cap_from_std_vecdeque(self.__val)
+        return (self.__val.type.get_unqualified_type_name() +
+                ("(len: %i, cap: %i)" % (head - tail, cap)))
+
+    def children(self):
+        (tail, head, data_ptr, cap) = \
+            rustpp.extract_tail_head_ptr_and_cap_from_std_vecdeque(self.__val)
+        gdb_ptr = data_ptr.get_wrapped_value()
+        for index in xrange(tail, head):
+            yield (str(index), (gdb_ptr + index).dereference())
+
+
 class RustStdStringPrinter(object):
     def __init__(self, val):
         self.__val = val