[libcxx-commits] [libcxx] ff618a9 - Simplify the libcxx std::string_view gdb pretty printer
David Blaikie via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 2 11:36:59 PST 2021
Author: David Blaikie
Date: 2021-12-02T11:36:38-08:00
New Revision: ff618a963aa52b9d2206f4ec83920b0e76535288
URL: https://github.com/llvm/llvm-project/commit/ff618a963aa52b9d2206f4ec83920b0e76535288
DIFF: https://github.com/llvm/llvm-project/commit/ff618a963aa52b9d2206f4ec83920b0e76535288.diff
LOG: Simplify the libcxx std::string_view gdb pretty printer
Seems better to rely on the existing formatting, makes the output
smaller/simpler - this is consistent with libstdc++'s std::string_view
pretty printing too.
Differential Revision: https://reviews.llvm.org/D113244
Added:
Modified:
libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
libcxx/utils/gdb/libcxx/printers.py
Removed:
################################################################################
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):
More information about the libcxx-commits
mailing list