1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

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)

llvm-svn: 289976
This commit is contained in:
David Blaikie 2016-12-16 19:16:22 +00:00
parent 7fb206b6f3
commit eb3e538057

View File

@ -103,9 +103,38 @@ class ArrayRefPrinter:
def display_hint (self): def display_hint (self):
return 'array' 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 = gdb.printing.RegexpCollectionPrettyPrinter("LLVMSupport")
pp.add_printer('llvm::SmallString', '^llvm::SmallString<.*>$', SmallStringPrinter) pp.add_printer('llvm::SmallString', '^llvm::SmallString<.*>$', SmallStringPrinter)
pp.add_printer('llvm::StringRef', '^llvm::StringRef$', StringRefPrinter) pp.add_printer('llvm::StringRef', '^llvm::StringRef$', StringRefPrinter)
pp.add_printer('llvm::SmallVectorImpl', '^llvm::SmallVector(Impl)?<.*>$', SmallVectorPrinter) pp.add_printer('llvm::SmallVectorImpl', '^llvm::SmallVector(Impl)?<.*>$', SmallVectorPrinter)
pp.add_printer('llvm::ArrayRef', '^llvm::(Const)?ArrayRef<.*>$', ArrayRefPrinter) 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) gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)