From b9f9c7710320ed1973ece7973d5918a09767a7e7 Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Fri, 2 Jun 2017 21:18:45 +0300 Subject: [PATCH] Add separate GDB pretty-printer for empty structs Use a class without children() method for printing empty structs. Presence of this method makes GDB's variable objects interface act like if the struct had children. --- src/etc/gdb_rust_pretty_printing.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index d2bc7dd53df..aab15d9ed1e 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -100,8 +100,10 @@ def rust_pretty_printer_lookup_function(gdb_val): val = GdbValue(gdb_val) type_kind = val.type.get_type_kind() - if (type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT or - type_kind == rustpp.TYPE_KIND_EMPTY): + if type_kind == rustpp.TYPE_KIND_EMPTY: + return RustEmptyPrinter(val) + + if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT: return RustStructPrinter(val, omit_first_field = False, omit_type_name = False, @@ -174,6 +176,14 @@ def rust_pretty_printer_lookup_function(gdb_val): #=------------------------------------------------------------------------------ # Pretty Printer Classes #=------------------------------------------------------------------------------ +class RustEmptyPrinter(object): + def __init__(self, val): + self.__val = val + + def to_string(self): + return self.__val.type.get_unqualified_type_name() + + class RustStructPrinter(object): def __init__(self, val, omit_first_field, omit_type_name, is_tuple_like): self.__val = val