Skip to content

Commit b6d3143

Browse files
committed
pretty print for std::collections::vecdeque
1 parent 6a2c97c commit b6d3143

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/etc/debugger_pretty_printers_common.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
TYPE_KIND_FIXED_SIZE_VEC = 16
4848
TYPE_KIND_REGULAR_UNION = 17
4949
TYPE_KIND_OS_STRING = 18
50+
TYPE_KIND_STD_VECDEQUE = 19
5051

5152
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
5253
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
@@ -62,6 +63,14 @@
6263
STD_VEC_FIELD_NAMES = [STD_VEC_FIELD_NAME_BUF,
6364
STD_VEC_FIELD_NAME_LENGTH]
6465

66+
# std::collections::VecDeque<> related constants
67+
STD_VECDEQUE_FIELD_NAME_TAIL = "tail"
68+
STD_VECDEQUE_FIELD_NAME_HEAD = "head"
69+
STD_VECDEQUE_FIELD_NAME_BUF = "buf"
70+
STD_VECDEQUE_FIELD_NAMES = [STD_VECDEQUE_FIELD_NAME_TAIL,
71+
STD_VECDEQUE_FIELD_NAME_HEAD,
72+
STD_VECDEQUE_FIELD_NAME_BUF]
73+
6574
# std::String related constants
6675
STD_STRING_FIELD_NAMES = ["vec"]
6776

@@ -161,6 +170,11 @@ def __classify_struct(self):
161170
self.__conforms_to_field_layout(STD_VEC_FIELD_NAMES)):
162171
return TYPE_KIND_STD_VEC
163172

173+
# STD COLLECTION VECDEQUE
174+
if (unqualified_type_name.startswith("VecDeque<") and
175+
self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)):
176+
return TYPE_KIND_STD_VECDEQUE
177+
164178
# STD STRING
165179
if (unqualified_type_name.startswith("String") and
166180
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
@@ -325,6 +339,25 @@ def extract_length_ptr_and_cap_from_std_vec(vec_val):
325339
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
326340
return (length, data_ptr, capacity)
327341

342+
343+
def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
344+
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_VECDEQUE
345+
tail_field_index = STD_VECDEQUE_FIELD_NAMES.index(STD_VECDEQUE_FIELD_NAME_TAIL)
346+
head_field_index = STD_VECDEQUE_FIELD_NAMES.index(STD_VECDEQUE_FIELD_NAME_HEAD)
347+
buf_field_index = STD_VECDEQUE_FIELD_NAMES.index(STD_VECDEQUE_FIELD_NAME_BUF)
348+
349+
tail = vec_val.get_child_at_index(tail_field_index).as_integer()
350+
head = vec_val.get_child_at_index(head_field_index).as_integer()
351+
buf = vec_val.get_child_at_index(buf_field_index)
352+
353+
vec_ptr_val = buf.get_child_at_index(0)
354+
capacity = buf.get_child_at_index(1).as_integer()
355+
unique_ptr_val = vec_ptr_val.get_child_at_index(0)
356+
data_ptr = unique_ptr_val.get_child_at_index(0)
357+
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
358+
return (tail, head, data_ptr, capacity)
359+
360+
328361
def extract_length_and_ptr_from_slice(slice_val):
329362
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
330363
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)

src/etc/gdb_rust_pretty_printing.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
124124
if type_kind == rustpp.TYPE_KIND_STD_VEC:
125125
return RustStdVecPrinter(val)
126126

127+
if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE:
128+
return RustStdVecDequePrinter(val)
129+
127130
if type_kind == rustpp.TYPE_KIND_STD_STRING:
128131
return RustStdStringPrinter(val)
129132

@@ -274,6 +277,26 @@ def children(self):
274277
yield (str(index), (gdb_ptr + index).dereference())
275278

276279

280+
class RustStdVecDequePrinter(object):
281+
def __init__(self, val):
282+
self.__val = val
283+
284+
@staticmethod
285+
def display_hint():
286+
return "array"
287+
288+
def to_string(self):
289+
(tail, head, data_ptr, cap) = rustpp.extract_tail_head_ptr_and_cap_from_std_vecdeque(self.__val)
290+
return (self.__val.type.get_unqualified_type_name() +
291+
("(len: %i, cap: %i)" % (head - tail, cap)))
292+
293+
def children(self):
294+
(tail, head, data_ptr, cap) = rustpp.extract_tail_head_ptr_and_cap_from_std_vecdeque(self.__val)
295+
gdb_ptr = data_ptr.get_wrapped_value()
296+
for index in xrange(tail, head):
297+
yield (str(index), (gdb_ptr + index).dereference())
298+
299+
277300
class RustStdStringPrinter(object):
278301
def __init__(self, val):
279302
self.__val = val

0 commit comments

Comments
 (0)