[libcxx-commits] [libcxx] r373691 - Make libc++ gdb pretty printer Python 3 compatible

Fangrui Song via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 3 21:47:33 PDT 2019


Author: maskray
Date: Thu Oct  3 21:47:33 2019
New Revision: 373691

URL: http://llvm.org/viewvc/llvm-project?rev=373691&view=rev
Log:
Make libc++ gdb pretty printer Python 3 compatible

Modified:
    libcxx/trunk/test/pretty_printers/gdb_pretty_printer_test.py
    libcxx/trunk/utils/gdb/libcxx/printers.py

Modified: libcxx/trunk/test/pretty_printers/gdb_pretty_printer_test.py
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/pretty_printers/gdb_pretty_printer_test.py?rev=373691&r1=373690&r2=373691&view=diff
==============================================================================
--- libcxx/trunk/test/pretty_printers/gdb_pretty_printer_test.py (original)
+++ libcxx/trunk/test/pretty_printers/gdb_pretty_printer_test.py Thu Oct  3 21:47:33 2019
@@ -17,6 +17,7 @@ See gdb_pretty_printer_test.sh.cpp on ho
 from __future__ import print_function
 import re
 import gdb
+import sys
 
 test_failures = 0
 
@@ -57,9 +58,9 @@ class CheckResult(gdb.Command):
                 print("FAIL: " + test_loc.symtab.filename +
                       ":" + str(test_loc.line))
                 print("GDB printed:")
-                print("   " + value)
+                print("   " + repr(value))
                 print("Value should match:")
-                print("   " + check_literal)
+                print("   " + repr(check_literal))
                 test_failures += 1
             else:
                 print("PASS: " + test_loc.symtab.filename +
@@ -76,11 +77,15 @@ class CheckResult(gdb.Command):
     def _get_value_string(self, compare_frame, testcase_frame):
         compare_frame.select()
         if "ComparePrettyPrint" in compare_frame.name():
-            return gdb.execute("p value", to_string=True)
-        value_str = str(compare_frame.read_var("value"))
-        clean_expression_str = value_str.strip("'\"")
-        testcase_frame.select()
-        return gdb.execute("p " + clean_expression_str, to_string=True)
+            s = gdb.execute("p value", to_string=True)
+        else:
+            value_str = str(compare_frame.read_var("value"))
+            clean_expression_str = value_str.strip("'\"")
+            testcase_frame.select()
+            s = gdb.execute("p " + clean_expression_str, to_string=True)
+        if sys.version_info.major == 2:
+            return s.decode("utf-8")
+        return s
 
 
 def exit_handler(event=None):

Modified: libcxx/trunk/utils/gdb/libcxx/printers.py
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/gdb/libcxx/printers.py?rev=373691&r1=373690&r2=373691&view=diff
==============================================================================
--- libcxx/trunk/utils/gdb/libcxx/printers.py (original)
+++ libcxx/trunk/utils/gdb/libcxx/printers.py Thu Oct  3 21:47:33 2019
@@ -137,13 +137,17 @@ class StdTuplePrinter(object):
         def __iter__(self):
             return self
 
-        def next(self):
+        def __next__(self):
             # child_iter raises StopIteration when appropriate.
             field_name = self.child_iter.next()
             child = self.val["__base_"][field_name]["__value_"]
             self.count += 1
             return ("[%d]" % self.count, child)
 
+        # TODO Delete when we drop Python 2.
+        def next(self):
+            return self.__next__()
+
     def __init__(self, val):
         self.val = val
 
@@ -311,7 +315,7 @@ class StdVectorPrinter(object):
         def __iter__(self):
             return self
 
-        def next(self):
+        def __next__(self):
             """Retrieve the next element."""
 
             self.count += 1
@@ -328,6 +332,10 @@ class StdVectorPrinter(object):
                 self.offset = 0
             return ("[%d]" % self.count, outbit)
 
+        # TODO Delete when we drop Python 2.
+        def next(self):
+            return self.__next__()
+
     class _VectorIterator(object):
         """Class to iterate over the non-bool vector's children."""
 
@@ -339,7 +347,7 @@ class StdVectorPrinter(object):
         def __iter__(self):
             return self
 
-        def next(self):
+        def __next__(self):
             self.count += 1
             if self.item == self.end:
                 raise StopIteration
@@ -347,6 +355,10 @@ class StdVectorPrinter(object):
             self.item += 1
             return ("[%d]" % self.count, entry)
 
+        # TODO Delete when we drop Python 2.
+        def next(self):
+            return self.__next__()
+
     def __init__(self, val):
         """Set val, length, capacity, and iterator for bool and normal vectors."""
         self.val = val




More information about the libcxx-commits mailing list