[llvm] 7c5c4e7 - [gdb-scripts] Add to_string methods to printer implementations

Krzysztof Drewniak via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 09:09:36 PDT 2022


Author: Krzysztof Drewniak
Date: 2022-06-21T16:09:30Z
New Revision: 7c5c4e781b8c4a28e90e06f0a96ccdfbaa3ad433

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

LOG: [gdb-scripts] Add to_string methods to printer implementations

Some GDB versions require all prettyprinter classes to define to_string.
This commit adds these definitions.

Reviewed By: csigg

Differential Revision: https://reviews.llvm.org/D127969

Added: 
    

Modified: 
    llvm/utils/gdb-scripts/prettyprinters.py
    mlir/utils/gdb-scripts/prettyprinters.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gdb-scripts/prettyprinters.py b/llvm/utils/gdb-scripts/prettyprinters.py
index 8d5f2d404434d..b9bf0ef4a795e 100644
--- a/llvm/utils/gdb-scripts/prettyprinters.py
+++ b/llvm/utils/gdb-scripts/prettyprinters.py
@@ -386,6 +386,9 @@ def children(self):
     yield ('pointer', self.pointer)
     yield ('value', self.value)
 
+  def to_string(self):
+    return '(%s, %s)' % self.pointer.type, self.value.type
+
 def make_pointer_int_pair_printer(val):
   """Factory for an llvm::PointerIntPair printer."""
   try:

diff  --git a/mlir/utils/gdb-scripts/prettyprinters.py b/mlir/utils/gdb-scripts/prettyprinters.py
index fcdb6641da109..45614bf99e8aa 100644
--- a/mlir/utils/gdb-scripts/prettyprinters.py
+++ b/mlir/utils/gdb-scripts/prettyprinters.py
@@ -16,6 +16,8 @@ def children(self):
       else:
         yield field.name, self.val[field.name]
 
+  def to_string(self):
+    return 'mlir::Storage'
 
 class TupleTypeStoragePrinter(StoragePrinter):
 
@@ -27,6 +29,8 @@ def children(self):
     for i in range(self.val['numElements']):
       yield 'elements[%u]' % i, elements[i]
 
+  def to_string(self):
+    return 'mlir::TupleTypeStorage of %u elements' % self.val['numElements']
 
 class FusedLocationStoragePrinter(StoragePrinter):
 
@@ -38,6 +42,9 @@ def children(self):
     for i in range(self.val['numLocs']):
       yield 'locs[%u]' % i, elements[i]
 
+  def to_string(self):
+    return 'mlir::FusedLocationStorage of %u locs' % self.val['numLocs']
+
 
 class StorageTypeMap:
   """Maps a TypeID to the corresponding concrete type.
@@ -105,7 +112,10 @@ def __init__(self, type_id, impl):
 
     def children(self):
       yield 'typeID', self.type_id
-      yield 'cast<%s>(impl)' % self.impl.type, self.impl
+      yield 'impl', self.impl
+
+    def to_string(self):
+      return 'cast<%s>' % self.impl.type
 
   if not val['impl']:
     return None
@@ -125,10 +135,15 @@ class ImplPrinter:
   """Printer for an instance with a single 'impl' member pointer."""
 
   def __init__(self, val):
+    self.val = val
     self.impl = val['impl']
 
   def children(self):
-    yield 'impl', (self.impl.dereference() if self.impl else self.impl)
+    if self.impl:
+      yield 'impl', self.impl.dereference()
+
+  def to_string(self):
+    return self.val.type.name
 
 
 # Printers of types deriving from Attribute::AttrBase or Type::TypeBase.


        


More information about the llvm-commits mailing list