[libcxx-commits] [libcxx] e4d5daa - Reenable gdb pretty printers, and update them.

Sterling Augustine via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 11 12:29:10 PDT 2022


Author: Sterling Augustine
Date: 2022-10-11T12:28:34-07:00
New Revision: e4d5daaf91f6719626fa36c75e553e91778b94a9

URL: https://github.com/llvm/llvm-project/commit/e4d5daaf91f6719626fa36c75e553e91778b94a9
DIFF: https://github.com/llvm/llvm-project/commit/e4d5daaf91f6719626fa36c75e553e91778b94a9.diff

LOG: Reenable gdb pretty printers, and update them.

Libcxx gdb pretty printers were disabled due to an old version
of gdb in the release testing. This reenables them, and fixes
various bit rot issues from not running them.

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 3a4e544ae8c8f..b922a8bd8ab61 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -11,9 +11,6 @@
 // UNSUPPORTED: no-localization
 // UNSUPPORTED: c++03
 
-// TODO: Investigate this failure, which happens only with the Bootstrapping build.
-// UNSUPPORTED: clang-14, clang-15, clang-16
-
 // TODO: Investigate this failure on GCC 12 (in Ubuntu Jammy)
 // UNSUPPORTED: gcc-12
 

diff  --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index 8d103ad5b3996..e62c3674683a1 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -64,6 +64,36 @@ def _remove_generics(typename):
     return match.group(1)
 
 
+def _cc_field(node):
+    """Previous versions of libcxx had inconsistent field naming naming. Handle
+    both types.
+    """
+    try:
+        return node["__value_"]["__cc_"]
+    except:
+        return node["__value_"]["__cc"]
+
+
+def _data_field(node):
+    """Previous versions of libcxx had inconsistent field naming naming. Handle
+    both types.
+    """
+    try:
+        return node["__data_"]
+    except:
+        return node["__data"]
+
+
+def _size_field(node):
+    """Previous versions of libcxx had inconsistent field naming naming. Handle
+    both types.
+    """
+    try:
+        return node["__size_"]
+    except:
+        return node["__size"]
+
+
 # Some common substitutions on the types to reduce visual clutter (A user who
 # wants to see the actual details can always use print/r).
 _common_substitutions = [
@@ -197,12 +227,9 @@ def __init__(self, val):
 
     def to_string(self):
         """Build a python string from the data whether stored inline or separately."""
-
         value_field = _value_of_pair_first(self.val["__r_"])
         short_field = value_field["__s"]
         short_size = short_field["__size_"]
-        if short_size == 0:
-            return ""
         if short_field["__is_long_"]:
             long_field = value_field["__l"]
             data = long_field["__data_"]
@@ -228,9 +255,9 @@ def display_hint(self):
     def to_string(self):  # pylint: disable=g-bad-name
       """GDB calls this to compute the pretty-printed form."""
 
-      ptr = self.val["__data"]
+      ptr = _data_field(self.val)
       ptr = ptr.cast(ptr.type.target().strip_typedefs().pointer())
-      size = self.val["__size"]
+      size = _size_field(self.val)
       return ptr.lazy_string(length=size)
 
 
@@ -667,8 +694,7 @@ def display_hint(self):
         return "map"
 
     def _get_key_value(self, node):
-        key_value = node.cast(self.util.cast_type).dereference()[
-            "__value_"]["__cc"]
+        key_value = _cc_field(node.cast(self.util.cast_type).dereference())
         return [key_value["first"], key_value["second"]]
 
 
@@ -734,7 +760,7 @@ def __init__(self, val):
                          _remove_generics(_prettify_typename(val.type)))
 
     def _get_node_value(self, node):
-        return node["__value_"]["__cc"]
+        return _cc_field(node)
 
 
 class SetIteratorPrinter(AbstractRBTreeIteratorPrinter):
@@ -821,7 +847,7 @@ class StdUnorderedMapPrinter(AbstractUnorderedCollectionPrinter):
     """Print a std::unordered_(multi)map."""
 
     def _get_key_value(self, node):
-        key_value = node["__value_"]["__cc"]
+        key_value = _cc_field(node)
         return [key_value["first"], key_value["second"]]
 
     def display_hint(self):
@@ -877,7 +903,7 @@ def __init__(self, val):
         self._initialize(val, val["__i_"]["__node_"])
 
     def _get_key_value(self):
-        key_value = self.node["__value_"]["__cc"]
+        key_value = _cc_field(self.node)
         return [key_value["first"], key_value["second"]]
 
     def display_hint(self):


        


More information about the libcxx-commits mailing list