diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp index 42d8897903489..b346316080060 100644 --- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp +++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp @@ -171,22 +171,19 @@ using string_view = std::string_view; void string_view_test() { std::string_view i_am_empty; - ComparePrettyPrintToChars(i_am_empty, "std::string_view of length 0: \"\""); + ComparePrettyPrintToChars(i_am_empty, "\"\""); std::string source_string("to be or not to be"); std::string_view to_be(source_string); - ComparePrettyPrintToChars( - to_be, "std::string_view of length 18: \"to be or not to be\""); + ComparePrettyPrintToChars(to_be, "\"to be or not to be\""); const char char_arr[] = "what a wonderful world"; std::string_view wonderful(&char_arr[7], 9); - ComparePrettyPrintToChars( - wonderful, "std::string_view of length 9: \"wonderful\""); + ComparePrettyPrintToChars(wonderful, "\"wonderful\""); const char char_arr1[] = "namespace_stringview"; string_view namespace_stringview(&char_arr1[10], 10); - ComparePrettyPrintToChars( - namespace_stringview, "std::string_view of length 10: \"stringview\""); + ComparePrettyPrintToChars(namespace_stringview, "\"stringview\""); } } diff --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py index 1b728a461f52b..6913570633bf1 100644 --- a/libcxx/utils/gdb/libcxx/printers.py +++ b/libcxx/utils/gdb/libcxx/printers.py @@ -248,24 +248,16 @@ class StdStringViewPrinter(object): def __init__(self, val): self.val = val + def display_hint(self): + return "string" + def to_string(self): # pylint: disable=g-bad-name """GDB calls this to compute the pretty-printed form.""" ptr = self.val["__data"] - length = self.val["__size"] - print_length = length - # We print more than just a simple string (i.e. we also print - # "of length %d"). Thus we can't use the "string" display_hint, - # and thus we have to handle "print elements" ourselves. - # For reference sake, gdb ensures limit == None or limit > 0. - limit = gdb.parameter("print elements") - if limit is not None: - print_length = min(print_length, limit) - # FIXME: Passing ISO-8859-1 here isn't always correct. - string = ptr.string("ISO-8859-1", "ignore", print_length) - if length > print_length: - string += "..." - return "std::string_view of length %d: \"%s\"" % (length, string) + ptr = ptr.cast(ptr.type.target().strip_typedefs().pointer()) + size = self.val["__size"] + return ptr.lazy_string(length=size) class StdUniquePtrPrinter(object):