[libcxx-commits] [PATCH] D113244: Simplify the libcxx std::string_view gdb pretty printer

David Blaikie via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 29 13:55:13 PST 2021


dblaikie updated this revision to Diff 390458.
dblaikie added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113244/new/

https://reviews.llvm.org/D113244

Files:
  libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
  libcxx/utils/gdb/libcxx/printers.py


Index: libcxx/utils/gdb/libcxx/printers.py
===================================================================
--- libcxx/utils/gdb/libcxx/printers.py
+++ libcxx/utils/gdb/libcxx/printers.py
@@ -248,24 +248,17 @@
     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)
+      size = self.val["__size"]
+      if hasattr(ptr, "lazy_string"):
+          return ptr.lazy_string(length=size)
+      return data.string(length=size)
 
 
 class StdUniquePtrPrinter(object):
Index: libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
===================================================================
--- libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -171,22 +171,19 @@
 
 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\"");
 }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113244.390458.patch
Type: text/x-patch
Size: 2668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211129/214f41c8/attachment.bin>


More information about the libcxx-commits mailing list