[llvm] r289976 - GDB pretty printer for llvm::Optional
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 16 11:16:22 PST 2016
Author: dblaikie
Date: Fri Dec 16 13:16:22 2016
New Revision: 289976
URL: http://llvm.org/viewvc/llvm-project?rev=289976&view=rev
Log:
GDB pretty printer for llvm::Optional
(some other implementations of an optional pretty printer print the full
name of the optional type (including template parameter) - but seems if
the template parameter isn't printed for std::vector, not sure why it
would be printed for optional, so erring on the side of consistency in
that direction here - compact, etc, as well)
Modified:
llvm/trunk/utils/gdb-scripts/prettyprinters.py
Modified: llvm/trunk/utils/gdb-scripts/prettyprinters.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gdb-scripts/prettyprinters.py?rev=289976&r1=289975&r2=289976&view=diff
==============================================================================
--- llvm/trunk/utils/gdb-scripts/prettyprinters.py (original)
+++ llvm/trunk/utils/gdb-scripts/prettyprinters.py Fri Dec 16 13:16:22 2016
@@ -103,9 +103,38 @@ class ArrayRefPrinter:
def display_hint (self):
return 'array'
+class OptionalPrinter:
+ """Print an llvm::Optional object."""
+
+ def __init__(self, value):
+ self.value = value
+
+ class _iterator:
+ def __init__(self, member, empty):
+ self.member = member
+ self.done = empty
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.done:
+ raise StopIteration
+ self.done = True
+ return ('value', self.member.dereference())
+
+ def children(self):
+ if not self.value['hasVal']:
+ return self._iterator('', True)
+ return self._iterator(self.value['storage']['buffer'].address.cast(self.value.type.template_argument(0).pointer()), False)
+
+ def to_string(self):
+ return 'llvm::Optional is %sinitialized' % ('' if self.value['hasVal'] else 'not ')
+
pp = gdb.printing.RegexpCollectionPrettyPrinter("LLVMSupport")
pp.add_printer('llvm::SmallString', '^llvm::SmallString<.*>$', SmallStringPrinter)
pp.add_printer('llvm::StringRef', '^llvm::StringRef$', StringRefPrinter)
pp.add_printer('llvm::SmallVectorImpl', '^llvm::SmallVector(Impl)?<.*>$', SmallVectorPrinter)
pp.add_printer('llvm::ArrayRef', '^llvm::(Const)?ArrayRef<.*>$', ArrayRefPrinter)
+pp.add_printer('llvm::Optional', '^llvm::Optional<.*>$', OptionalPrinter)
gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)
More information about the llvm-commits
mailing list