[libcxx-commits] [PATCH] D132983: Fix std::fpos pretty printer on musl

Pirama Arumuga Nainar via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 15 15:00:06 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG13c6828bedeb: Fix std::fpos pretty printer on musl (authored by ccross, committed by pirama).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132983

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
@@ -757,10 +757,18 @@
         typename = _remove_generics(_prettify_typename(self.val.type))
         offset = self.val["__off_"]
         state = self.val["__st_"]
-        count = state["__count"]
-        value = state["__value"]["__wch"]
-        return "%s with stream offset:%s with state: {count:%s value:%s}" % (
-            typename, offset, count, value)
+
+        state_fields = []
+        if state.type.code == gdb.TYPE_CODE_STRUCT:
+            state_fields = [f.name for f in state.type.fields()]
+
+        state_string = ""
+        if "__count" in state_fields and "__value" in state_fields:
+            count = state["__count"]
+            value = state["__value"]["__wch"]
+            state_string = " with state: {count:%s value:%s}" % (count, value)
+
+        return "%s with stream offset:%s%s" % (typename, offset, state_string)
 
 
 class AbstractUnorderedCollectionPrinter(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
@@ -643,17 +643,14 @@
 
 void streampos_test() {
   std::streampos test0 = 67;
-  ComparePrettyPrintToChars(
-      test0, "std::fpos with stream offset:67 with state: {count:0 value:0}");
+  ComparePrettyPrintToRegex(test0, "^std::fpos with stream offset:67( with state: {count:0 value:0})?$");
   std::istringstream input("testing the input stream here");
   std::streampos test1 = input.tellg();
-  ComparePrettyPrintToChars(
-      test1, "std::fpos with stream offset:0 with state: {count:0 value:0}");
+  ComparePrettyPrintToRegex(test1, "^std::fpos with stream offset:0( with state: {count:0 value:0})?$");
   std::unique_ptr<char[]> buffer(new char[5]);
   input.read(buffer.get(), 5);
   test1 = input.tellg();
-  ComparePrettyPrintToChars(
-      test1, "std::fpos with stream offset:5 with state: {count:0 value:0}");
+  ComparePrettyPrintToRegex(test1, "^std::fpos with stream offset:5( with state: {count:0 value:0})?$");
 }
 
 int main(int, char**) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132983.460513.patch
Type: text/x-patch
Size: 2316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220915/379395b3/attachment.bin>


More information about the libcxx-commits mailing list