[libcxx-commits] [PATCH] D79924: [gdb] Decay type before passing into printer

Leszek Swirski via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 14 01:33:52 PDT 2020


LeszekSwirski created this revision.
Herald added a subscriber: libcxx-commits.
LeszekSwirski added a reviewer: echristo.

The existing gdb printer logic didn't work for const types, references, or typedefs. Now we strip const, references, and typedefs, before doing any of the matching checks or printer lookup.


Repository:
  rCXX libc++

https://reviews.llvm.org/D79924

Files:
  utils/gdb/libcxx/printers.py


Index: utils/gdb/libcxx/printers.py
===================================================================
--- utils/gdb/libcxx/printers.py
+++ utils/gdb/libcxx/printers.py
@@ -946,12 +946,20 @@
     def __call__(self, val):
         """Return the pretty printer for a val, if the type is supported."""
 
+        # Get a non-qualfied, non-reference version of the type, with typedefs
+        # stripped.
+        val_type = val.type
+        while val_type.code in [gdb.TYPE_CODE_REF, gdb.TYPE_CODE_RVALUE_REF]:
+          val_type = val_type.target()
+        val_type = val_type.unqualified()
+        val_type = val_type.strip_typedefs()
+
         # Do not handle any type that is not a struct/class.
-        if val.type.strip_typedefs().code != gdb.TYPE_CODE_STRUCT:
+        if val_type.code != gdb.TYPE_CODE_STRUCT:
             return None
 
         # Don't attempt types known to be inside libstdcxx.
-        typename = val.type.name or val.type.tag or str(val.type)
+        typename = val_type.name or val_type.tag or str(val_type)
         match = re.match("^std::(__.*?)::", typename)
         if match is None or match.group(1) in ["__cxx1998",
                                                "__debug",
@@ -960,7 +968,7 @@
             return None
 
         # Handle any using declarations or other typedefs.
-        typename = _prettify_typename(val.type)
+        typename = _prettify_typename(val_type)
         if not typename:
             return None
         without_generics = _remove_generics(typename)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79924.263932.patch
Type: text/x-patch
Size: 1531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200514/a7d19543/attachment.bin>


More information about the libcxx-commits mailing list