[libcxx-commits] [PATCH] D117470: [libc++] Fix GDB pretty printers when GDB uses Python 2.7

Alexander Richardson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 17 05:50:22 PST 2022


arichardson created this revision.
arichardson added reviewers: libc++, ldionne, DavidSpickett, saugustine, gAlfonso-bit.
arichardson requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

The gdb_pretty_printer_test.sh fails if GDB was built against Python 2.7
since Python 2 expects iterators to have a next() method rather than
using __next__. To make the pretty printers work with both Python 2 and 3
we can simply set next to __next__ in the iterator classes.

Python 2.7 support was removed in f46f93b4786377dd7ee704ef2beedadfe4f05adf <https://reviews.llvm.org/rGf46f93b4786377dd7ee704ef2beedadfe4f05adf>,
so this effectively reverts that commit. While Python 2.7 is EOL, it
appears there are still many GDB installations that are linked against
Python 2.7, so we may want to keep this tiny amount of compat code
around for a while longer.

Without this commit the tests fails with errors such as:

  GDB printed:
     u"std::tuple containingTypeError: iter() returned non-iterator of type '_Children'\n"
  Value should match:
     u'std::tuple containing = {[1] = 2, [2] = 3, [3] = 4}'


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117470

Files:
  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
@@ -147,6 +147,8 @@
             self.count += 1
             return ("[%d]" % self.count, child)
 
+        next = __next__  # Needed for GDB built against Python 2.7.
+
     def __init__(self, val):
         self.val = val
 
@@ -356,6 +358,8 @@
                 self.offset = 0
             return ("[%d]" % self.count, outbit)
 
+        next = __next__  # Needed for GDB built against Python 2.7.
+
     class _VectorIterator(object):
         """Class to iterate over the non-bool vector's children."""
 
@@ -375,6 +379,8 @@
             self.item += 1
             return ("[%d]" % self.count, entry)
 
+        next = __next__  # Needed for GDB built against Python 2.7.
+
     def __init__(self, val):
         """Set val, length, capacity, and iterator for bool and normal vectors."""
         self.val = val


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117470.400502.patch
Type: text/x-patch
Size: 1009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220117/c2ef7d8b/attachment.bin>


More information about the libcxx-commits mailing list