[gdb-scripts] Add to_string methods to printer implementations
authorKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Thu, 16 Jun 2022 14:38:56 +0000 (14:38 +0000)
committerKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Tue, 21 Jun 2022 16:09:30 +0000 (16:09 +0000)
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

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

index 8d5f2d4..b9bf0ef 100644 (file)
@@ -386,6 +386,9 @@ class PointerIntPairPrinter:
     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:
index fcdb664..45614bf 100644 (file)
@@ -16,6 +16,8 @@ class StoragePrinter:
       else:
         yield field.name, self.val[field.name]
 
+  def to_string(self):
+    return 'mlir::Storage'
 
 class TupleTypeStoragePrinter(StoragePrinter):
 
@@ -27,6 +29,8 @@ class TupleTypeStoragePrinter(StoragePrinter):
     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 @@ class FusedLocationStoragePrinter(StoragePrinter):
     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 get_attr_or_type_printer(val, get_type_id):
 
     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.