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

Krzysztof Drewniak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 07:41:52 PDT 2022


krzysz00 created this revision.
krzysz00 added a reviewer: csigg.
Herald added subscribers: bzcheeseman, sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a project: All.
krzysz00 requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: MLIR, LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127969

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


Index: mlir/utils/gdb-scripts/prettyprinters.py
===================================================================
--- mlir/utils/gdb-scripts/prettyprinters.py
+++ mlir/utils/gdb-scripts/prettyprinters.py
@@ -16,6 +16,8 @@
       else:
         yield field.name, self.val[field.name]
 
+  def to_string(self):
+    return 'mlir::Storage'
 
 class TupleTypeStoragePrinter(StoragePrinter):
 
@@ -27,6 +29,8 @@
     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 @@
     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 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 @@
   """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.
Index: llvm/utils/gdb-scripts/prettyprinters.py
===================================================================
--- llvm/utils/gdb-scripts/prettyprinters.py
+++ llvm/utils/gdb-scripts/prettyprinters.py
@@ -386,6 +386,9 @@
     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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127969.437538.patch
Type: text/x-patch
Size: 2184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220616/8ba0ca2a/attachment.bin>


More information about the llvm-commits mailing list