From ac33d2cbfbe103cb9dda7cc31eda85fcd8ca039d Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Sun, 28 May 2017 12:08:40 +0300 Subject: [PATCH 1/8] Fix GDB pretty-printer for tuples Names of children should not be the same, because GDB uses them to distinguish the children. --- src/etc/gdb_rust_pretty_printing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index afac8d6bbaefc..e617435f54f4c 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -186,10 +186,10 @@ def children(self): cs = [] wrapped_value = self.__val.get_wrapped_value() - for field in self.__val.type.get_fields(): + for number, field in enumerate(self.__val.type.get_fields()): field_value = wrapped_value[field.name] if self.__is_tuple_like: - cs.append(("", field_value)) + cs.append((str(number), field_value)) else: cs.append((field.name, field_value)) From 167e4b09d1688a0b4ac9b260a84bacdc926e0230 Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Tue, 30 May 2017 11:14:25 +0300 Subject: [PATCH 2/8] Fix 'invalid literal for int()' exception in pretty-printers Some pointers values include additional info, so they can't be parsed with int(). --- src/etc/gdb_rust_pretty_printing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index e617435f54f4c..2ad16b50d3f8e 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -78,7 +78,8 @@ def get_child_at_index(self, index): def as_integer(self): if self.gdb_val.type.code == gdb.TYPE_CODE_PTR: - return int(str(self.gdb_val), 0) + as_str = str(self.gdb_val).split()[0] + return int(as_str, 0) return int(self.gdb_val) def get_wrapped_value(self): From 10977bcf6cb278895313045b048851bef019272d Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Tue, 30 May 2017 23:42:35 +0300 Subject: [PATCH 3/8] Fix 'invalid literal for int()' exception with unicode in pretty-printers str() can't handle unicode strings --- 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 2ad16b50d3f8e..aa1d00eaaab6a 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -78,7 +78,7 @@ def get_child_at_index(self, index): def as_integer(self): if self.gdb_val.type.code == gdb.TYPE_CODE_PTR: - as_str = str(self.gdb_val).split()[0] + as_str = unicode(self.gdb_val).split()[0] return int(as_str, 0) return int(self.gdb_val) From c7ef85ca0eb09acad16d2f969e69737308290309 Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Thu, 1 Jun 2017 21:26:09 +0300 Subject: [PATCH 4/8] Add test for 'invalid literal for int()' exception in gdb pretty-printers --- src/test/debuginfo/pretty-std.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index 153f0c8271fc4..a1a2cd67bb33a 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -38,6 +38,9 @@ // gdbg-check:$6 = None // gdbr-check:$6 = core::option::Option::None +// gdb-command: print some_string +// gdbr-check:$7 = Some = {"IAMA optional string!"} + // === LLDB TESTS ================================================================================== @@ -82,6 +85,8 @@ fn main() { let some = Some(8i16); let none: Option = None; + let some_string = Some("IAMA optional string!".to_owned()); + zzz(); // #break } From c1f687b73fc76808d8f4555d6f77b7f64e554fa9 Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Fri, 2 Jun 2017 16:18:00 +0300 Subject: [PATCH 5/8] Add GDB pretty-printer for OsString --- src/etc/debugger_pretty_printers_common.py | 9 +++++++++ src/etc/gdb_rust_pretty_printing.py | 18 ++++++++++++++++++ src/test/debuginfo/pretty-std.rs | 12 ++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/etc/debugger_pretty_printers_common.py b/src/etc/debugger_pretty_printers_common.py index 5e3ff5246a922..7eb008a05f61b 100644 --- a/src/etc/debugger_pretty_printers_common.py +++ b/src/etc/debugger_pretty_printers_common.py @@ -46,6 +46,7 @@ TYPE_KIND_PTR = 15 TYPE_KIND_FIXED_SIZE_VEC = 16 TYPE_KIND_REGULAR_UNION = 17 +TYPE_KIND_OS_STRING = 18 ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$" ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR" @@ -64,6 +65,9 @@ # std::String related constants STD_STRING_FIELD_NAMES = ["vec"] +# std::ffi::OsString related constants +OS_STRING_FIELD_NAMES = ["inner"] + class Type(object): """ @@ -162,6 +166,11 @@ def __classify_struct(self): self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)): return TYPE_KIND_STD_STRING + # OS STRING + if (unqualified_type_name == "OsString" and + self.__conforms_to_field_layout(OS_STRING_FIELD_NAMES)): + return TYPE_KIND_OS_STRING + # ENUM VARIANTS if fields[0].name == ENUM_DISR_FIELD_NAME: if field_count == 1: diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index aa1d00eaaab6a..d2bc7dd53df7e 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -125,6 +125,9 @@ def rust_pretty_printer_lookup_function(gdb_val): if type_kind == rustpp.TYPE_KIND_STD_STRING: return RustStdStringPrinter(val) + if type_kind == rustpp.TYPE_KIND_OS_STRING: + return RustOsStringPrinter(val) + if type_kind == rustpp.TYPE_KIND_TUPLE: return RustStructPrinter(val, omit_first_field = False, @@ -269,6 +272,21 @@ def to_string(self): length=length) +class RustOsStringPrinter(object): + def __init__(self, val): + self.__val = val + + def to_string(self): + buf = self.__val.get_child_at_index(0) + vec = buf.get_child_at_index(0) + if vec.type.get_unqualified_type_name() == "Wtf8Buf": + vec = vec.get_child_at_index(0) + + (length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec( + vec) + return '"%s"' % data_ptr.get_wrapped_value().string(length=length) + + class RustCStyleVariantPrinter(object): def __init__(self, val): assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_ENUM diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index a1a2cd67bb33a..88a3c76b85817 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -38,8 +38,11 @@ // gdbg-check:$6 = None // gdbr-check:$6 = core::option::Option::None -// gdb-command: print some_string -// gdbr-check:$7 = Some = {"IAMA optional string!"} +// gdbr-command: print os_string +// gdbr-check:$7 = "IAMA OS string 😃" + +// gdbr-command: print some_string +// gdbr-check:$8 = Some = {"IAMA optional string!"} // === LLDB TESTS ================================================================================== @@ -66,6 +69,8 @@ #![allow(unused_variables)] +use std::ffi::OsString; + fn main() { @@ -81,6 +86,9 @@ fn main() { // String let string = "IAMA string!".to_string(); + // OsString + let os_string = OsString::from("IAMA OS string \u{1F603}"); + // Option let some = Some(8i16); let none: Option = None; From b9f9c7710320ed1973ece7973d5918a09767a7e7 Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Fri, 2 Jun 2017 21:18:45 +0300 Subject: [PATCH 6/8] 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 d2bc7dd53df7e..aab15d9ed1e3c 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 From d7c0d7569b47298da4a45dfd96275b9a888fe58c Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Fri, 9 Jun 2017 18:51:28 +0300 Subject: [PATCH 7/8] Pretty-printers tests: gdbr -> gdb --- src/test/debuginfo/pretty-std.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index 88a3c76b85817..9596f0287bc59 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -38,11 +38,11 @@ // gdbg-check:$6 = None // gdbr-check:$6 = core::option::Option::None -// gdbr-command: print os_string -// gdbr-check:$7 = "IAMA OS string 😃" +// gdb-command: print os_string +// gdb-check:$7 = "IAMA OS string 😃" -// gdbr-command: print some_string -// gdbr-check:$8 = Some = {"IAMA optional string!"} +// gdb-command: print some_string +// gdb-check:$8 = Some = {"IAMA optional string!"} // === LLDB TESTS ================================================================================== From 63076ddbb8e9856e9996adb49fc0a67a29ca697b Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Fri, 9 Jun 2017 19:09:02 +0300 Subject: [PATCH 8/8] Add compat_str() which works with unicode in both Python 2 and 3 GDB can be built with Python 2 or with Python 3 --- src/etc/debugger_pretty_printers_common.py | 5 +++++ src/etc/gdb_rust_pretty_printing.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/etc/debugger_pretty_printers_common.py b/src/etc/debugger_pretty_printers_common.py index 7eb008a05f61b..4a38d4be083fd 100644 --- a/src/etc/debugger_pretty_printers_common.py +++ b/src/etc/debugger_pretty_printers_common.py @@ -354,3 +354,8 @@ def extract_type_name(qualified_type_name): return qualified_type_name else: return qualified_type_name[index + 2:] + +try: + compat_str = unicode # Python 2 +except NameError: + compat_str = str diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index aab15d9ed1e3c..822dc58140470 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -78,7 +78,7 @@ def get_child_at_index(self, index): def as_integer(self): if self.gdb_val.type.code == gdb.TYPE_CODE_PTR: - as_str = unicode(self.gdb_val).split()[0] + as_str = rustpp.compat_str(self.gdb_val).split()[0] return int(as_str, 0) return int(self.gdb_val)